LordSputnik
Posts: 17
Joined: Mon Jul 16, 2012 8:39 pm

SDL and OpenGL ES

Mon Jul 16, 2012 9:07 pm

Hey everyone,

I'm trying to create a window where I can render graphics using OpenGL ES (through EGL) and pick up input events. However, I've heard that using X windows is slower than rendering directly to the frame buffer, so I'm trying to program with this in mind.

So far, I've pretty much copied the code from the github link at the bottom of this blog post:

http://benosteen.wordpress.com/2012/04/ ... x-windows/

I found that in a forum post somewhere on here. After a bit of Makefile writing, I got it to compile, and it runs nicely.

Now, I'm trying to get some mouse/keyboard input working, so I decided to use SDL. I'm trying to figure out how to integrate SDL and OpenGL ES. My first thought has been to create a full screen X window using SDL, and then use EGL to render to the framebuffer over the top of it, so I can get keyboard and mouse events through the X window, but ignore it when rendering.

It seems a little hacky, although I think it'll work. But I'm a little new to the frame buffer and OpenGL ES, so is there a better way of getting the keyboard/mouse input from SDL when rendering directly to the frame buffer?

EDIT: I'm using C and the gcc compiler, thought that I'd better add that! :P

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5502
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: SDL and OpenGL ES

Mon Jul 16, 2012 9:33 pm

Quake 3 (https://github.com/raspberrypi/quake3) does exactly what you descibe (SDL for input events with OpenGL ES window over the top) and runs well.

LordSputnik
Posts: 17
Joined: Mon Jul 16, 2012 8:39 pm

Re: SDL and OpenGL ES

Mon Jul 16, 2012 9:51 pm

Thanks for your reply, that's good to hear :)

jmacey
Posts: 135
Joined: Thu May 31, 2012 1:05 pm

Re: SDL and OpenGL ES

Wed Jul 18, 2012 10:13 am

Yes that's exactly what I'm doing as well, use SDL for keyboard and mouse and use my own EGLWindow class for the GL context. I've written a blog post about it here http://jonmacey.blogspot.co.uk/2012/06/ ... onfig.html you can also see some demos that use my NGL library here

http://code.google.com/p/pingl/

With a couple of videos of it all working here

http://nccastaff.bournemouth.ac.uk/jmac ... index.html

Jon

LordSputnik
Posts: 17
Joined: Mon Jul 16, 2012 8:39 pm

Re: SDL and OpenGL ES

Wed Jul 18, 2012 10:18 am

Yeah I saw your blog before, that's where I got the idea. I have it bookmarked :)

mlepage
Posts: 95
Joined: Tue Jun 12, 2012 1:58 am

Re: SDL and OpenGL ES

Wed Jul 18, 2012 11:42 pm

I'm trying to do the same thing: use SDL for input etc., but GLES2 for video. Is there a simple boiled-down HOWTO for how to do this, so I don't have to troll through a lot of links to piece it together? I have some other porting to focus on, I'd like to get this boilerplate out of the way as painlessly as possible. Thanks!

jmacey
Posts: 135
Joined: Thu May 31, 2012 1:05 pm

Re: SDL and OpenGL ES

Fri Jul 20, 2012 7:41 am

Here is the minimal code I use to create an SDL context for mouse and keyboard

Code: Select all

#include <iostream>
#include <cstdlib>
#include "bcm_host.h"
#include <SDL/SDL.h>


void exitfunc()
{
delete win;
SDL_Quit();
bcm_host_deinit();
}

int main()
{
  bcm_host_init();
	atexit(exitfunc);

	if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
	{
      std::cerr<<"Unable to init SDL: "<<SDL_GetError()<<"\n";
      exit(EXIT_FAILURE);
  }


SDL_Surface* myVideoSurface = SDL_SetVideoMode(0,0, 32,  SDL_SWSURFACE);
// Print out some information about the video surface
  if (myVideoSurface != NULL) 
  {
       std::cout << "The current video surface bits per pixel is " << (int)myVideoSurface->format->BitsPerPixel << std::endl;
  }
  
	// now do the EGL Window stuff and use SDL to process events as normal  
}
Once you have done the SDL init stuff you can then create an EGL context as normal and use OpenGL code etc. I use my own class for this (seem my other blog posts).

What I will do when I get a chance is to modify the SDL source tree (or create some sort of patch to it) so It can be used normally on the pi. It may be that this will work out of the box anyway http://pandorawiki.org/Combining_OpenGL ... he_Pandora but not tested as yet.

cmarty
Posts: 40
Joined: Thu Jul 19, 2012 7:23 am
Location: Czech Republic

Re: SDL and OpenGL ES

Wed Feb 06, 2013 8:37 am

Thanks jmacey for your code. It helps me a lot.
But in my application I need to set video mode to 1x1 resolution. When I use 0x0 a get whole black screen and the program stuck in SDL_SetVideoMode. I'm using the standard debian sdl1.2 package.

Return to “OpenGLES”