Sign in to follow this  
blanky

OpenGL 2D Engine

Recommended Posts

blanky    364
Hey guys, I want to make my 2D engine with OpenGL. However, I want to get the basics out of the way: would I basically texture quads or figures? Or is there another way. Thanks guys, heh, if you could elaborate on the process a bit more (dont have to be entirely specific) that'd be nice, I think that I obviously wont use the Z buffer (or I can if I want the effect that the player is a bit away fromt he background.) Thanks guys! EDIT: Er sorry, didn't read the FAQ, found some info, thanks guys. But I'd still like to know your opinions and tricks if you'd like, just to not waste this topic (since there's no delete feature)

Share this post


Link to post
Share on other sites
Goober King    553
For a more true to form 2D engine probably stick with the ortho mode and for get about the z-buffer. If you use the hardware to manage the distance then you will start to run into some other issues. For 2D you generaly want to have full control over all your pixels and the hardware will be scaling the images acording to the depth. Which can change the way things look quite a bit depending on a number of things. It can work but it depends on what your doing exactly and creating smart art that takes all that suff into acount.

I would say in most cases its best just to creat and manage a set of planes. Draw them from back to front and move them acording to how "far" away they are. Far planes scroll less, closer ones more.

It can depend so I what all do you want it for?

Share this post


Link to post
Share on other sites
blanky    364
I'd like a 2D side scroller, but I just wanted to know the basics of making one. I know you use orthographic projection, but would you just texture quads? Etc., what tricks people use in 2D engines and what hints you know that could help me out, nothing specific, just to point me in the right direction, thanks for the help.

Share this post


Link to post
Share on other sites
Goober King    553
Quote:
Original post by blankdev
I'd like a 2D side scroller, but I just wanted to know the basics of making one. I know you use orthographic projection, but would you just texture quads? Etc., what tricks people use in 2D engines and what hints you know that could help me out, nothing specific, just to point me in the right direction, thanks for the help.


Yup. Just texture a quad. From there most any 2D technique should apply. Creating a tile engine is place to start. There's loads of info on programing tile engines and they are fairly simple to create. When you build the engine start by creating a map editor for it. That way you can make a map, save it, and load it into whatever it is you want to use it for later.

Share this post


Link to post
Share on other sites
blanky    364
Ah, okay thanks for your help. Although, I'm very new to tool making, do you know of any tutorials on the subject? (perferably map editor making), it can be a very simple one, of course I can figure it out, but to see how everyone else does it, thanks.

Share this post


Link to post
Share on other sites
jeroenb    282
You can create your scrolling tile engine as complex as your want. I use vertex buffer objects, vertex- and fragment shaders, etc to render my 2D engine.

First you should decide how to setup your engine. It will ofcourse support multiple layers. Then define how to store the layers in memory. Often this is done as an 2D array which with indices of the tile to use. Those tiles will all be stored in one big bitmap. Rendering is then as easy as looping through these indices and display the tiles on the screen.

When you have this running you can start optimizing things if necessary.

Share this post


Link to post
Share on other sites
Goober King    553
You can go almost as nuts as you wish. A lot of crazyness isn't need. At least not your first time around. The isometric land forum deals with top down tile engines as well as isometric ones and is the best place to get people help. As for articles and such just run a search on Gamedev and google. There is loads of info on the subject and much of it is easy to understand. Find an aproach that you like and try it out. Just replace any references to sprite drawing with a textured quads and your in the biz.

Below is a screen shot from my last run at a tile engine. A lot of the stuff is personal ideas, much of which never was done or didn't really work. Some things did work fab so I will suggest them for your own editor.


The bottom row is a small list of the selectable tiles. The mouse wheel is used to flip through the full range. Turns out that is a damn cool and handy way of picking your tiles. The large box on the lower left is a preview of the selected tiles. I had it so you could select 2 or 4 tile sets to draw with as well as one. The preview is always in the box. Just one thing you can do. A Colored quad would work too. The purple diamonds spin around and define a "range" of tiles to change. Ignore the event stuff. It had to do with the interactive qualities of the tiles. Something that you should think about tough. Additives were just going to be extra graphics layerd on top of the tiles. Not a tile engine thing.

The main things are making sure you can load and save your map and figuring out how you want to define and use the memory used for for the map. If memory serves I think I just made a character pointer. Then fetched the amount of height * width after I knew what that was. That gives you 256 tile types to play with. It would be cool if you could use a 2D array and have map[hight][width] but you cant. Not without knowing the exact size of the map. So then you dig up your value by Map[xvalue + (yvalue*mapwidth)].

you can also use an array of structures.
{
1. tile number here
2. linked list pointer to next tile.(for layered tiles)
}

Go nuts

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By pseudomarvin
      I assumed that if a shader is computationally expensive then the execution is just slower. But running the following GLSL FS instead just crashes
      void main() { float x = 0; float y = 0; int sum = 0; for (float x = 0; x < 10; x += 0.00005) { for (float y = 0; y < 10; y += 0.00005) { sum++; } } fragColor = vec4(1, 1, 1 , 1.0); } with unhandled exception in nvoglv32.dll. Are there any hard limits on the number of steps/time that a shader can take before it is shut down? I was thinking about implementing some time intensive computation in shaders where it would take on the order of seconds to compute a frame, is that possible? Thanks.
    • By Arulbabu Donbosco
      There are studios selling applications which is just copying any 3Dgraphic content and regenerating into another new window. especially for CAVE Virtual reality experience. so that the user opens REvite or CAD or any other 3D applications and opens a model. then when the user selects the rendered window the VR application copies the 3D model information from the OpenGL window. 
      I got the clue that the VR application replaces the windows opengl32.dll file. how this is possible ... how can we copy the 3d content from the current OpenGL window.
      anyone, please help me .. how to go further... to create an application like VR CAVE. 
       
      Thanks
    • By cebugdev
      hi all,

      i am trying to build an OpenGL 2D GUI system, (yeah yeah, i know i should not be re inventing the wheel, but this is for educational and some other purpose only),
      i have built GUI system before using 2D systems such as that of HTML/JS canvas, but in 2D system, i can directly match a mouse coordinates to the actual graphic coordinates with additional computation for screen size/ratio/scale ofcourse.
      now i want to port it to OpenGL, i know that to render a 2D object in OpenGL we specify coordiantes in Clip space or use the orthographic projection, now heres what i need help about.
      1. what is the right way of rendering the GUI? is it thru drawing in clip space or switching to ortho projection?
      2. from screen coordinates (top left is 0,0 nd bottom right is width height), how can i map the mouse coordinates to OpenGL 2D so that mouse events such as button click works? In consideration ofcourse to the current screen/size dimension.
      3. when let say if the screen size/dimension is different, how to handle this? in my previous javascript 2D engine using canvas, i just have my working coordinates and then just perform the bitblk or copying my working canvas to screen canvas and scale the mouse coordinates from there, in OpenGL how to work on a multiple screen sizes (more like an OpenGL ES question).
      lastly, if you guys know any books, resources, links or tutorials that handle or discuss this, i found one with marekknows opengl game engine website but its not free,
      Just let me know. Did not have any luck finding resource in google for writing our own OpenGL GUI framework.
      IF there are no any available online, just let me know, what things do i need to look into for OpenGL and i will study them one by one to make it work.
      thank you, and looking forward to positive replies.
    • By fllwr0491
      I have a few beginner questions about tesselation that I really have no clue.
      The opengl wiki doesn't seem to talk anything about the details.
       
      What is the relationship between TCS layout out and TES layout in?
      How does the tesselator know how control points are organized?
          e.g. If TES input requests triangles, but TCS can output N vertices.
             What happens in this case?
      In this article,
      http://www.informit.com/articles/article.aspx?p=2120983
      the isoline example TCS out=4, but TES in=isoline.
      And gl_TessCoord is only a single one.
      So which ones are the control points?
      How are tesselator building primitives?
    • By Orella
      I've been developing a 2D Engine using SFML + ImGui.
      Here you can see an image
      The editor is rendered using ImGui and the scene window is a sf::RenderTexture where I draw the GameObjects and then is converted to ImGui::Image to render it in the editor.
      Now I need to create a 3D Engine during this year in my Bachelor Degree but using SDL2 + ImGui and I want to recreate what I did with the 2D Engine. 
      I've managed to render the editor like I did in the 2D Engine using this example that comes with ImGui. 
      3D Editor preview
      But I don't know how to create an equivalent of sf::RenderTexture in SDL2, so I can draw the 3D scene there and convert it to ImGui::Image to show it in the editor.
      If you can provide code will be better. And if you want me to provide any specific code tell me.
      Thanks!
  • Popular Now