Handle resize better

This commit is contained in:
Joshua Granick
2014-07-09 19:26:21 -07:00
parent 60679bd514
commit d4290a9515
4 changed files with 40 additions and 35 deletions

View File

@@ -18,6 +18,17 @@ namespace lime {
SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER);
currentUpdate = 0;
lastUpdate = 0;
nextUpdate = 0;
KeyEvent keyEvent;
MouseEvent mouseEvent;
RenderEvent renderEvent;
TouchEvent touchEvent;
UpdateEvent updateEvent;
WindowEvent windowEvent;
}
@@ -162,7 +173,6 @@ namespace lime {
case SDL_WINDOWEVENT_SHOWN:
case SDL_WINDOWEVENT_HIDDEN:
case SDL_WINDOWEVENT_SIZE_CHANGED:
case SDL_WINDOWEVENT_FOCUS_GAINED:
case SDL_WINDOWEVENT_FOCUS_LOST:
case SDL_WINDOWEVENT_MOVED:
@@ -175,6 +185,12 @@ namespace lime {
RenderEvent::Dispatch (&renderEvent);
break;
case SDL_WINDOWEVENT_SIZE_CHANGED:
ProcessWindowEvent (event);
RenderEvent::Dispatch (&renderEvent);
break;
case SDL_WINDOWEVENT_CLOSE:
ProcessWindowEvent (event);

View File

@@ -11,40 +11,26 @@ namespace lime {
currentWindow = window;
sdlWindow = ((SDLWindow*)window)->sdlWindow;
if (OpenGLBindings::Init ()) {
int sdlFlags = SDL_RENDERER_ACCELERATED;
if (window->flags & WINDOW_FLAG_VSYNC) sdlFlags |= SDL_RENDERER_PRESENTVSYNC;
if (window->flags & WINDOW_FLAG_DEPTH_BUFFER) {
SDL_GLContext context = SDL_GL_CreateContext (sdlWindow);
if (context) {
if (window->flags & WINDOW_FLAG_VSYNC) {
SDL_GL_SetSwapInterval (1);
} else {
SDL_GL_SetSwapInterval (0);
}
if (window->flags & WINDOW_FLAG_DEPTH_BUFFER) {
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 32 - (window->flags & WINDOW_FLAG_STENCIL_BUFFER) ? 8 : 0);
}
if (window->flags & WINDOW_FLAG_STENCIL_BUFFER) {
SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 8);
}
SDL_GL_MakeCurrent (sdlWindow, context);
}
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 32 - (window->flags & WINDOW_FLAG_STENCIL_BUFFER) ? 8 : 0);
}
if (window->flags & WINDOW_FLAG_STENCIL_BUFFER) {
SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 8);
}
sdlRenderer = SDL_CreateRenderer (sdlWindow, -1, sdlFlags);
OpenGLBindings::Init ();
}
@@ -57,7 +43,7 @@ namespace lime {
void SDLRenderer::Flip () {
SDL_GL_SwapWindow (sdlWindow);
SDL_RenderPresent (sdlRenderer);
}

View File

@@ -18,6 +18,7 @@ namespace lime {
virtual void Flip ();
SDL_Renderer* sdlRenderer;
SDL_Window* sdlWindow;
};

View File

@@ -13,6 +13,7 @@ class Main extends Application {
private var buffer:GLBuffer;
private var matrixUniform:GLUniformLocation;
private var program:GLProgram;
private var texture:GLTexture;
private var textureAttribute:Int;
@@ -89,14 +90,12 @@ class Main extends Application {
vertexAttribute = gl.getAttribLocation (program, "aPosition");
textureAttribute = gl.getAttribLocation (program, "aTexCoord");
var matrixUniform = gl.getUniformLocation (program, "uMatrix");
matrixUniform = gl.getUniformLocation (program, "uMatrix");
var imageUniform = gl.getUniformLocation (program, "uImage0");
gl.enableVertexAttribArray (vertexAttribute);
gl.enableVertexAttribArray (textureAttribute);
gl.uniform1i (imageUniform, 0);
gl.uniformMatrix4fv (matrixUniform, false, Matrix4.createOrtho (0, window.width, window.height, 0, -1000, 1000));
var image = Assets.getImage ("assets/lime.png");
@@ -148,6 +147,9 @@ class Main extends Application {
gl.clearColor (r, g, b, a);
gl.clear (gl.COLOR_BUFFER_BIT);
var matrix = Matrix4.createOrtho (0, window.width, window.height, 0, -1000, 1000);
gl.uniformMatrix4fv (matrixUniform, false, matrix);
gl.activeTexture (gl.TEXTURE0);
gl.bindTexture (gl.TEXTURE_2D, texture);