[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

opengl and textures



I can't understand why, instead of drawing a texture, it draws only a white 
(or whatever glColor sets)  square.

After glEnable()s and glAlphaFunc, i draw two quads with two different 
textures:

//==========================================================
 glColor3f(1.0, 1.0, 1.0);
 glEnable(GL_TEXTURE_2D);
 glEnable(GL_ALPHA_TEST);
 glAlphaFunc(GL_GREATER, 0.5);

 bind_select_tex();	//calls glBindTexture()
 glBegin(GL_QUADS);
    glTexCoord2f(0.0, 1.0); glVertex2f(-1.0, -1.0);	// bottom left	//
    glTexCoord2f(0.0, 0.0); glVertex2f( 1.0, -1.0);	// bottom right	//
    glTexCoord2f(1.0, 0.0); glVertex2f( 1.0,  1.0);	// top right	//
    glTexCoord2f(1.0, 1.0); glVertex2f(-1.0,  1.0);	// top left	//
 glEnd();

 glBindTexture(GL_TEXTURE_2D, t->gltext);
 glBegin(GL_QUADS);
    glTexCoord2f(0.0, 1.0); glVertex2f(-1.0, -1.0);	// bottom left	//
    glTexCoord2f(0.0, 0.0); glVertex2f( 1.0, -1.0);	// bottom right	//
    glTexCoord2f(1.0, 0.0); glVertex2f( 1.0,  1.0);	// top right	//
    glTexCoord2f(1.0, 1.0); glVertex2f(-1.0,  1.0);	// top left	//
 glEnd();
//============================================================
int bind_select_tex()
{
 glBindTexture(GL_TEXTURE_2D, select_tex);
}
//=============================================================

While the first quad is flat white, the second (a transparent tank) is drawn 
properly, so i suppose it is just a texture loadup problem.
The loadup code is:

//=============================================================
p = png_load(select_tex_fn);	// load "select.png"
 if(!p)
    {
	pr("png_load");
	pe("unable to load %s, aborting.\n", select_tex_fn);
	return -1;
    }
 glGenTextures(GL_TEXTURE_2D, &select_tex);
 glEnable(GL_TEXTURE_2D);	// should be useless? //
 bind_select_tex();
 glTexImage2D(
    GL_TEXTURE_2D,	// target //
    0,			// mipmap depth //
    4,			// components //
    p->w,		// width //
    p->h,		// height //
    0,			// border //
    GL_RGBA,		// format //
    GL_UNSIGNED_BYTE,	// pixel type //
    p->d		// image data //
 );
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 glDisable(GL_TEXTURE_2D);

 free(p);
//========================================================
I almost copied the loadup code i used with the tank texture...

Any idea/suggestion?
Is there any book/online-resource where i could find answer to such questions 
without annoying others?

Hope the post is not too big...

Thanx,
Francesco Orsenigo