Skip to main content
GameDev.net gamedev.net
🔒 Locked

texture mapping

Started by emzee Jun 18, 2002 at 4:52 AM 10 replies 1.6k views
Original Post
emzee
emzee
Can anyone help me with my texture mapping app. The texture mapping part is from NeHe-s tutorial. Code is here: #include <gl/glut.h> #include <gl/gl.h> #include <gl/glu.h> #include <gl/glaux.h> unsigned texture[1]; AUX_RGBImageRec *LoadBMP(char *Filename) { ifstream fin(Filename); if(fin.is_open()) { fin.close(); return auxDIBImageLoad(Filename); } return NULL; } bool LoadGLTextures() { bool status=false; AUX_RGBImageRec *TextureImage[1]; memset(TextureImage,0,sizeof(void *)*1); if(TextureImage[0]=LoadBMP("texture.bmp")) { status=true; glGenTextures(1, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if(TextureImage[0]) { if(TextureImage[0]->data) delete TextureImage[0]->data; delete TextureImage[0]; } return status; } void changeSize(int w, int h) { if(h==0) h=1; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0, 0, w, h); gluPerspective(45, (float)w/h, 1, 1000); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0,0.0,5.0, 0.0,0.0,-1.0, 0.0f,1.0f,0.0f); } void renderScene() { glClear(GL_COLOR_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D, texture[0]); glColor3f(0.0, 1.0, 0.0); glPopMatrix(); glRotatef(90, 1.0, 0.0, 0.0); glRotatef(20, 0.0, 0.0, 1.0); glutWireSphere(1.0, 12, 12); glPushMatrix(); glutSwapBuffers(); glFlush(); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitWindowPosition(-1, -1); glutInitWindowSize(1024, 768); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glClearColor(0.0, 0.0, 0.0, 0.0); glutCreateWindow("Globe"); if(!LoadGLTextures()) return 0; glEnable(GL_TEXTURE_2D); glutDisplayFunc(renderScene); glutReshapeFunc(changeSize); glutMainLoop(); return 0; } [edited by - emzee on June 18, 2002 6:40:43 AM]
4llj00rb4ndw1th4r3b3l0ngst0m3p0rn
Crawl
Crawl
My guess is that your getting an undeclared identifier error because your using...

unsigned texture[1];

before it''s declared,... try moving it to the top of your file, right below the includes,.......

-Crawl
--------
SwSh
SwSh
First of all, if you want the texture how it really is, you should set the color to white and not to green:
glColor3f(1.0f, 1.0f, 1.0f);
I think glut should know how it has to assign the texture coordinates to vertices. (I mean, you have to say how it has to be done) I don't use glut, but you should search for that. (now, the texture is displayed but with the wrong texcoords -> only the lower right pixel of your texture is on the object)

===========================
UNKNOWN caused an invalid page fault in module unknown at 0000:bff80eb6
: win98 with multiple sclerose

[edited by - SwSh on June 18, 2002 6:40:57 AM]
emzee
emzee
oh, that just got pasted to the wrong place. The LoadGLTextures() fails.

[edited by - emzee on June 18, 2002 6:47:07 AM]
4llj00rb4ndw1th4r3b3l0ngst0m3p0rn
SwSh
SwSh
one more thingie: glutWireSphere gives a wireframed sphere
if you want a solid one, use: glutSolidSphere
SwSh
SwSh
Did you place the "texture.bmp" file in the right directory?
If you''re using msvc++ and you run the program with ctrl-f5, the working directory is not the /debug or the /release but the one above (where your sources are located)
emzee
emzee
i executed the app manually and the thing didnt even fail, but the texture wasnt loaded.
4llj00rb4ndw1th4r3b3l0ngst0m3p0rn
Crawl
Crawl

glPopMatrix();
glRotatef(90, 1.0, 0.0, 0.0);
glRotatef(20, 0.0, 0.0, 1.0);
glutWireSphere(1.0, 12, 12);
glPushMatrix();


You also got your push/pop reversed..... meaning that each frame another 90 degrees will be added to x-axis, and another 20 degrees to the z-axis...... making the sphere rotate.

This could be the desired effect, but i thought i would point it out.....

-Crawl
--------
SwSh
SwSh
The texture is loaded correctly, but not displayed correctly due to wrong (no) texture coordinates.
You could eventually use quadrics, there are many tutorials on that topic and they give you more control.
see: www.gametutorials.com on the bottom.

just paste:
GLUquadricObj *object = gluNewQuadric();
gluQuadricTexture(object, true);
gluQuadricDrawStyle(object, GLU_FILL);
gluSphere(object, 1.0f, 12, 12);
instead of: glutWireSphere(1.0f, 12, 12);

===========================
UNKNOWN caused an invalid page fault in module unknown at 0000:bff80eb6
: win98 with multiple sclerose
emzee
emzee
nope, the thing still doesnt work. just gives me blank/white sphere.

[edited by - emzee on June 19, 2002 4:41:15 PM]
4llj00rb4ndw1th4r3b3l0ngst0m3p0rn
SporadicFire
SporadicFire
what size are you textures? they should be 32x32 or 64x64 or 128x128 or 256x256 or they wont work..
emzee
emzee
That solved the problem, thank you.
4llj00rb4ndw1th4r3b3l0ngst0m3p0rn

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.