Opengl drawing many textures!

Started by
16 comments, last by brunooo 14 years, 7 months ago
Thank you, I will need to group the textures together to not bind them many times.

VBO's and Frame buffers will work on every computer with a gpu? Or it will only work on newer ones like I read that Shader only work in newer gpus (correct me if I am wrong). I want my game to run on my grandma computer with a very old gpu of 32 MB :) (At the moment it is working smoothly :D)
Advertisement
Why it is a wrong method I posted?
Nanoha's approach has one drawback: if the texture changes many times (for example checked pattern), it will mean no speed boost.
glBindTexture(GL_TEXTURE_2D, texture1);glBegin(GL_QUADS);for(int i = 0; i < numTiles; i++){        if(  tiles.texture == texture1)        {       vertices/tex to draw quad (use actual vertices not translate)                   }}glEnd();glBindTexture(GL_TEXTURE_2D, texture2);glBegin(GL_QUADS);for(int i = 0; i < numTiles; i++){        if(  tiles.texture == texture2)        {       vertices/tex to draw quad (use actual vertices not translate)                   }}glEnd();glBindTexture(GL_TEXTURE_2D, texture3);...//or place it in a loop too.
This way, you have exactly the same number of binding/begin-end, as your types of textures. The extra time spent in the more loops is negligible compared to the other methods. I'm beginning to think that my posts are invisible, or maybe I became the legendary ABARABA?
To Szecs: Nanoha's approach is cleaner and more general (ie no advance knowledge of tile textures needed). He also mentioned to sort the tiles based on texture, so a checkerboard will not cause needless state changes :)
Quote:Original post by szecsor maybe I became the legendary ABARABA?


Lol Szecs, I did mine based on yours :P so your certainly not invisible. Its yours just a little more general/expandable. Each tile should be sorted based on texture first. So if its a checkbord type texture all the tiles would be sorted white first, then all the black ones so only 2 texture changes will be done.

If there are 200 different textures then yes, there will have to be 200 different texture changes but thats a problem with any method.

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

I see, I overlooked the sorting thing. (So I am really like ABARABA)
BertS is right, Ive been thinking, I cant use glRotatef between glBegin()/glEnd(), can I?
Quote:Original post by szecs
Texture binding and transformations aren't allowed between glBegin-glEnd
The same with state changes (glEnable/Disable)
Thanks again! I used stl map to group the textures with same texture object, and every loop I clear and refill it. I was not gaining performance than I profiled my program and found that the problem now is with stl maps :p, I will do something to not clear and refill it every time!

This topic is closed to new replies.

Advertisement