PDA

View Full Version : why my texture is not displayed ?



airseb
05-06-2003, 12:11 PM
do i have to do something with my bmp file and visual c++ ?
And can you tell me why GL_TRIANGLE_FAN works here and not GL_TRIANGLES ?




#include <gl\GLAUX.h>
#include <gl\glut.h>
#include <gl\gl.h>


GLuint texname[1] ;

void init ()
{
AUX_RGBImageRec *texture1;
texture1 = auxDIBImageLoad("D:\\programmation\\[Mes programmes Open GL]\\Logo.bmp");
glGenTextures (1, texname) ;
glBindTexture (GL_TEXTURE_2D, texname[0]) ;
glTexImage2D(GL_TEXTURE_2D, 0, 3, (texture1)->sizeX, (texture1)->sizeY,
0, GL_RGB, GL_UNSIGNED_BYTE, (texture1)->data);
glEnable(GL_TEXTURE_2D) ;
}


void reshape (int w, int h)
{
glViewport (0, 0, w, h) ;
glMatrixMode (GL_PROJECTION) ;
glLoadIdentity () ;
glFrustum(-5.0 , 5.0, -15.0, 5.0, 5.0, 500.0); //perspective conique
glMatrixMode(GL_MODELVIEW); //la matrice active de modelisation/visualisation sera affectée
glLoadIdentity(); //charge la matrice identité

gluLookAt (0.0, 0.0, -5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0) ;
}

void display ()
{

//glPolygonMode (GL_FRONT_AND_BACK, GL_LINE) ;

glClear (GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT ) ;
glBindTexture (GL_TEXTURE_2D, texname[0]) ;
glBegin (GL_TRIANGLE_FAN) ;
glTexCoord2f(1.0, 0.0) ; glVertex3f (-1.0, -1.0, 0.0) ;//les coordonnées sont fausses, corrigez les
glTexCoord2f(1.0, 1.0) ; glVertex3f (-1.0, 1.0, 0.0) ;
glTexCoord2f(0.0, 1.0) ; glVertex3f (1.0, 1.0, 0.0) ;
glTexCoord2f(0.0, 0.0) ; glVertex3f (1.0, -1.0, 0.0) ;
glEnd () ;

glutSwapBuffers() ;

}


void main (int argc, char** argv)
{

//cout<<"hello"<<endl ;

glutInit (&amp;argc, argv) ;
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) ;
glutInitWindowSize (640, 480) ;
glutInitWindowPosition (250,250) ;
glutCreateWindow (argv [0]) ;
glEnable( GL_DEPTH_TEST );

init () ;
glutReshapeFunc (reshape) ;
glutDisplayFunc (display) ;
glutMainLoop () ;
}

Deiussum
05-06-2003, 12:35 PM
You're just going to keep posting your code to new threads for each new problem, aren't you? http://www.opengl.org/discussion_boards/ubb/smile.gif

Textures need to have dimensions that are a power of 2. My guess is, yours doesn't.

When you say triangles don't work, are you just changing GL_TRIANGLE_FAN to GL_TRIANGLES? If so, that won't work. You've only got 4 vertices, and therefore only 1 full triangle. That last vertex will simply be ignored.

Bob
05-06-2003, 12:46 PM
You're not providing a full mipmap set for the default minification filter. Either create a full mipmap set or set the minification filter to a non-mipmap filter like GL_NEAREST or GL_LINEAR.

airseb
05-07-2003, 07:02 AM
Originally posted by Bob:
You're not providing a full mipmap set for the default minification filter. Either create a full mipmap set or set the minification filter to a non-mipmap filter like GL_NEAREST or GL_LINEAR.

thanks bob and Deiussum, it works now ! http://www.opengl.org/discussion_boards/ubb/biggrin.gif
but i would like to know why we are forced to use glParameteri ?
and what is the minification filter ? maybe i know it in my language but in english i don't see what it is, can you explain it to me ?

Deiussum
05-07-2003, 07:20 AM
You have to set it because the default value is set to mip maps. Basically, it has to do with how the texture is shrunk.

For instance, when you draw the quad further away in a perspective view, the area the texture is drawn to gets smaller. With mip mapping, you have multiple images that are basically the same, but are different sizes, so the most appropriate size is chosen.

You should also probably set the magnification filter, as that also is defaulted to use mip mapping.