• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Acharis

OpenGL + SDL

12 posts in this topic

Is there a way to use both OpenGL and SDL (not just for keyboard input but for 2D graphics)? I want to render a 3D scene in the background and blit on top of it various 2D interface elements via SDL.

I'm thinking along the lines of "render OpenGL to SDL surface instead of screen and then blit it" solution. Performance is of extremely low importance.
0

Share this post


Link to post
Share on other sites
OpenGL supports both 2D and 3D graphics, it uses polygons to render graphics which means that you can render both 2D and 3D graphics in the same application (did you notice the Captain Obvious in there? :P ) You would just have to render your 2D interface in relation to the screen and the 3D world in relation to a camera that exist within that 3D space.
I don't know how familiar you are with OpenGL, but here's a useful website that gets you comfortable with the library: http://nehe.gamedev.net/
Hope this helps :)
0

Share this post


Link to post
Share on other sites
Yes, I know I can use OpenGL for drawing 2D primitives. But I hoped for SDL blit solution. This would let me share my already existing 2D drawing code, true type fonts code, etc mixed with 3D.

Is it possible?
0

Share this post


Link to post
Share on other sites
Oh, sorry.
I don't think you can use SDLs blitting when you use OpenGL since you can (by the looks of it) only enable one of them at a time, you can write "SDL_SetVideoMode( x, y, 32, SDL_OPENGL )" to enable OpenGLs rendering and "SDL_SetVideoMode( x, y, 32, SDL_SWSURFACE )" to enable SDLs rendering, but never enable both at the same time with that method.
Maybe there's a way to use both OpenGLs rendering and SDLs rendering in the same application, but my answer to you would be that you probably can't.

Something you can do is to load an SDL_Surface and render it on a polygon using OpenGL, but that, I think, is about as "close" as you can get to SDLs way of rendering while using OpenGL. Whatever the case, I think that it's easier to just switch over to OpenGLs rendering, OpenGL is much more useful and faster compared to SDL.
0

Share this post


Link to post
Share on other sites
Well, you can render fonts with SDL_ttf to surfaces, and then render the pixel data as a texture in OpenGL. If you are adventurous, you can do roughly the same thing. You create a blank surface, blit your scene on it, and then extract the pixels from the surface to map them on a texture. You will have to repeat the process every time you change something in SDL.
0

Share this post


Link to post
Share on other sites
Sorry to just randomly jump in here but I was looking through gamedev and just decided to create an account because I saw this question. I am new to SDL and openGL but I thought maybe I could help with a bit of code from one of my projects. This may be helpful or may not, but it does seem to answer the question of how to get SDL_SWSURFACE and SDL_OPENGL on at the same time.

[source lang="cpp"] int videoFlags;
const SDL_VideoInfo* videoInfo;

SDL_Init( SDL_INIT_EVERYTHING );

videoInfo = SDL_GetVideoInfo();
if(!videoInfo)
return false;

videoFlags = SDL_OPENGL;
videoFlags |= SDL_GL_DOUBLEBUFFER;
videoFlags |= SDL_HWPALETTE;
videoFlags |= SDL_RESIZABLE;

if( videoInfo->hw_available )
videoFlags |= SDL_HWSURFACE;
else
videoFlags |= SDL_SWSURFACE;

if( videoInfo->blit_hw )
videoFlags |= SDL_HWACCEL;

SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

screen = SDL_SetVideoMode( screenW,screenH,screenBPP,videoFlags );[/source]
1

Share this post


Link to post
Share on other sites
To clarify, I need pixel perfect accuracy, so converting surface to a texture and then display it as 2 triangles is not an option. If my memory is correct, the only way to do pixel perfect render in OpenGL is the use of glDrawPixels (which is unfortunatelly not hardware accelerated, IIRC).

Also, it needs to run on OpenGL 1.3 max (compatibility with older intel video onboard cards, especially in a bit older laptops).

[quote name='dilyan_rusev' timestamp='1343582397' post='4964279']
Well, you can render fonts with SDL_ttf to surfaces, and then render the pixel data as a texture in OpenGL. If you are adventurous, you can do roughly the same thing. You create a blank surface, blit your scene on it, and then extract the pixels from the surface to map them on a texture. You will have to repeat the process every time you change something in SDL.
[/quote]Hmm, if I'm reading this right, you are saying I can first render the 3D scene via OpenGL, then read it via SDL and create SDL_surface of it and the clear the screen and redraw everything I want using SDL blits?

But it would require changing some SDL video setting between these two (from OpenGL to SDL video)? Edited by Acharis
0

Share this post


Link to post
Share on other sites
OK, what you do is that you create a surface in memory with [url="http://sdl.beuc.net/sdl.wiki/SDL_CreateRGBSurface"]SDL_CreateRGBSurface[/url] . SDL blitting functions should not care that you are blitting on a memory surface instead of blitting on the screen surface. You just make sure that the memory surface is in the same format as your images (you probably want to convert your sprites with [url="http://sdl.beuc.net/sdl.wiki/SDL_ConvertSurface"]SDL_ConvertSurface[/url] when you load to to be of the same format as the one you create with SDL_CreateRGBSurface).

Finally, when you are done drawing to the memory surface, you just [url="http://content.gpwiki.org/index.php/SDL:Tutorials:Using_SDL_with_OpenGL"]generate a texture out of it[/url], and draw it on the whole screen, as if it were a texture you loaded from a file.

So far as fonts go, I do love the simplicity of SDL_ttf. It renders to a SDL_Surface, which you can simply treat as yet another texture, if you were using the OpenGL API directly.
0

Share this post


Link to post
Share on other sites
It actually isn't that hard to create an SDL-like texture render API in OpenGL. You can render your 3D scene, clear/disable the depth buffer, and then render your ortho 2D graphics on top if it.

If you're too lazy to do it yourself, I basically already did it for you in my [url="http://lazyfoo.net/tutorials/OpenGL/index.php"]OpenGL Tutorial[/url], both in modern OpenGL and OpenGL 2.1.
0

Share this post


Link to post
Share on other sites
Clarification what I need:
- I need PIXEL PERFECT solution, so absolutelly no "textures" involved at all. I need a control of a position of a single pixel (for 2D render only).
- Max OpenGL 1.3 (I need it to run on old laptops with IBM gfx card onboard, these sux a lot when it comes to OpenGL support, even if not that old), also it needs to run under outdated drivers (yes, I'm making a very low specs retro game, which is to be played on inferior hardware that is not capable of even running any modern game).
- Ideally (but I can live without it) would be if I could directly use SDL code to rended 2D stuff (interface on top of a 3D scene, no mixing these two together, a separate 3D scene at the bottom and separate 2D on top of it), that would save me a lot of rewriting and keeping 2 versions of the render engine (plus, SDL is much faster when it comes to render compared to glDrawPixels since it can use VRAM).

Yes, I know, these requirements are odd and no one makes games this way nowadays :)



I think, something like this would be the most convenient:
- render 3D scene in OpenGL
- instead of swapping the scene from secondary to primary buffer (screen), copy/convert the scene to SDL_surface
- disable OpenGL, enable SDL video and clear everything on the screen/buffer
- blit via SDL the 3D scene (stored as SDL_surface) and then do the normal SDL blits for the rest
- swap the buffers (SDL) so the primary screen/surface is updated

Is this possible?
0

Share this post


Link to post
Share on other sites
JTippets answered a similar question [url=http://www.gamedev.net/topic/629496-dynamic-objects-in-isometric-map-drawing-algorythms/]here[/url]. Just because you need something 'pixel perfect' does not mean you cannot involve textures.
1

Share this post


Link to post
Share on other sites
If you want pixel perfect rendering, just remember that when polygons rasterize they rasterize to the center of the pixel. If you wanted to draw a line from 0 to 5 inclusive, you draw from 0.5 to 5.5.

Try setting up your ortho projection matrix and then translate it <0.5, 0.5, 0.0> to center your pixels.
1

Share this post


Link to post
Share on other sites
[quote name='BitMaster' timestamp='1344862716' post='4969042']
JTippets answered a similar question [url="http://www.gamedev.net/topic/629496-dynamic-objects-in-isometric-map-drawing-algorythms/"]here[/url]. Just because you need something 'pixel perfect' does not mean you cannot involve textures.
[/quote]Hmmm, very interesting. I thought 3D cards do not provide such capability and the exact accuracy depends on the card used. If textures can be used then indeed it's very nice performance wise.

OK, so now it's mostly convenience question. Is there a way to use BOTH OpenGL (for 3D) and SDL_Blit (for primitive 2D overlay), so I don't need to rewrite my already existing SDL code?

Also, I would like to understand how exactly opening screen/context/canvas works? A screen is a screen, it should be a buffer on GFX card VRAM which should be usable the same way by all APIs. What exactly happens when I define the screen as "SDL_OPENGL" and why can't I use normal SDL Blits then?
0

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  
Followers 0