Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: What's wrong with my texture

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    13

    What's wrong with my texture

    It does not render with texture. The triangle and the sphere are rendered with the last-used blue color.

    What's wrong with it? Thanks a lot!

    On init:
    Code :
    ......
    FIBITMAP* tmp = FreeImage_Load(FIF_JPEG,"gstar.jpg",0);
    FIBITMAP* img = FreeImage_ConvertTo32Bits(tmp);
    FreeImage_Unload(tmp);
     
    glGenTextures( 1, &texture );
    glBindTexture(GL_TEXTURE_2D,texture);
    glTexImage2D(
    	GL_TEXTURE_2D, 0, GL_RGBA,
    	FreeImage_GetWidth(img), FreeImage_GetHeight(img),
    	0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,
    	FreeImage_GetBits(img) );
    printf("generated texture: %d\n",texture);
    ......

    On drawing:
    Code :
    ......
    // draw axis
    glBegin(GL_LINES);
    	glColor3f(1,0,0);
    	glVertex3d(0,0,0);
    	glVertex3d(100,0,0);
     
    	glColor3f(0,1,0);
    	glVertex3d(0,0,0);
    	glVertex3d(0,100,0);
     
    	glColor3f(0,0,1);
    	glVertex3d(0,0,0);
    	glVertex3d(0,0,100);
    glEnd();
     
    // textured triangle
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texture);
    glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
    glBegin(GL_TRIANGLES);
    	glNormal3d(1,1,1);
     
    	glTexCoord2f(0,0);
    	glVertex3d(5,0,0);
     
    	glTexCoord2f(1,0);
    	glVertex3d(0,5,0);
     
    	glTexCoord2f(0,1);
    	glVertex3d(0,0,5);
    glEnd();
    glDisable(GL_TEXTURE_2D);
     
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texture);
    gluSphere(quad,2,32,32);
    glDisable(GL_TEXTURE_2D);
     
    ......

  2. #2
    Member Contributor
    Join Date
    Jan 2011
    Posts
    78

    Re: What's wrong with my texture

    Quote Originally Posted by Xi Yang
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
    FreeImage_GetWidth(img), FreeImage_GetHeight(img),
    0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,
    FreeImage_GetBits(img) );
    GL_UNSIGNED_INT_8_8_8_8? You probably meant GL_UNSIGNED_BYTE. Anyways, why call glTexEnv? If you remove it, your texture should show up.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    13

    Re: What's wrong with my texture

    Quote Originally Posted by DarkGKnight
    Quote Originally Posted by Xi Yang
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
    FreeImage_GetWidth(img), FreeImage_GetHeight(img),
    0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,
    FreeImage_GetBits(img) );
    GL_UNSIGNED_INT_8_8_8_8? You probably meant GL_UNSIGNED_BYTE.
    I've tried GL_UNSIGNED_BYTE. It don't works either.

  4. #4
    Member Contributor
    Join Date
    Jan 2011
    Posts
    78

    Re: What's wrong with my texture

    What about removing glTexEnv?

  5. #5
    Senior Member Regular Contributor
    Join Date
    Oct 2009
    Posts
    463

    Re: What's wrong with my texture

    Have you loaded mipmaps for each level, or alternatively disabled mipmaps for the texture? Since according to the spec:
    Quote Originally Posted by OpenGL_4.1_Spec
    In the initial state, the value assigned to TEXTURE_MIN_FILTER is NEAREST_MIPMAP_LINEAR (except for rectangular textures, where the initial value is LINEAR), and the value for TEXTURE_MAG_FILTER is LINEAR

  6. #6
    Member Contributor
    Join Date
    Jan 2011
    Posts
    78

    Re: What's wrong with my texture

    On my system, the triangle is textured, but the sphere is not. To enable texturing of the sphere, gluQuadricTexture must be called.
    Thus, at minimum, your triangle should be textured. Therefore, you are most likely experiencing a driver bug. Are you testing this code on Intel GPU hardware?

  7. #7
    Senior Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    458

    Re: What's wrong with my texture

    Use gluBuild2DMipmaps instead of glTexImage2D if you just start with GL. This will avoid unexpected unrendered textured.

  8. #8
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    13

    Re: What's wrong with my texture

    Quote Originally Posted by DarkGKnight
    On my system, the triangle is textured, but the sphere is not. To enable texturing of the sphere, gluQuadricTexture must be called.
    Thus, at minimum, your triangle should be textured. Therefore, you are most likely experiencing a driver bug. Are you testing this code on Intel GPU hardware?
    My platform is: Fedora 14, with Nvidia 8XXXM chip, using the driver from rpmfusion, version 1:260.19.36-1.fc14, using the libGL.so provided by Nvidia driver.

    Moreover, I did not mention that the quadric is actually enabled texturing:
    Code :
    int main(int argc, char **argv) {
    	srand48(1);
     
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    	glutInitWindowSize(400,400);
    	glutInitWindowPosition(100,100);
    	glutCreateWindow("run");
     
    	glutDisplayFunc(on_display);
    	glutMouseFunc(on_mouse);
    	glutMotionFunc(on_motion);
    	glutSpecialFunc(on_keyboard);
    	init();
     
    	// init global objects
    	quad = gluNewQuadric();
    	gluQuadricOrientation(quad,GLU_OUTSIDE);
    	gluQuadricDrawStyle(quad,GLU_FILL);
    	gluQuadricNormals(quad,GLU_SMOOTH);
    	gluQuadricTexture(quad,GL_TRUE);
     
    	glutMainLoop();
    	exit(0);
    }

  9. #9
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    13

    Re: What's wrong with my texture

    Quote Originally Posted by _arts_
    Use gluBuild2DMipmaps instead of glTexImage2D if you just start with GL. This will avoid unexpected unrendered textured.
    It works!! Thanks a lot!!!
    So, the system don't happy if I don't provide it the full series of mipmapping?

  10. #10
    Senior Member Regular Contributor
    Join Date
    Oct 2009
    Posts
    463

    Re: What's wrong with my texture

    If this is your only texture loading code:
    glGenTextures( 1, &texture );
    glBindTexture(GL_TEXTURE_2D,texture);
    glTexImage2D(
    GL_TEXTURE_2D, 0, GL_RGBA,
    FreeImage_GetWidth(img), FreeImage_GetHeight(img),
    0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,
    FreeImage_GetBits(img) );
    printf("generated texture: %d\n",texture);
    Then you aren't filling all the levels of the texture, so your texture won't be complete, and binding the incomplete texture to a texture unit will cause texturing for the texture unit you bind that texture to be disabled.

    You have several options:
    1) You can either generate the required levels from the level 0 image, using glGenerateMipmap(GL_TEXTURE_2D) (recommended) or gluBuild2DMipmap or glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE).

    2) You can load each level of the texture manually, eg. for an 8x8 texture image, you would also need to load 4x4, 2x2 and 1x1 images too:
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, img_level[0]);
    glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, img_level[1]);
    glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, img_level[2]);
    glTexImage2D(GL_TEXTURE_2D, 3, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, img_level[3]);

    3) You can disable mipmaps (not recommended except in certain situations):
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

Page 1 of 2 12 LastLast

Similar Threads

  1. Texture being rendered wrong
    By Shedex in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-21-2016, 03:15 PM
  2. What's wrong with the texture ??
    By in forum OpenGL: Basic Coding
    Replies: 12
    Last Post: 08-05-2004, 11:06 PM
  3. texture creating: what's wrong?
    By Digital-fol in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-26-2004, 02:33 PM
  4. .ASE texture coord wrong?
    By robfram in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-10-2001, 01:21 AM
  5. What's wrong with my texture mapping?
    By in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 07-28-2000, 12:10 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