Advertisement

creating a blank texture?

Started by March 03, 2001 12:23 AM
6 comments, last by thuned 23 years, 8 months ago
i would i do this? does this work?

AUX_RGBImageRec* data;
GLuint texture;
memset(data,0,sizeof(void *)*1);
glGenTextures(1, texture);
data->sizeX = width;
data->sizeY = height;
 
then, since data is all 0''s, it''ll just come out with a black texture of width,height? or how should i do it? and if i create blank stuff this way, does the power of 2 texture size limit still apply? thuned life is unfair, take advantage of it. UNMB2 - if the link doesn''t work, try clicking it
life is unfair, take advantage of it.UNMB2 - if the link doesn't work, try clicking it :)
Why do you want to do this? It would be easier to just turn texture mapping and set the color to black, wouldn''t it?
Advertisement
I''ve never seen this kind of struct/class (AUX_RGBImageRec).
By the way I suppose there are two mistakes in your code.

First of all, "sizeof(void *)*1" doesn''t set the correct image lenght in bytes. This should be something like width*height*(bpp/8).
The void data is theorically a null (0-byte) data. Going down to the real thing, compiler could consider sizeof(void *) to be zero, resulting in a zero byte memset. Unless the compiler implicitly makes a cast to an unsigned int (considering the pointer must point to a 32-bit address), setting only 4 bytes as zero. Multiplying the result of a sizeof by 1 is unuseful.

Then, you shouldn''t try to directly memset "data". By doing so, you start memsetting this object starting from the first allocated variable, which could be any variable both sizex or image data.
You could memset the entire object, by using sizeof(AUX_RGBImageRec), but it''s better to use the default constructor for setting all 0s (which can be used in structs, too), and eventually overload it in the case you want to immediately set its width,height,bpp or image data itself. I suppose AUX_RGBImageRec has a void pointer pointing to image data.
As for me, the right way to do this should be:

memset(data->PtrToBitmap,0,width*height*(bpp/8));

Data must have been correctly created, which doesn''t seem your case, as if you forgot it in your code, you''re just writing 0/4 bytes somewhere in meomry and then assigning width and height to an unknown memory area.
I suppose this could hang up everything.


Hope this helps.
David20321, i want these blank textures so i can blit other textures onto this.


AUX_RGBImageRec i think i the glaux.h''s bitmap loading thing. i guess i can just load a blank bitmap, but is there any other way?


thuned



life is unfair, take advantage of it.
UNMB2 - if the link doesn''t work, try clicking it
life is unfair, take advantage of it.UNMB2 - if the link doesn't work, try clicking it :)
Read Nehe''s TGA loading tutorial, it shows you how to load a texture from a custom file. Then just remove the file loading code and have it set the texture 0xFF all the way through with a memset. Using the GLAux libraries kind of makes texture loading harder to understand (it hides the code from you), that''s why I didn''t like them originally.

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://www.gdarchive.net/druidgames/
thanks, but i don''t really get the .texID part. below are like the only times they''re used:
	glGenTextures(1, &texture[0].texID);					// Generate OpenGL texture IDs	glBindTexture(GL_TEXTURE_2D, texture[0].texID);			// Bind Our Texture 

does gentextures change the value of texID? and what actually IS texID? address of the texture? like how does bindtexture know what texture to use just by an int?


thuned

life is unfair, take advantage of it.
UNMB2 - if the link doesn''t work, try clicking it
life is unfair, take advantage of it.UNMB2 - if the link doesn't work, try clicking it :)
Advertisement
why do you want to know this?

glGenTextures generates a texture on hardware if possible and gives you and integer value containing the texture id ( could be some sort of hash table index or something). you can then use this id to bind a texture onto a polygon and youre done. if you want a black texture, just create one black image or memset the image data with your black value
TexID is the number assigned to the texture (as was stated by AP). When you call glGenTextures, it finds places for the number of textures you want to create, in this case only one. Then is stores an identifier for each texture in the array (or single unsigned int in this case) so that you can bind that texture at any time in the future. When you bind the texture you''re allowed to do certain operations to it (like when you''re loading it), and anything you draw (if GL_TEXTURE_2D is enabled) will be textured with it.

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://www.gdarchive.net/druidgames/

This topic is closed to new replies.

Advertisement