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. opengl_sample.txt 6.24KB 42 downloads 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.
Members - Reputation: 112
Posted 17 April 2013 - 09:34 AM
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
Edited by HypnotiC, 17 April 2013 - 09:36 AM.