Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Texture on 3d object

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2009
    Posts
    3

    Texture on 3d object

    Hy there.
    I'am studing computer grafics, and start to learn abou OpenGl.I have to put textures (in bmp file) on a pyramid and i coulden't do it...I whant to kown if some one is dispose to help me ...

    tks mates

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Texture on 3d object

    Have a read throught this whole thread :
    http://www.opengl.org/discussion_boa...255046&fpart=1

  3. #3
    Intern Newbie
    Join Date
    May 2007
    Location
    China
    Posts
    35

    Re: Texture on 3d object

    1. an easier way to load bmp file is using 'auxDIBImageLoad'
    notice that the size of the image is better of power of two, you could use 'gluScaleImage' to scale your image to a proper size.

    2. before using a texture, you should create a texture object at first. something like this :

    glGenTexture( 1, &handle );

    3. active texture target, bind the object, load pixels into buffer, for example :

    glEnable( GL_TEXTURE_2D );
    glBindBuffer( handle );

    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels );

    glBindBuffer( 0 );
    glDisable( GL_TEXTURE_2D );

    4. use this as a texture

    glEnable( GL_TEXTURE_2D );
    glBindBuffer( handle );

    // set filter
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

    // set wrap mode
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

    // draw something ...

    glBindBuffer( 0 );
    glDisable( GL_TEXTURE_2D );

    hope this will work

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2009
    Posts
    3

    Re: Texture on 3d object

    tks for all the help, but i whas enable to do it ...

    i will send my code for you to try...

    http://www.megaupload.com/?d=2SUADFHF

    by mates

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2009
    Posts
    3

    Re: Texture on 3d object

    i put the code in : http://pastebin.com/m6092b2fd
    for making the things easy

  6. #6
    Intern Newbie
    Join Date
    May 2007
    Location
    China
    Posts
    35

    Re: Texture on 3d object

    Quote Originally Posted by ephtracy
    glEnable( GL_TEXTURE_2D );
    <s>glBindBuffer( handle );</s>
    glBindTexture( GL_TEXTURE_2D, handle );

    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels );

    glBindTexture( GL_TEXTURE_2D, 0 );
    <s>glBindBuffer( 0 );</s>
    glDisable( GL_TEXTURE_2D );
    I am sorry that I made a big mistake for binding texture.
    there is no 'glBindBuffer( handle )' function, so use this instead :

    glBindTexture( GL_TEXTURE_2D, handle );

    you could visit http://nehe.gamedev.net/ where you could found some tutorials that may be helpful to you.
    ( maybe lesson 6 : Texture Mapping )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •