Hello, I’m writing a 2D rpg using java2D right now but considering switching over to jogl. I should actualy say switching back to jogl. I had started with java2D switched to jogl using drawPixels() for all of my rendering and then switched to texturing quads and drawing those, and finaly switched back to java2D because i didn’t have time (at the time ;D).
I should also state my reasons for using jogl instead: accelerated tranlucency, affine transforms, creating various special effects that will require it, and hopefully increased drawing speed.
What I want to know is whether using drawPixels() or texturing quads is the correct way to go about creating my game. I also am wondering how I would render my maps if I choose option 2: texturing quads. I don’t know if I should have each tile be a separate quad and have my tileset be an array of textures that I will apply to these quads, or if th whole map should be a single quad, or if I should just use drawPixels()…
Please help me to better understand all aspects of the situation I am looking at and hopefully come up with a solution.
Quads are generally always much faster and will work correctly in all situations. Drawpixels is riddled with pitfalls; don’t use it.
Divide your map into a grid and each grid will be rendered by one quad in an orthographic projection.
Cas
Ok, that tips me off on one big part of what I was doing wrong, thank ya much. I tried creating a grid of quads but I was not using orthographic projection, I’m a complete newb and I can’t remember what it was called but I was using the type you would use to render 3D objects. And one of the problems I had with this was getting the map to fill the exact screen dimensions… Well, sounds good and I can’t wait to give it another try. Anything else absolutely neccesary thatI should know about making a 2D game in openGL? (tip from the master?)
Thanks that actualy helped quite a bit bookmarks thread. I really which there was a search feature on this forum…
One other question: for drawing my maps I have a single image (480x256) that contains all the tiles, and when I was using java2D I broke these into seperate images when a new chipset was first loaded I stored them in array. Problem is that it seems it would be better to just have one texture and change its coords to draw the tiles I need and I don’t think textures can be those dimensions. Is this true? if it is how do I work around it? also, am i looking at this the wrong way or in my rendering method am I going to need some giant loop to apply the texture to each tile getting displayed?
generaly 40x30 tiles on screen at all times.
[quote]Problem is that it seems it would be better to just have one texture and change its coords to draw the tiles I need and I don’t think textures can be those dimensions. Is this true?
[/quote]
Yes.
You put all your sprites/tiles on one or more texture PNGs, which are sized 2^n values (like 512x512, so they please the current 3d graphic cards).
Then you (let) calculate the UV pairs for each tile on the texture.
In order to draw one tile, you say to OpenGL: bind texture-n and draw a vertex quad sized the tile’s pixel dimension, with the appropriate UV pairs.
Since many tiles fit on one texture, you save the switching of texture context with OpenGL, which is (usually) expensive.
It’s extremely expensive, because you then have to render each quad individually instead of blitting them all in one call to glDrawElements! And that’s about as slow as you can get in OpenGL. Performance likely to be slower than Java2D…
Cas
well I must say, thats a shame. The reason is becaues the images I am using for my map have those specific dimensions because tons of people make them for rm2k (an RPG making program) and certain tiles are in certain places (animated water tiles here, another group here…) and alot of my code depends on them being in those positions.
Fortunately its summer and the amount of time I have on my hands is… alot ;D. So when I get to the texture drawing part I enable the texture context, loop through and texture all my quads, disable it and continue with whatever else I’m doing and I should be good to go eh?
Pretty much. There’s no problem with wasting a bit of space at the edges of the texture if you don’t want to fill them with tile graphics.
Cas
[quote]It’s extremely expensive, because you then have to render each quad individually instead of blitting them all in one call to glDrawElements! And that’s about as slow as you can get in OpenGL. Performance likely to be slower than Java2D…
[/quote]
That sounds valid for tile based maps indeed. Thanks for the hint.
What I wrote is the case with my hobby project where I’ve got animated sprites being on one (++) texture page and I’ve to change texture context for most of the sprites anyway.
thanks for all the help guys. I’ve just been finishing up some work on my terrain editor, but today I will start switchin over to jogl and we’ll see how things go