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

Thread: Texture Problem

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2002
    Location
    San Jose, CA, USA
    Posts
    9

    Texture Problem

    I am having a problem displaying my texture using a quad. If I draw it using glDrawPixels, its ok. I would rather use a quad since it is more flexible. The pixel data is stored in an array as unsigned chars.

    Below is the code snippets. Can anyone tell me what I am doing wrong? Thanks!

    // generate a 2d texture image from an arary
    pBitmap->w = (int)array[0]; // first 2 entries hold width & height.
    pBitmap->h = (int)array[1];
    pBitmap->pixels = &array[2];
    glGenTextures( 1, &(pBitmap->texId) );
    glBindTexture(GL_TEXTURE_2D, pBitmap->texId );
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, pBitmap->w, pBitmap->h, 0, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->pixels );


    // draw a texture (2d) x axis acoss, y axis down

    #if 1

    glRasterPos2f( (float)x+.5, (float)y + (float)pBitmap->h + .5);
    glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
    glDrawPixels( pBitmap->w, pBitmap->h, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->pixels );

    #else

    glEnable( GL_TEXTURE_2D );
    glBindTexture( GL_TEXTURE_2D, pBitmap->texId );

    glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
    glBegin( GL_QUADS);

    // Bottom Left
    glTexCoord2f( 0, 0 );
    glVertex2i( x, y );
    // Top left
    glTexCoord2f( 0, 1 );
    glVertex2i( x, y+h );
    // Top right
    glTexCoord2f( 1, 1 );
    glVertex2i( x+w, y+h );
    // Bottom right
    glTexCoord2f( 1 , 0 );
    glVertex2i( x+w, y );
    glEnd();
    glDisable( GL_TEXTURE_2D );

    #endif

  2. #2
    Member Contributor
    Join Date
    Apr 2002
    Location
    UK
    Posts
    50

    Re: Texture Problem

    Can you see the Quad ok?

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2002
    Location
    San Jose, CA, USA
    Posts
    9

    Re: Texture Problem

    yes. I get a white quad. At first, i thought it was back face culling. But, I turned back face culling on & the quad is still there. Then, I thought it was the vertex order, so I tried changing it around. Nothing seems to get it to work....
    I assume it is something I am doing wrong in the texture setup phase.

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

    Re: Texture Problem

    Does your texture have dimensions that are a power of 2? ie. 32x32, 64x32, 128x128, etc..

    If not, then that is your problem.
    Deiussum
    Software Engineer and OpenGL enthusiast

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2002
    Location
    San Jose, CA, USA
    Posts
    9

    Re: Texture Problem

    The textures are powers of 2. ( 128x128 & 64x64 )
    All the gl commands are not returning any errors.
    The texture ID's seem to be ok.
    Are there some glEnable or disable commands I can try turning on/off that might help determine what is going on?

  6. #6
    Member Contributor
    Join Date
    Apr 2002
    Location
    UK
    Posts
    50

    Re: Texture Problem

    Have you tried using build2dmipmaps to create your trxture?

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

    Re: Texture Problem

    Are you creating the textures after you've initialized the window to use OpenGL?
    Deiussum
    Software Engineer and OpenGL enthusiast

  8. #8
    Member Contributor
    Join Date
    Jun 2002
    Location
    Alamogordo, NM USA
    Posts
    67

    Re: Texture Problem

    What are the physical sizes of your textures?
    Japanese Proverb: "Talk about things of tomorrow and the mice in the ceiling laugh."

  9. #9
    Senior Member Regular Contributor
    Join Date
    Sep 2001
    Location
    macedon, ny
    Posts
    288

    Re: Texture Problem

    Im not sure what you are doing wrong, but the above code would be much much simpler using the library "devIL" you can find it at www.imagelib.org its opengl syntax and very intuitive.

    Here is an example of loading an image into OpenGL
    ILuint Image;

    ilGenImages(1, &Image);
    ilBindImage(Image);
    ilLoadImage("WhateverIwant.tga");
    ilutGLBindTexImage();
    ilDeleteImages(1, &Image);
    glBindTexture (GL_TEXTURE_2D, Image);

    and bang your done. Now everything is bound, gaged, and set for opengl. That easy. you can also build MipMaps this way, with a call to ilBindMipmaps(image); instead of ilBindImage, and boom your mipmaps are done. I would recomend this way. But as I stated before, no idea what your current problem is.

  10. #10
    Junior Member Newbie
    Join Date
    Jun 2002
    Location
    San Jose, CA, USA
    Posts
    9

    Re: Texture Problem

    Pops - Nope. How would this help?
    Deiussum - Yes. There are no reported opengl errors.
    Jeffry - 128x128 & 64x64.

    I am going to set this on the back burner for now & come back to it in a couple of days once I finished fleshing out some other sections of code.

    Thanks for the help.

Page 1 of 2 12 LastLast

Similar Threads

  1. Render to texture problem or problem in approach
    By Taimoorak in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-07-2018, 06:04 AM
  2. Replies: 1
    Last Post: 01-10-2005, 09:50 AM
  3. Replies: 0
    Last Post: 01-09-2005, 06:01 PM
  4. Replies: 0
    Last Post: 01-09-2005, 05:53 PM
  5. Replies: 1
    Last Post: 01-09-2005, 05:50 PM

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