0.1 Graph cube
This commit is contained in:
51
src/window.c
Normal file
51
src/window.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "main.h"
|
||||
|
||||
void window_callback( GLFWwindow * window, int w, int h )
|
||||
{
|
||||
int m = ( w<h )? w: h;
|
||||
|
||||
glViewport( (w-m)/2, (h-m)/2, m, m );
|
||||
}
|
||||
|
||||
window_t init_window( unsigned int w, unsigned int h, const char * name )
|
||||
{
|
||||
void * window;
|
||||
|
||||
if( !glfwInit() )
|
||||
return NULL;
|
||||
|
||||
glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 3 );
|
||||
glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 3 );
|
||||
glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
|
||||
|
||||
window = glfwCreateWindow( w, h, name, NULL, NULL );
|
||||
|
||||
if( !window )
|
||||
{
|
||||
glfwTerminate();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
glfwSetWindowSizeCallback( window, window_callback );
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
void use_window( window_t window )
|
||||
{
|
||||
glfwMakeContextCurrent( (void*)window );
|
||||
}
|
||||
|
||||
int is_open_window( window_t window )
|
||||
{
|
||||
glfwSwapBuffers( (void*)window );
|
||||
glfwPollEvents();
|
||||
return !glfwWindowShouldClose( (void*)window );
|
||||
}
|
||||
|
||||
void close_window( window_t window )
|
||||
{
|
||||
glfwDestroyWindow( (void*)window );
|
||||
glfwTerminate();
|
||||
}
|
||||
Reference in New Issue
Block a user