Archived

This topic is now archived and is closed to further replies.

ma0

OpenGL A good OpenGL 2d Tutorial?

Recommended Posts

ma0    122
Where can I find a good 2d tutorial?? I''m playing with QUADS and textures, but I want to know if there is other good alternatives (glRect?How can I texture it?) Thanks ma0

Share this post


Link to post
Share on other sites
ma0    122
Thanks for the answer (U are the only who answered me)
I am now trying different solutions for a simple Tile *engine* (engine is a big word tough

- GL_QUADS + glTextCoords ( I''ve tried with gl_Rect but I dont know how to map a texture on it :-)

- gl_Drawpixels + glRasterPos

I want to test what''s the fastest solution..
Now I have some problem with the glRasterPos (I am not able to tile the entire screen..then I have to understand how to simulate the glTranslate..

I have a little question too.. how can I *create* a surface bigger than the screen, so if i translate, i always see something? I''ve tried changing the glViewport but then It changes the tile dimensions too..I don''t understand perfectly how they works.

Another BIG problem. how coordinates works? I''ve read many tutorials,but I don''t understand how to apply them. If I create a viewport of 640x480 and my cube is a 0.5,0.5,.. it will be half of the screen..how people can translate the diffent way of thinking coordinates?

Share this post


Link to post
Share on other sites
Drizzt DoUrden    100
2D in OpenGL isn''t the greatest way to go. I would suggest you check out Simple DirectMedia Layer (SDL). There is a great tutorial on how to get it setup here on GameDev, its a featured article on the main page, and then go to cone3d.gamedev.net and take the SDL Graphics Tutorials.

This is a great alternative. SDL is very simple to use, and very easy to learn.

If you have any trouble with it (if you decide to use it), post your problem in the Cone3D forum, and you will be answered a.s.a.p.

SDL works with OpenGL, and there is alot of stuff you can do with it very simply, compared to how OpenGL does it.

Good luck.

Share this post


Link to post
Share on other sites
Terran Marine    122
I use glOrtho with textured quads for my OpenGL-based tile engine :
http://rpg-forge.i8.com/screen_1.jpg


As you can see it looks the biz, and thanks to 3d acceleration you can do neat zooming in\out and loads of other effects.

Everyone has a 3d card nowadays.

Edited by - Terran Marine on December 14, 2001 2:34:09 AM

Edited by - Terran Marine on December 14, 2001 2:34:40 AM

Share this post


Link to post
Share on other sites
ma0    122
about SDL... I am using OpenGL because SDL unfortunately works fast only if I use it as root (on Linux) This is NO good.
I don''t like to use system ram instead of video ram and no hardware acceleration only because I am not root..
This is why I am trying to create some little example in OpenGL . Then I will translate it in SDL to show the difference..

ma0

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
quote:
Original post by Terran Marine
I use glOrtho with textured quads for my OpenGL-based tile engine :
http://rpg-forge.i8.com/screen_1.jpg



Can I see some of your code? I have some problem to understan how glOrtho2D (i use the 2D form) and glView works together..I am using 64x64 tiles and I want to create a *terrain* bigger than the screen..but If i set glView bigger , my tiles becomes bigger..
--> How are related the -1.0..1.0 coords? they are glOrtho xmin->xmax or glView?
(example in 640x480 screen: glTranslatef(0.2,0.0,0.0) are 640/2+(1/640*0.2) ??)

Share this post


Link to post
Share on other sites
gregs    364
Don''t use glDrawPixels/glRasterPos - it chokes the graphics pipeline and can cause your FPS to drop about 4/5ths. Use GL_QUADs!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Generally, you will always want to set glViewport to the size of the window - that way the entire window will be used. If you enlarge the window but not the viewport, you''ll only be using a small portion of the new window.

A call to glOrtho2D is the same as a call to glOrtho with -1.0, 1.0 as the near and far clip planes. Remember, just because you are thinking in 2D, you are still drawing in 3D and the z axis does exist.

Now, you can thank of glOrtho as a way to map screen coordinates to pixel coordinates. If you reset the recatangle to start at (0,0) and use width and height of the window everytime you resize the screen, then your coordinates will range from (0,0) to (winWidth, winHeight).

So, to keep the images from stretching win the window is resized, call both glOrtho AND glViewport with the new window dimensions in your resize function. Otherwise, if you make glViewport bigger, but don''t update glOrtho, then you will have a larger viewport which maps to the original screen coordinates. That is, if you set the width/height of the viewport to (800,600), but glOrtho''s width/height are set to (640,480), then OpenGL will map the coordinates so that position (640,480) is actually (800/600) on the screen. Therefore, all of your images will be larger than you expect.

This is sometimes desirable. For example, if you have a game where you only want to display a row of 10 tiles at a time, just never call glOrtho after the first call, update glViewport each time the screen is resized, and you will always display the same number of tiles. They will be stretched to fit the window. If you have a scrolling game, you might instead update the viewport AND the projection each time the window is resized in order to show more of the map.

Share this post


Link to post
Share on other sites
Brannon    122
It sounds like you want to be able to render a world that is say 1000x1000, but have a viewport that is 100x100, and scrolls over the world. I am assuming you want to do this because it should be faster than rendering each screen/view from scratch.

This is really just a blitting trick, and not handled by something like OpenGL. If you want to do that, then render to an offscreen surface, and then blit portions of that to the screen. This is of course assuming that you *can* render to an offscreen surface (not a backbuffer) and assuming that you dont lose the hardware acceleration if you do so.

As for being faster, sure it''s probably faster, but when modern day video cards can render millions of texture mapped triangles/second, I don''t think you''ll be stressing that limit with your average 2d game.


-Brannon

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
quote:
Original post by Brannon
If you want to do that, then render to an offscreen surface, and then blit portions of that to the screen. This is of course assuming that you *can* render to an offscreen surface (not a backbuffer) and assuming that you dont lose the hardware acceleration if you do so.


Ok. How can I do this? It''s impossible in OpenGL to render an offscreen surface.. I have to use SDL to do it..or not?

Share this post


Link to post
Share on other sites
Null and Void    1088
quote:
Original post by Brannon
If you want to do that, then render to an offscreen surface, and then blit portions of that to the screen. This is of course assuming that you *can* render to an offscreen surface (not a backbuffer) and assuming that you dont lose the hardware acceleration if you do so.

That''s a horrible method. Even for a 2D API that''s not that great of a method. Simply use glTranslatef and (if not only) occlusion techiques to decide what and where you should render tiles. How are tiles hard? I don''t get it. They aren''t any harder in OpenGL than any other API; they''re barely any different!

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
Brannon    122
How is that a horrible method? Back in the day (386/486/etc), re-drawing an entire screen every frame killed performance. You could get magnitudes of order better perf if you only redrew what changed (for 2D games).

I''m not suggesting you do that. OpenGL is designed (as far as I can tell) to redraw the entire screen each frame. So, use it as it was designed.

Sorry if you thought I was suggesting rendering to an offscreen surface. Dont do it. Redraw the screen.

On windows, you can render to a GDI surface (offscreen), and then blit it where ever you want. But you probably wont get hardware acceleration, since you are then using the generic MS OpenGL APIs, and not the video card driver''s APIs.

There is a way to render to an offscreen surface .. because you can render to a texture .. but I think it involves some nasty tricks.. something along the lines of rendering to the backbuffer, and then reading the pixels from the back buffer into your own buffer, that you then specify as a texture.


-Brannon

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
You can just redraw a portion of the screen in OpenGL. Look into scissor testing. Should be in one of the nehe tuts.

Sypes

Share this post


Link to post
Share on other sites
Null and Void    1088
I wasn''t complaining about only redrawing a portion of the screen. I was refering to using an offscreen buffer and selecting a portion of it to draw each time. "Dirty rectangles" are still a viable technique in OpenGL, but offscreen buffers are more trouble than they''re worth.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites

  • Similar Content

    • By povilaslt2
      Hello. I'm Programmer who is in search of 2D game project who preferably uses OpenGL and C++. You can see my projects in GitHub. Project genre doesn't matter (except MMO's :D).
    • By ZeldaFan555
      Hello, My name is Matt. I am a programmer. I mostly use Java, but can use C++ and various other languages. I'm looking for someone to partner up with for random projects, preferably using OpenGL, though I'd be open to just about anything. If you're interested you can contact me on Skype or on here, thank you!
      Skype: Mangodoor408
    • By tyhender
      Hello, my name is Mark. I'm hobby programmer. 
      So recently,I thought that it's good idea to find people to create a full 3D engine. I'm looking for people experienced in scripting 3D shaders and implementing physics into engine(game)(we are going to use the React physics engine). 
      And,ye,no money =D I'm just looking for hobbyists that will be proud of their work. If engine(or game) will have financial succes,well,then maybe =D
      Sorry for late replies.
      I mostly give more information when people PM me,but this post is REALLY short,even for me =D
      So here's few more points:
      Engine will use openGL and SDL for graphics. It will use React3D physics library for physics simulation. Engine(most probably,atleast for the first part) won't have graphical fron-end,it will be a framework . I think final engine should be enough to set up an FPS in a couple of minutes. A bit about my self:
      I've been programming for 7 years total. I learned very slowly it as "secondary interesting thing" for like 3 years, but then began to script more seriously.  My primary language is C++,which we are going to use for the engine. Yes,I did 3D graphics with physics simulation before. No, my portfolio isn't very impressive. I'm working on that No,I wasn't employed officially. If anybody need to know more PM me. 
       
    • By Zaphyk
      I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
  • Popular Now