Sign in to follow this  

texture mapping question

This topic is 2545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've just started learning OpenGL and well I've been trying to get texture mapping working. I've written my own bitmap class to load 24bpp bmps. It seems to work perfectly. I even manage to render some of it to the screen but it's a bit strange.

This is what it shows: http://img232.imageshack.us/img232/6237/errorlg.jpg
and my OpenGL code: http://pastebin.com/tuuZnR9N

It should only be displaying the red image(魔)... and only one of them (not 3) in the WHOLE square.

Share this post


Link to post
Share on other sites
You need to change the width and height of your texture. It's the same thing if you're going to use a texture for a sprite sheet. you only want to use a section of it at a time. So lets say that the actual bitmap or targa file has a length of 15and a width of 15. Now lets say that each individual image on the sprite sheet is 5 pixels wide and five pixels tall. To only display the first image in the sprite sheet you'd need to list the origin of the image (if the origin is at the bottom left corner of the image) at (0, 10). When you want to display the next sprite in the sheet you'd increment it the left (5,10) and so on until you get to the end of the first row (10,10). Then you'd move to the next row (0, 5). Repeat and then go the the last row (0, 0). Simple example but you get the idea.

Share this post


Link to post
Share on other sites
In your code you map the entire DEMON texture to the quad. What does demon.bmp look like? Is it just one symbol, or 6 symbols?

If it is just one symbol, then it appears you have an error in the way you load the textures, probably in the readBMP function of your Bitmap class.

Does it appear correctly is you load and display just one bmp file?

Share this post


Link to post
Share on other sites
thank you!!! it works... it was my getWidth function... i was returning the width*3 (*3 because 3 bytes per pixel...)... once i re-adjusted that and returned it worked :)

Share this post


Link to post
Share on other sites
Ok, now I'm trying to make a cube with my 6 textures I've made. First I'm only using 1 texture for all 6 sides. It works but looks a little weird.

result: http://img257.imageshack.us/img257/8420/24bmprendered.png

I figure it has to do with the glTexCoord2f and glVertex3f calls I'm doing. I've rewritten them thinking about it but it doesn't look right still.

Also, the rate at which something renders is machine dependent... so, on another machine my cube will be rotating at a different speed with this code right? Is there an easy way to control this?


void renderScene(void) {

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,PROTECTION);

glRotatef(rquadx,1.0f,0.0f,0.0f);
glRotatef(rquady,0.0f,1.0f,0.0f);
glRotatef(rquadz,0.0f,0.0f,1.0f);

glBegin (GL_QUADS);

//front
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.25f, 0.25f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.25f, 0.25f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.25f, -0.25f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.25f, -0.25f, 0.0f);

//back
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.25f, 0.25f, -0.5f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.25f, 0.25f, -0.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.25f, -0.25f, -0.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.25f, -0.25f, -0.5f);

//right
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.25f, 0.25f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.25f, 0.25f, -0.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.25f,-0.25f, -0.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.25f,-0.25f, 0.0f);

//left
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.25f, 0.25f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.25f, 0.25f, -0.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.25f,-0.25f, -0.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.25f,-0.25f, 0.0f);

//top
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.25f, 0.25f, -0.5f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.25f, 0.25f, -0.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.25f, 0.25f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.25f, 0.25f, 0.0f);

//bottom
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.25f, -0.25f, -0.5f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.25f, -0.25f, -0.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.25f, -0.25f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.25f, -0.25f, 0.0f);

glEnd ();
glFlush();
glutSwapBuffers();

rquadx += 0.003f;
rquady += 0.002f;
rquadz += 0.004f;
}

Share this post


Link to post
Share on other sites

This topic is 2545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this