Archived

This topic is now archived and is closed to further replies.

Wodzu

problems with Automatic Texture-Coordinate Generation

Recommended Posts

Wodzu    122
Hi, i am begining my adventure with OpenGl. I've read a tutorial about texture mapping, but there is no tutorial how to map a texture on object with many vertex. For example a Sphere... How to automaticaly map texture on it? I know i should use GlTexGen(), but have problems with that... Here is a code how i load a texture and how i create a sphere... procedure LoadGLTextures; var texture1: PTAUX_RGBImageRec; begin // Load Texture texture1 := auxDIBImageLoadA('C:\earth.bmp'); if (not Assigned(texture1)) then Halt(1); // Create Texture glGenTextures(1, texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1^.sizeX, texture1^.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1^.data); end; function InitGL:bool; // All Setup For OpenGL Goes Here var Kula: GLUquadricObj; begin LoadGLTextures(); // Load The Texture(s) glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading glClearColor(0.0, 0.0, 0.0, 0.0); glClearDepth(1.0); // Depth Buffer Setup glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); // Enables Depth Testing glDepthFunc(GL_LESS); // The Type Of Depth Test To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); ListaCial:= glGenLists(1); Kula:=gluNewQuadric(); gluQuadricDrawStyle(Kula, GLU_FILL); //* smooth shaded */ gluQuadricNormals(Kula, GLU_SMOOTH); glNewList(ListaCial, GL_COMPILE); gluQuadricTexture(Kula,GL_TRUE); glTexCoord2f(1,1); gluSphere(Kula,1,75,20); glEndList(); initGL:=true; end; And here is how draw the scene function DrawGLScene():bool; begin glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // Reset The View glTranslatef(0.0,0.0,-8.0+x); glColor3f(0.7,0.0,0.0); glCallList(ListaCial); DrawGLScene:=true; // Everything Went OK end; I will be very greatfull is someone tells me what should i add to my code to map texture on sphere. Regards, Wodzu [edited by - Wodzu on September 1, 2003 9:28:42 AM]

Share this post


Link to post
Share on other sites
RipTorn    722
you don''t need to use glTexGen.

since your using GLU quadratics, the gluSphere command will make all the appropriate calls to glBegin/glEnd and setup the vertices with glVertex## If you also want normals, then you use gluQuadricNormals to set the draw style to generate normals (so gluSphere will also make the appropriate calls to glNormal##
Hence, if you also want texture to be applied, you need gluSphere to also make calls to glTexCoord##, then you need to set the texturing style with gluQuadricTexture.

simple, really.

| - Project-X - On hold (kindof ).. - | - adDeath - | - email me - |

Share this post


Link to post
Share on other sites
Wodzu    122
I still dont understand how exactly tha should be done;(
I modified my code slightly, could you look on it and show me where i have made a mistake? Still i dont see texture on Sphere, i see only Red Sphere...

I am asking You for a patience

Thanks for Your time,

Regards,
Wodzu

Ps. And i dont know how to setup the GlTextCoord##

[edited by - Wodzu on September 1, 2003 9:32:55 AM]

Share this post


Link to post
Share on other sites