I cant make OpenGL texture a quad.

Started by
4 comments, last by Witchcraven 19 years, 6 months ago
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 present for tribute this haiku:Inane Ravings OfThe Haunting JubilationA Mad Engineer©Copyright 2005 ExtrariusAll Rights Reserved
Advertisement
Are your Textures width and height a power of 2? If they are not they wont be loaded.
glEnable(GL_TEXTURE_2D) ?
_______________________________ ________ _____ ___ __ _`By offloading cognitive load to the computer, programmers are able to design more elegant systems' - Unununium OS regarding Python
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.
--------------------------I present for tribute this haiku:Inane Ravings OfThe Haunting JubilationA Mad Engineer©Copyright 2005 ExtrariusAll Rights Reserved
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.
That would work. Although that is just so...unclean :P Thanks. If I didnt know about that power of 2 thing I may ave just gone insane trying to fix a bug that was not even in code.
--------------------------I present for tribute this haiku:Inane Ravings OfThe Haunting JubilationA Mad Engineer©Copyright 2005 ExtrariusAll Rights Reserved

This topic is closed to new replies.

Advertisement