Skip to main content
gamedev.net
🔒 Locked

texture changes

Started by AcidZombie24 Dec 10, 2008 at 7:39 PM 0 replies 800+ views
Original Post
AcidZombie24
AcidZombie24
i am a 3d noob. I remember that texture changes should be avoided and i know its faster to render via array then calling glVertex3f. So i wanted to know how do i set this up? Do i want a few vector loop through my sprites (this is for 2d) figure out what texture file it is using then stick it in the proper vector? But all of this would be CPU based and nothing would be on the video card? Is putting data on the videocard only useful when i have many vertices relative to eachother? Now that i think of it the only way its useful is if they are relative and i do a glTranslatef in between each mesh? I am not exactly sure how performance is and i like to read a few tutorials but is what i know right? (otherwise i'll read something and think it works differently then it does bc what i know is not true)
<SkilletAudio> Your framerate proves your lack of manhood
spek
spek
There is not perfect way to do things. The key is balancing. CPU and GPU should cooperate. So, if the GPU has not much to do, you should try to do the graphical related stuff as much as possible on the GPU. On the other hand, don't forget the CPU neither. Don't be afraid to switch textures, as long as you don't do it thousands of times. If possible, avoid unnessesary switches, but also don't strangle yourself with nearly impossible approaches. Current hardware can do quiet alot :)

I'm not sure what you are trying to do, but as for sprites, atlas textures are a good way to do things in common. That means that you draw all frames on 1 big texture. This is usefull if you have a lot of the same sprites on your screen (20 Doom2 Imps for example). Each character could have another frame, but the texture stays the same. You only have to adjust the texture coordinates. This can be done on the CPU, or in the vertex shader by giving the current frame index (all the frames should be positioned in a uniform grid though). Thus:
1.- Set atlas texture active on the video card
2.- Render all sprites that use this texture:
2.b- For each sprite, set the proper texture coordinates (glTexcoord2f(...)) with the CPU, or pass the frame ID to a vertex shader via a parameter and let the shader calculate the coordinates.
3.- Unapply the texture / switch to the next

Greetings,
Rick

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.