Merge: crisel -> main
This commit is contained in:
109
src/input.c
109
src/input.c
@@ -2,52 +2,100 @@
|
|||||||
#include <cglm/quat.h>
|
#include <cglm/quat.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#define ANGLE ((float)0x02/0xff*2*GLM_PI)
|
#define ANGLE ((float)0x01/0xff*2*GLM_PI)
|
||||||
|
|
||||||
|
unsigned char selected_axis = 0;
|
||||||
|
int window_width;
|
||||||
|
int window_height;
|
||||||
|
|
||||||
versor q = GLM_QUAT_IDENTITY_INIT;
|
versor q = GLM_QUAT_IDENTITY_INIT;
|
||||||
|
|
||||||
vec3 axis[3] =
|
vec3 axis[3] =
|
||||||
{
|
{
|
||||||
{1,0,0},
|
{1, 0, 0},
|
||||||
{0,1,0},
|
{0, 1, 0},
|
||||||
{0,0,1},
|
{0, 0, 1},
|
||||||
};
|
};
|
||||||
|
|
||||||
quat_t poll_input( window_t window )
|
void __window_callback(GLFWwindow * window, int w, int h)
|
||||||
|
{
|
||||||
|
int m;
|
||||||
|
|
||||||
|
m = (w < h) ? w : h;
|
||||||
|
window_width = w;
|
||||||
|
window_height = h;
|
||||||
|
|
||||||
|
glViewport((w - m) / 2, (h - m) / 2, m, m);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __mouse_callback(GLFWwindow* window, int button, int action, int mods)
|
||||||
|
{
|
||||||
|
unsigned char green_value;
|
||||||
|
double xpos, ypos;
|
||||||
|
|
||||||
|
if( button != GLFW_MOUSE_BUTTON_LEFT || action != GLFW_PRESS )
|
||||||
|
return;
|
||||||
|
|
||||||
|
glfwGetCursorPos(window, &xpos, &ypos);
|
||||||
|
glReadPixels((int)xpos, (int)(window_height - ypos), 1, 1, GL_GREEN, GL_UNSIGNED_BYTE, &green_value);
|
||||||
|
|
||||||
|
|
||||||
|
switch(green_value)
|
||||||
|
{
|
||||||
|
case 0xD3:
|
||||||
|
case 0xD4:
|
||||||
|
case 0xD5:
|
||||||
|
selected_axis = green_value-0xD3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void __scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
|
||||||
{
|
{
|
||||||
versor p = GLM_QUAT_IDENTITY_INIT;
|
versor p = GLM_QUAT_IDENTITY_INIT;
|
||||||
|
|
||||||
if( glfwGetKey( (void*)window, 'Q' ) == GLFW_PRESS )
|
glm_quatv(p, yoffset*ANGLE, axis[selected_axis]);
|
||||||
|
|
||||||
|
glm_quat_mul(p, q, q);
|
||||||
|
glm_quat_rotatev(p, axis[0], axis[0]);
|
||||||
|
glm_quat_rotatev(p, axis[1], axis[1]);
|
||||||
|
glm_quat_rotatev(p, axis[2], axis[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
quat_t poll_input(window_t window)
|
||||||
|
{
|
||||||
|
versor p = GLM_QUAT_IDENTITY_INIT;
|
||||||
|
|
||||||
|
if( glfwGetKey((GLFWwindow*)window, 'Q') == GLFW_PRESS )
|
||||||
{
|
{
|
||||||
glm_quatv( p, ANGLE, axis[0] );
|
glm_quatv(p, ANGLE, axis[0]);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if( glfwGetKey( (void*)window, 'W' ) == GLFW_PRESS )
|
if( glfwGetKey((GLFWwindow*)window, 'W') == GLFW_PRESS )
|
||||||
{
|
{
|
||||||
glm_quatv( p, -ANGLE, axis[0] );
|
glm_quatv(p, -ANGLE, axis[0]);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if( glfwGetKey((GLFWwindow*)window, 'A') == GLFW_PRESS )
|
||||||
|
{
|
||||||
|
glm_quatv(p, ANGLE, axis[1]);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if( glfwGetKey((GLFWwindow*)window, 'S') == GLFW_PRESS )
|
||||||
|
{
|
||||||
|
glm_quatv(p, -ANGLE, axis[1]);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if( glfwGetKey((GLFWwindow*)window, 'Z') == GLFW_PRESS )
|
||||||
|
{
|
||||||
|
glm_quatv(p, ANGLE, axis[2]);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if( glfwGetKey((GLFWwindow*)window, 'X') == GLFW_PRESS )
|
||||||
|
{
|
||||||
|
glm_quatv(p, -ANGLE, axis[2]);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( glfwGetKey( (void*)window, 'A' ) == GLFW_PRESS )
|
|
||||||
{
|
|
||||||
glm_quatv( p, ANGLE, axis[1] );
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
if( glfwGetKey( (void*)window, 'S' ) == GLFW_PRESS )
|
|
||||||
{
|
|
||||||
glm_quatv( p, -ANGLE, axis[1] );
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( glfwGetKey( (void*)window, 'Z' ) == GLFW_PRESS )
|
|
||||||
{
|
|
||||||
glm_quatv( p, ANGLE, axis[2] );
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
if( glfwGetKey( (void*)window, 'X' ) == GLFW_PRESS )
|
|
||||||
{
|
|
||||||
glm_quatv( p, -ANGLE, axis[2] );
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
end:
|
end:
|
||||||
glm_quat_mul( p, q, q );
|
glm_quat_mul( p, q, q );
|
||||||
glm_quat_rotatev( p, axis[0], axis[0] );
|
glm_quat_rotatev( p, axis[0], axis[0] );
|
||||||
@@ -56,3 +104,4 @@ end:
|
|||||||
glm_quat_normalize( q );
|
glm_quat_normalize( q );
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
#include "data/axis.h"
|
#include "data/axis.h"
|
||||||
#include "data/shaders.h"
|
#include "data/shaders.h"
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
//#include <stdlib.h>
|
|
||||||
|
|
||||||
#define WIDTH 512
|
#define WIDTH 512
|
||||||
#define HEIGHT 512
|
#define HEIGHT 512
|
||||||
|
|
||||||
|
|||||||
49
src/main.h
49
src/main.h
@@ -1,3 +1,6 @@
|
|||||||
|
#include <GL/glew.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
typedef const void * window_t;
|
typedef const void * window_t;
|
||||||
typedef unsigned int id_t;
|
typedef unsigned int id_t;
|
||||||
typedef void * mesh_t;
|
typedef void * mesh_t;
|
||||||
@@ -12,48 +15,48 @@ enum
|
|||||||
VERTEX, FRAGMENT
|
VERTEX, FRAGMENT
|
||||||
};
|
};
|
||||||
|
|
||||||
window_t init_window( unsigned int w, unsigned int h, const char * name );
|
window_t init_window(unsigned int w, unsigned int h, const char * name);
|
||||||
|
|
||||||
void use_window( window_t window );
|
void use_window(window_t window);
|
||||||
|
|
||||||
int is_open_window( window_t window );
|
int is_open_window(window_t window);
|
||||||
|
|
||||||
void close_window( window_t window );
|
void close_window(window_t window);
|
||||||
|
|
||||||
mesh_t create_mesh( narray_float_t mesh );
|
mesh_t create_mesh(narray_float_t mesh);
|
||||||
|
|
||||||
void destroy_mesh( mesh_t p );
|
void destroy_mesh(mesh_t p);
|
||||||
|
|
||||||
void draw_mesh( mesh_t p );
|
void draw_mesh(mesh_t p);
|
||||||
|
|
||||||
void set_clean_color_context( unsigned char, unsigned char, unsigned char );
|
void set_clean_color_context(unsigned char, unsigned char, unsigned char);
|
||||||
|
|
||||||
void clean_context( void );
|
void clean_context(void);
|
||||||
|
|
||||||
void destroy_shader( id_t shader );
|
void destroy_shader(id_t shader);
|
||||||
|
|
||||||
id_t create_shader( void );
|
id_t create_shader(void);
|
||||||
|
|
||||||
void use_shader( id_t program );
|
void use_shader(id_t program);
|
||||||
|
|
||||||
unsigned char gload_program( id_t program, const char * src, unsigned int type );
|
unsigned char gload_program(id_t program, const char * src, unsigned int type);
|
||||||
|
|
||||||
void gload_float( id_t program, char * var, float f );
|
void gload_float(id_t program, char * var, float f);
|
||||||
|
|
||||||
void gload_mat4( id_t program, char * var, mat4_t m );
|
void gload_mat4(id_t program, char * var, mat4_t m);
|
||||||
|
|
||||||
void load_fix_matrix( id_t shader, float ratio );
|
void load_fix_matrix(id_t shader, float ratio);
|
||||||
|
|
||||||
void load_mdl_matrix( id_t shader, unsigned char i, unsigned char c );
|
void load_mdl_matrix(id_t shader, unsigned char i, unsigned char c);
|
||||||
|
|
||||||
void load_rot_matrix( id_t shader, quat_t q );
|
void load_rot_matrix(id_t shader, quat_t q);
|
||||||
|
|
||||||
id_t config_texture( unsigned short type );
|
id_t config_texture(unsigned short type);
|
||||||
|
|
||||||
void use_texture( id_t texture );
|
void use_texture(id_t texture);
|
||||||
|
|
||||||
void destroy_texture( id_t texture );
|
void destroy_texture(id_t texture);
|
||||||
|
|
||||||
id_t create_palette_texture( const narray_u8_t colors );
|
id_t create_palette_texture(const narray_u8_t colors);
|
||||||
|
|
||||||
quat_t poll_input( window_t window );
|
quat_t poll_input(window_t window);
|
||||||
|
|||||||
42
src/window.c
42
src/window.c
@@ -1,24 +1,24 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
void __window_callback( GLFWwindow * window, int w, int h )
|
void __window_callback(GLFWwindow *, int, int);
|
||||||
{
|
void __mouse_callback(GLFWwindow *, int, int, int);
|
||||||
int m = ( w<h )? w: h;
|
void __scroll_callback(GLFWwindow *, double, double);
|
||||||
glViewport( (w-m)/2, (h-m)/2, m, m );
|
|
||||||
}
|
|
||||||
|
|
||||||
window_t init_window( unsigned int w, unsigned int h, const char * name )
|
window_t init_window(unsigned int w, unsigned int h, const char * name)
|
||||||
{
|
{
|
||||||
void * window;
|
void * window;
|
||||||
|
void __mouse_callback(GLFWwindow *window, int button, int action, int mods);
|
||||||
|
void __scroll_callback(GLFWwindow *window, double xoffset, double yoffset);
|
||||||
|
|
||||||
if( !glfwInit() )
|
if( !glfwInit() )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 3 );
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 3 );
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
|
|
||||||
window = glfwCreateWindow( w, h, name, NULL, NULL );
|
window = glfwCreateWindow(w, h, name, NULL, NULL);
|
||||||
|
|
||||||
if( !window )
|
if( !window )
|
||||||
{
|
{
|
||||||
@@ -26,24 +26,30 @@ window_t init_window( unsigned int w, unsigned int h, const char * name )
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowSizeCallback( window, __window_callback );
|
glfwSetWindowSizeCallback(window, __window_callback);
|
||||||
|
glfwSetMouseButtonCallback((GLFWwindow*)window, __mouse_callback);
|
||||||
|
glfwSetScrollCallback((GLFWwindow*)window, __scroll_callback);
|
||||||
|
|
||||||
|
__window_callback( window, w, h );
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
void use_window( window_t window )
|
void use_window(window_t window)
|
||||||
{
|
{
|
||||||
glfwMakeContextCurrent( (void*)window );
|
glfwMakeContextCurrent((void*)window);
|
||||||
}
|
}
|
||||||
|
|
||||||
int is_open_window( window_t window )
|
int is_open_window(window_t window)
|
||||||
{
|
{
|
||||||
glfwSwapBuffers( (void*)window );
|
glfwSwapBuffers((void*)window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
return !glfwWindowShouldClose( (void*)window );
|
|
||||||
|
return !glfwWindowShouldClose((void*)window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void close_window( window_t window )
|
void close_window(window_t window)
|
||||||
{
|
{
|
||||||
glfwDestroyWindow( (void*)window );
|
glfwDestroyWindow((void*)window);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user