Texturing problems...

Started by
3 comments, last by MARS_999 19 years ago
Argh. Been working with OpenGL for quite some time and still I get stuck at the basics from time to time. I'm trying to create a texture from some data, but it wont work - I only get an white texture. Here's some code:

glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glEnable(GL_TEXTURE_2D);
			  			  
unsigned char* raw = new unsigned char[1024*3];
for (int j = 0; j < 1024*3; j++)
	raw[j] = Random(1, 100);
				
unsigned int tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
					
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, raw);
				
glLoadIdentity();
			  
glBegin(GL_QUADS);
	glTexCoord2f(0, 0);
	glVertex2i(0, 0);
	    		
	glTexCoord2f(1.0f, 0);
	glVertex2i(32, 0);
	    		
	glTexCoord2f(1.0f, 1.0f);
	glVertex2i(32, 32);
	    		
	glTexCoord2f(0, 1.0f);
	glVertex2i(0, 32);		
glEnd();

I know it's probably not a good idea to generate the texture every frame, but I'm just testing at the moment. If i use another texture (generated by a TGA) this works fine, so it's not any other settings I think. Any ideas why it won't work?
-Lord Maz-
Advertisement
You shouldn't be generating a new texture every frame like that I am wondering if you have an overflow? I don't see any texture filtering setup either for the texture. And you should delete that memory once you are done if you are planning on newing it again right away...
Ah, think I found the problem. As usual, I didn't remember the state-machine-ickyness of OpenGL and tried to set texture filturing (forgot that completely in the test code i posted...) before i called bindtexture. Thanks for the reply.
-Lord Maz-
1024*3 = 1D
1024*1024*3 =2D
1024*1024*1024*3 = 3D
i hope you get it :)
EDIT:
the width and height in glTexImage2D should be same the width and height of the Texture array
Quote:Original post by ff8
1024*3 = 1D
1024*1024*3 =2D
1024*1024*1024*3 = 3D
i hope you get it :)
EDIT:
the width and height in glTexImage2D should be same the width and height of the Texture array


He is correct FF8, 32*32*3 = 3072 and 1024*3 = 3072 he is just going about it in a not so clear way.

This topic is closed to new replies.

Advertisement