#1 Members - Reputation: 889
Posted 27 July 2012 - 02:49 PM
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.
#2 Members - Reputation: 149
Posted 28 July 2012 - 11:02 AM
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
#4 Members - Reputation: 149
Posted 28 July 2012 - 02:37 PM
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.
#5 Members - Reputation: 542
Posted 29 July 2012 - 11:19 AM
#6 Members - Reputation: 106
Posted 29 July 2012 - 11:50 PM
[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]
#7 Members - Reputation: 889
Posted 11 August 2012 - 10:51 AM
Also, it needs to run on OpenGL 1.3 max (compatibility with older intel video onboard cards, especially in a bit older laptops).
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?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.
But it would require changing some SDL video setting between these two (from OpenGL to SDL video)?
Edited by Acharis, 11 August 2012 - 10:53 AM.
#8 Members - Reputation: 542
Posted 11 August 2012 - 01:48 PM
Finally, when you are done drawing to the memory surface, you just generate a texture out of it, 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.
#9 Members - Reputation: 1031
Posted 11 August 2012 - 04:08 PM
If you're too lazy to do it yourself, I basically already did it for you in my OpenGL Tutorial, both in modern OpenGL and OpenGL 2.1.
Transition from OpenGL 2 to modern OpenGL using my OpenGL Tutorial.
#10 Members - Reputation: 889
Posted 13 August 2012 - 05:00 AM
- 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?
#12 Members - Reputation: 1031
Posted 13 August 2012 - 07:01 AM
Try setting up your ortho projection matrix and then translate it <0.5, 0.5, 0.0> to center your pixels.
Transition from OpenGL 2 to modern OpenGL using my OpenGL Tutorial.
#13 Members - Reputation: 889
Posted 20 August 2012 - 02:04 AM
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.JTippets answered a similar question here. Just because you need something 'pixel perfect' does not mean you cannot involve textures.
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?






