add GUI class
This commit is contained in:
parent
dc47bf5256
commit
6767062155
69
src/gui/GUI.cc
Normal file
69
src/gui/GUI.cc
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#include "GUI.h"
|
||||||
|
#include "gl3w.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#define WIDTH 500
|
||||||
|
#define HEIGHT 500
|
||||||
|
|
||||||
|
namespace jes
|
||||||
|
{
|
||||||
|
GUI::GUI()
|
||||||
|
{
|
||||||
|
if (SDL_Init(SDL_INIT_VIDEO))
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to initialize SDL!" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
atexit(SDL_Quit);
|
||||||
|
|
||||||
|
m_window = SDL_CreateWindow("jes",
|
||||||
|
SDL_WINDOWPOS_UNDEFINED,
|
||||||
|
SDL_WINDOWPOS_UNDEFINED,
|
||||||
|
WIDTH,
|
||||||
|
HEIGHT,
|
||||||
|
SDL_WINDOW_OPENGL);
|
||||||
|
if (!m_window)
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to create window!" << std::endl;
|
||||||
|
SDL_Quit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)SDL_GL_CreateContext(m_window);
|
||||||
|
|
||||||
|
if (gl3wInit() != 0)
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to gl3wInit()" << std::endl;
|
||||||
|
SDL_Quit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gl3wIsSupported(3, 0))
|
||||||
|
{
|
||||||
|
std::cerr << "OpenGL 3.0 is not supported!" << std::endl;
|
||||||
|
SDL_Quit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
glClearColor (0.0, 0.0, 0.0, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUI::run()
|
||||||
|
{
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
SDL_GL_SwapWindow(m_window);
|
||||||
|
|
||||||
|
SDL_Event event;
|
||||||
|
while (SDL_WaitEvent(&event))
|
||||||
|
{
|
||||||
|
if (event.type == SDL_QUIT)
|
||||||
|
break;
|
||||||
|
else if (event.type == SDL_KEYDOWN)
|
||||||
|
{
|
||||||
|
if (event.key.keysym.sym == SDLK_ESCAPE)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
src/gui/GUI.h
Normal file
21
src/gui/GUI.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef JES_GUI_H
|
||||||
|
#define JES_GUI_H
|
||||||
|
|
||||||
|
#include "jes/Ref.h"
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
namespace jes
|
||||||
|
{
|
||||||
|
class GUI
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GUI();
|
||||||
|
void run();
|
||||||
|
protected:
|
||||||
|
SDL_Window * m_window;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef Ref<GUI> GUIRef;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,75 +1,10 @@
|
|||||||
#include "gl3w.h"
|
|
||||||
#include <SDL.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "GUI.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define WIDTH 500
|
|
||||||
#define HEIGHT 500
|
|
||||||
|
|
||||||
void init(void)
|
|
||||||
{
|
|
||||||
glClearColor (0.0, 0.0, 0.0, 0.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void display(SDL_Window * window)
|
|
||||||
{
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
SDL_GL_SwapWindow(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (SDL_Init(SDL_INIT_VIDEO))
|
jes::GUIRef gui = new jes::GUI();
|
||||||
{
|
gui->run();
|
||||||
cerr << "Failed to initialize SDL!" << endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
atexit(SDL_Quit);
|
|
||||||
|
|
||||||
SDL_Window * window = SDL_CreateWindow(argv[0],
|
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
|
||||||
WIDTH,
|
|
||||||
HEIGHT,
|
|
||||||
SDL_WINDOW_OPENGL);
|
|
||||||
if (!window)
|
|
||||||
{
|
|
||||||
cerr << "Failed to create window!" << endl;
|
|
||||||
SDL_Quit();
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
(void)SDL_GL_CreateContext(window);
|
|
||||||
|
|
||||||
if (gl3wInit() != 0)
|
|
||||||
{
|
|
||||||
cerr << "Failed to gl3wInit()" << endl;
|
|
||||||
SDL_Quit();
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gl3wIsSupported(3, 0))
|
|
||||||
{
|
|
||||||
cerr << "OpenGL 3.0 is not supported!" << endl;
|
|
||||||
SDL_Quit();
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
init();
|
|
||||||
display(window);
|
|
||||||
SDL_Event event;
|
|
||||||
while (SDL_WaitEvent(&event))
|
|
||||||
{
|
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
break;
|
|
||||||
else if (event.type == SDL_KEYDOWN)
|
|
||||||
{
|
|
||||||
if (event.key.keysym.sym == SDLK_ESCAPE)
|
|
||||||
break;
|
|
||||||
if (event.key.keysym.sym == SDLK_RETURN)
|
|
||||||
display(window);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user