Skip to content

Instantly share code, notes, and snippets.

@sreich
Created January 22, 2013 01:49
Show Gist options
  • Save sreich/4591362 to your computer and use it in GitHub Desktop.
Save sreich/4591362 to your computer and use it in GitHub Desktop.
#include "Gwen/Gwen.h"
#include "Gwen/Skins/Simple.h"
#include "Gwen/Skins/TexturedBase.h"
#include "Gwen/UnitTest/UnitTest.h"
#include "Gwen/Renderers/OpenGL.h"
#include "Gwen/Controls/WindowCanvas.h"
#include "Gwen/Controls/Canvas.h"
#include <SDL_video.h>
#include <SDL.h>
#include <GL/glew.h>
//
// These are the renderers that work with WindowCanvas
// (you need to include the relevant libs to use them)
//
#include "Gwen/Renderers/OpenGL.h"
//#include "Gwen/Renderers/GDIPlus.h"
//#include "Gwen/Renderers/Direct2D.h"
//#include "Gwen/Renderers/DirectX9.h"
#include <assert.h>
//
// Program starts here
//
SDL_Window* m_window = nullptr;
SDL_GLContext m_contextGL = nullptr;
int main()
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0) {
std::string error = SDL_GetError();
assert(0);
// Debug::fatal(false, Debug::Area::System, "failure to initialize SDL error: " + error);
}
m_window = SDL_CreateWindow("TEST", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
1600, 900, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
glewInit();
m_contextGL = SDL_GL_CreateContext(m_window);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
// Request opengl 3.3 context.
// FIXME: i *want 3.2, but Mesa 9 only has 3.0.. :(
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
/* Turn on double buffering with a 24bit Z buffer.
* You may need to change this to 16 or 32 for your system */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
Gwen::Renderer::OpenGL *m_renderer = new Gwen::Renderer::OpenGL();
m_renderer->Init();
Gwen::Skin::TexturedBase m_skin(m_renderer);
m_skin.Init("/home/sreich/DefaultSkin.png");
Gwen::Controls::Canvas* m_canvas = new Gwen::Controls::Canvas(&m_skin);
m_canvas->SetSize(998, 650 - 24);
m_canvas->SetDrawBackground(true);
m_canvas->SetBackgroundColor(Gwen::Color(0, 200, 0, 255));
UnitTest* m_unit = new UnitTest(m_canvas);
m_unit->SetPos(10, 10);
m_unit->Show();
while (true) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
m_canvas->RenderCanvas();
SDL_GL_SwapWindow(m_window);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment