Proper Texturing In OpenGL...

SephirothSephiroth Fayetteville, NC, USA
OK, I now have bitmap loading working, but the image appears all stretched and distorted on my polygons. I am using triangles since they are drawn the fastest, but somehow the bitmap (32x32) is drawn onto the triangle as though the image was a triangle as well! I am using "Carved Stone.bmp" from the windows directory for now. I saved it as a 24bit bitmap in my AoY_SE/Textures directory. How should I properly map the texture onto a triangle? Thanks for the help!



  • ive had that problem before. cant exactly remember the last time i mapped a texture over a triangle. this should work

    /* from the top-left corner, to the bottom-left, to the
    * bottom-right of the image.

    but you probably have exactly that... i will check later, i havent slept in a while, logic gone, thinking abandoned hours ago, so im probably wrong. if you are using coordinates that are floating point values then it wont work. any texture <= 32x32 cant have texture coords other than 0 or 1. i dont know why, but this is how i found it to be. just resize your image if thats what you are doing.
  • Sounds like a texture co-ordinate problem. Each vertex of your triangle should have a texture co-ordinate as well. The texture co-ordinate is an x/y offset into your bitmap. ( texture co-ords are usualy named u,v instead of x,y ) Its difficult to help as I cant see the result.
    When texture co-ords are expressed as floating point values, this means that they are a percentage of the width/height of the bitmap. So for your 32X32 bmp, a uv of 0.0,0.0 will be top left. 1.0, 1.0 will be bottom right. 0.5, 0.5 will be the middle. This is so you can substitute higher res bitmaps and keep the same texture co-ords.
  • SephirothSephiroth Fayetteville, NC, USA
    Thanks guys, but I fixed it a while back. I accidentally had the glVertex3f() function in front of glTexCoord2f(), thus screwing it royally! Now if I can get a collision-detection function working I'll be set! I already wrote a short function that checks ticks each program loop and varies how far/fast objects move based ont he result. This means that you get framerate independant movement of everything in the game!


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!