Hi, I've been working to build a SDL+OpenGL game engine for a while now,
and decided to build the editor GUI using Agar.
Anyway, I want to be able initialize the OpenGL/SDL context
myself, and then to be able to turn on an editor mode in the
engine using Agar later. Anyway, I wrote some small test code to see if
I could launch Agar with a previously defined OpenGL SDL_Surface. The
program is adapted from the
C++ demo.
Code:
#include <agar/core.h>
#include <agar/gui.h>
#include <agar/gui/opengl.h>
#ifdef _APPLE_
#include <SDL/SDL_opengl.h>
#include <SDL/SDL.h>
#else
#include <SDL_opengl.h>
#include <SDL.h>
#endif
#include <iostream>
using namespace std;
int
main(int argc, char *argv[])
{
AG_Window *win;
SDL_Surface * screen;
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER);
/*Set buffer sizes*/
SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,8);
screen = SDL_SetVideoMode(640,480,32,SDL_OPENGL| SDL_HWSURFACE);
if (AG_InitCore("cpp-demo", 0) == -1) {
cerr << AG_GetError() << endl;
return (1);
}
if (AG_InitVideoSDL(screen,AG_VIDEO_OPENGL) == -1) {
cerr << AG_GetError() << endl;
return (-1);
}
AG_BindGlobalKey(AG_KEY_ESCAPE, AG_KEYMOD_ANY, AG_Quit);
win = AG_WindowNew(0);
AG_LabelNew(win, 0, "Hello World!");
AG_WindowShow(win);
AG_EventLoop();
AG_Destroy();
return (0);
}
As you can see I'm calling AG_InitVideoSDL. The above code
segment works correctly if you remove the SDL_OPENGL
flag from SDL_SetVideoMode, otherwise it causes a
segmentation fault when AG_EventLoop is called. I did a
stack trace, and found that the function SDL_FillRect
was being called, which would indicate that the non-opengl
sdl driver is being called. So, my question is this, what is the
correct way of setting Agar up for an OpenGl based
SDL_Surface which has already been created. I'm keen to
have a strict control on Agar using a custom event loop,
but for now I just want to get it accepting my surface.
_______________________________________________
Agar mailing list
[email protected]
http://libagar.org/lists.html