PDA

View Full Version : Texture on 3d object



jpfelgueiras
03-29-2009, 06:25 AM
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

ZbuffeR
03-29-2009, 06:59 AM
Have a read throught this whole thread :
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=255046&fpart=1

ephtracy
03-29-2009, 07:16 AM
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:)

jpfelgueiras
03-29-2009, 02:36 PM
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

jpfelgueiras
03-29-2009, 03:02 PM
i put the code in : http://pastebin.com/m6092b2fd
for making the things easy

ephtracy
03-29-2009, 10:23 PM
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 )