Texture Mapping

Started by
0 comments, last by HypnotiC 11 years ago

How do I display multiple textures? for example, I created to polygons, one for the Background Picture, and another one for the sprite. I am using SOIL (Simple OpenGL Image Library) to load png files into the textures, so far I am successful in displaying either one of the two textures, but how do I display them both? I uploaded my source code. [attachment=14890:opengl_sample.txt] Also, I do not know how to display the texture with the correct corresponding size with the png file, for example, the image file is 76 x 80, but when i display it it becomes so large. I need help, I am kinda noobish. sad.png

Advertisement

1. the reason you can't display both texture is the following:

In each frame, you set the model view matrix to identity, which maps the whole viewport to [-1,1]x[-1,1].

And both of your calls to Render() draw the quad covering [-1,1]x[-1,1].

So now you load first texture and draw a quad, the texture will be mapped to whole viewport,

then you load the second texture and draw a quad, which is also mapped to the whole viewport (so the second one overlaps the first one).

Thus you can only see one texture.

2. As for the texture size,

1) because you model view matrix is identity,

2) and you quad covers the whole viewport,

3) your texture coordinates cover the whole image

so you always see the texture as big as your viewport, right?

You can change any of 1)~3), for example, change from Render(1,1,0) to Render(0.5,0.5,0), then the texture would be come 1/4 of the original size

[ if you choose 3), you may also need to change the wrap options ]

Hope this helps

This topic is closed to new replies.

Advertisement