I cant make OpenGL texture a quad.
I am rather new to OpenGL, having no desire to make 3d games and all, but it turns out GL seemed like it would work rather well for a 2d game I am working on that needs to rotate and zoom every sprite every frame. So I stared simple, texturing a quad. And to my dismay, it just displays a white quad. Here is my code:
glGenTextures(1, (ampersand get mangled)image[0]);
glBindTexture(GL_TEXTURE_2D, image[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, ts->w, ts->h, 0, GL_RGB, GL_UNSIGNED_BYTE, ts->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
A little later:
void blitImage(Pimage *image, int x, int y){
glBindTexture(GL_TEXTURE_2D, image->image[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2i(-100, -100);
glTexCoord2f(1.0f, 0.0f); glVertex2i(100, -100);
glTexCoord2f(1.0f, 1.0f); glVertex2i(100, 100);
glTexCoord2f(0.0f, 1.0f); glVertex2i(-100, 100);
glEnd();
}
As far as I know, I adapted NeHe properly.
I did enable textures, but they are not a power of 2. How inconvienient. Is there a way around that? This is a 2d sprite game.
You could use a larger texture than you need that encompasses the size you want. say you want to have a 100X200 texture, you would use a 128x256 and the use the UV coordinates clip to the 100x200 area with in the texture.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement