Howdy, Stranger!

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

Categories

Proper Texturing In OpenGL...

SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
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!

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

Comments

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

    [code]
    /* from the top-left corner, to the bottom-left, to the
    * bottom-right of the image.
    */
    glBindTexture(GL_TEXTURE_2D,texture);
    glBegin(GL_TRIANGLES);
    glTexCoord2f(0,1);
    glVertex3f(/*values*/);
    glTexCoord2f(0,0);
    glVertex3f(/*values*/);
    glTexCoord2f(1,0);
    glVertex3f(/*values*/);
    glEnd();
    [/code]

    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.
  • WudanWudan Member Posts: 66
    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, USAMember Posts: 1,035
    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!

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

Sign In or Register to comment.