Efficency

Started by
29 comments, last by LessThanJoe 21 years, 11 months ago
all rightyo, I''ve a 2d array that is 800x600. Each spot holds a number 0-4 for the color I want at that spot. When outputing this...1 pixel at a time, would it be best to: // by output here, i mean do a glVertex3f just loop through set the color every single time output each point... or set the color loop through while searching for that color output points that have the matching color repeat for every color Thanks
Advertisement
Both of those methods are going to blow. Hard. It doesn''t sound like you want to be using OpenGL for whatever you''re doing.

-- John
Thank you for that encourging advice...but for now I am making a simple 2d tank game, and am more concerned with making the code for the game then the code for the graphics. After I finish this, I will procede to learn how to work with more 3d programs and let OpenGl do the work for me.

Could someone please tell me which of those two methods will be quicker. Thank you.
oops, double posted somehow

[edited by - lessthanjoe on May 4, 2002 6:50:17 PM]
Actually he''s right. I assume you''re doing some sort of Worms/TankWar/Take turns shooting at angle game. I would suggest two things. 1) Switch to DirectX 7 and use DirectDraw (which can be made more efficient for lots of single pixel sets) or 2) Using OpenGL, create a bunch of big (256x256) textures that can cover the screen (tiled across the screen). Modify these textures rather than trying to mess with the screen.

In response to your orignal query, the first method would seem best (though you should test both with a profiler to be sure). The second method is likely to cause alot of cache misses and more importantly the overhead of doing 4 IFs for every pixel would be huge.
I just kind of realized something. Like right now, I am doing a deformation that creates a hole in the terrain, and I wrote the code that changes the 2d array. Would it work if I added in the code that changed the pixel colors in with this then just do a SwapBuffers when I want to output something?
(paraphrase, basically OpenGl will store the terrain for me and I just change the pixels I want changed.)

Now that this concept is in my head, it looks like it would be fairly easy to code. I'm going to take a break from coding for a while, hopefully someone will tell me if this thing I'm doing is possible.

If this new method would work, do you think the first method I listed would be best to use when I first draw the terrain at the begining (The lag would be acceptable and considered as load time)

[edited by - lessthanjoe on May 4, 2002 7:23:07 PM]
Maybe you could treat the terrain as a large polygon / set of polygons. It''d make drawing a lot faster, and reduce memory usage, but collision detection and terrain deformation would be harder. Overall, I think it would be faster...
Yet another request here...how would you guys handle the terrain? How would I go about setting a backround image?
Use tiles. Say if your tiles would be 20x20, you''d need a 40x30 array (dont use pixel like that!)

this may help a bit
http://www.gamedev.net/reference/programming/features/terrain_trans/
---Quite soon...ICQ: 163187735
Rather then just repeating to use tiles, could someone please explain to me how I am supposed to use tiles. Should I make 20 40x30 2d arrays? Then what? How would outputting these to the screen be any different.

Has anyone here made a worms game? How did you impliment the terrain?

Thanks for tolerating the unlearned.

This topic is closed to new replies.

Advertisement