Results 1 to 5 of 5

Thread: why my texture is not displayed ?

  1. #1
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    France
    Posts
    286

    why my texture is not displayed ?

    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 ?

    Code :
    #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 () ;
    	}

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: why my texture is not displayed ?

    You're just going to keep posting your code to new threads for each new problem, aren't you?

    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.
    Deiussum
    Software Engineer and OpenGL enthusiast

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: why my texture is not displayed ?

    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.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    France
    Posts
    286

    Re: why my texture is not displayed ?

    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 !
    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 ?

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: why my texture is not displayed ?

    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.
    Deiussum
    Software Engineer and OpenGL enthusiast

Similar Threads

  1. Graphics Displayed in Windows Photo Viewer vs OpenGL Texture Rendering
    By OceanJeff40 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-12-2018, 06:29 AM
  2. Texture loaded with SOIL isn't displayed
    By 6krktr in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-15-2017, 08:42 AM
  3. Nothing displayed
    By 3DPrgmer in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 09-08-2016, 03:22 AM
  4. Only one pixel of a texture is displayed
    By Alexandre++ in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-03-2011, 09:24 AM
  5. vertex array and texture : no texture displayed
    By jean-luc in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 02-03-2010, 08:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean