PDA

View Full Version : texture showing up as color set by glColor? help!



silex
05-24-2006, 10:39 AM
Hi,

I'm stretching a texture across an entire viewport for an augmented reality type application with video feed.

However, right now I can't even get a regular texture to display correctly. I load identity matrices for projection and modelview so I can specify a quad in normalized coordinates like this:


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D, debug_tex );

glBegin(GL_QUADS);

glTexCoord2f( 0.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f( 1.0f, 1.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f( 1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f( 0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glEnd();

glDisable(GL_TEXTURE_2D);
With GL_LIGHTING disabled, I get a green screen; when it's enabled, it's grey. If I change the vertices to cover half the screen, then I get a half green screen.

I don't think this is the problem, but I have multiple viewports and I use scissoring.

Anyone seen this before?

Thanks!

jide
05-24-2006, 10:43 AM
What you have is simply the result of the modulate texture environment. Setting it to replace or changing your quad colors will help.
About lighting, expect nothing until you have set light properties, materials and normals.

silex
05-24-2006, 10:45 AM
I see you are from France:

Pourais tu clarifier ce que tu veux dire par "modulate texture environment" et "setting it to replace"? Je ne suis pas tres familier avec les fonctions de texture dans OGL.

J'ai essaye:

glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );

mais ca n'a rien change.

Merci!

If not:

Could you clarify what you mean by "modulate texture environment" and "setting it to replace"? I'm not very familiar with OGL texture functions.

jide
05-24-2006, 10:53 AM
**** I've been betrayed by the informations I gave on me... So, some french now.

D'abord, ici, que tu sois français, allemand ou chinois, on parle anglais. C'est en sorte une marque de respect envers les autres. Sinon ça serait le merdier total. Juste pour information, sans aucune arrière pensée.

Avant d'utiliser ta texture, tu dois spécifier la fonction de texture avec glTexEnv**:


glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);par exemple devrait suffir.
Ce que tu as m'a tout l'air d'être dû * ce problème.

Sinon un autre conseil, un bon bouquin sur GL, comme l'officiel, te fera gagner et du temps et de la connaissance :)

PS: essaies l'anglais c'est pas si dur ;)

silex
05-24-2006, 11:04 AM
OT: En fait l'anglais est ma premiere langue, alors je vais l'utiliser a partir de maintenant... :)

Setting glTexEnv* didn't seem to work. I first placed it in the drawing code, called each frame, and then in the texture initialization code:


glEnable(GL_TEXTURE_2D);
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glGenTextures(1, &debug_tex);
glBindTexture(GL_TEXTURE_2D, debug_tex);
glTexImage2D( GL_TEXTURE_2D, 0, 3, tex_image->w, tex_image->h, 0, GL_BGR,
GL_UNSIGNED_BYTE, tex_image->pixels );

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

jide
05-24-2006, 11:07 AM
Call it after you bound your texture, it works on the active texture.

silex
05-24-2006, 11:12 AM
Yes, that is where I placed it in the drawing loop.


glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,debug_tex);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
...And in the texture initialization, moving it to after the bind call did not help either. To be clear: I am using only one call at a time, not one in the initialization and one each frame.

Perhaps my problem is not texture modulation?

jide
05-24-2006, 11:50 AM
Okay, so can you clarify all ? What exactly do you have ? I understood you had a texture colored with the glColor, am I wrong ? Can you at least see the texture, or is it an all blank/red/... ? Can you give some code or some snaps ? Does GL_BGR is really what you need to use ?

TexEnv can be called just once on texture creation or each time for each frame, depending on your needs.

I cannot say more for the moment.

silex
05-24-2006, 01:33 PM
Sorry, I thought my problem would be obvious with what I said before, but maybe it is more complicated than I hoped.

Since my initial post, I wrote a test program using the same code as I have already posted (without any calls to glTexEnv*) without the rest of drawing code (that draws 3D models and a text overlay).

This test program correctly displayed the texture. If I call glColor3f, instead of making the entire screen (i.e. the texture that covers the entire screen) that color, it shades it that color. The GL_BGR is correct for how SDL loads .bmp textures.

So, it must be something that is set in the other parts of the rendering that is interfering with the drawing of the texture. Or, perhaps, I am drawing things in the wrong order?

With this thought in mind, I remove all other rendering from my main loop except for the code which renders the full-viewport textured quad. Unfortunately, the problem persists.

Clearly, the texture is there and displayed, since if I modify the glVertex* calls, different segments of the screen are covered by the quad.

Initialization:


int video::load_texture(void)
{ SDL_Surface* tex_image=NULL;

if ((tex_image = SDL_LoadBMP("nehe.bmp")))
{ glEnable(GL_TEXTURE_2D);
glGenTextures(1, &debug_tex);
glBindTexture(GL_TEXTURE_2D, debug_tex);
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glTexImage2D( GL_TEXTURE_2D, 0, 3, tex_image->w, tex_image->h, 0, GL_BGR,
GL_UNSIGNED_BYTE, tex_image->pixels );

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

printf("loaded image!\n");
}
else
{ printf("couldn't load image!\n");
}

if (tex_image) SDL_FreeSurface(tex_image);
}Each frame:


int video::draw(void)
{ glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//glDisable(GL_BLEND);
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D, debug_tex );

glBegin(GL_QUADS);
//glTexCoord2d(0.0,0.0);
glTexCoord2f( 0.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
//glTexCoord2d(0.0,scale_height);
glTexCoord2f( 1.0f, 1.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
//glTexCoord2d(scale_width,scale_height);
glTexCoord2f( 1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
//glTexCoord2d(scale_width,0.0);
glTexCoord2f( 0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glEnd();

glDisable(GL_TEXTURE_2D);

return 1;
} If there are no mistakes in the code above, I suspect other glTexEnv* properties are being set somewhere else (in my font drawing code, perhaps) that are affecting the texture mapping but I do not know what they could be.

silex
05-24-2006, 02:13 PM
Fixed. Apparently I was initializing the texture too early, or something like that. :D