add main event loop, init() and display()
This commit is contained in:
parent
cf24d96c11
commit
a7d14a3aab
36
source/app.d
36
source/app.d
@ -2,6 +2,21 @@ import std.stdio;
|
||||
import derelict.sdl2.sdl;
|
||||
import derelict.opengl3.gl3;
|
||||
|
||||
enum int WIDTH = 800;
|
||||
enum int HEIGHT = 600;
|
||||
|
||||
void init()
|
||||
{
|
||||
glClearColor (1.0, 0.7, 0.0, 0.0);
|
||||
glViewport(0, 0, WIDTH, HEIGHT);
|
||||
}
|
||||
|
||||
void display(SDL_Window * window)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
SDL_GL_SwapWindow(window);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
DerelictSDL2.load();
|
||||
@ -17,8 +32,8 @@ int main()
|
||||
SDL_Window * window = SDL_CreateWindow("d-dub-derelict-sdl2-gl3-demo",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
800,
|
||||
600,
|
||||
WIDTH,
|
||||
HEIGHT,
|
||||
SDL_WINDOW_OPENGL);
|
||||
SDL_GLContext context = SDL_GL_CreateContext(window);
|
||||
|
||||
@ -30,7 +45,22 @@ int main()
|
||||
|
||||
DerelictGL3.reload();
|
||||
|
||||
SDL_Delay(2000);
|
||||
init();
|
||||
SDL_Event event;
|
||||
for (;;)
|
||||
{
|
||||
if (SDL_PollEvent(&event))
|
||||
{
|
||||
if (event.type == SDL_QUIT)
|
||||
break;
|
||||
else if (event.type == SDL_KEYDOWN)
|
||||
{
|
||||
if (event.key.keysym.scancode == SDL_SCANCODE_ESCAPE)
|
||||
break;
|
||||
}
|
||||
}
|
||||
display(window);
|
||||
}
|
||||
|
||||
SDL_GL_DeleteContext(context);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user