Wait for Multidimentional struct

This commit is contained in:
PedroEdiaz
2024-10-18 14:01:25 -06:00
parent 7c8cfcbfce
commit 0552616bf9
7 changed files with 48 additions and 14 deletions

View File

@@ -1,8 +1,14 @@
const char * vs = const char * vs =
"#version 330 core\n" "#version 330 core\n"
"layout (location = 0) in vec3 aPos;" "layout (location = 0) in float aPos_x;"
"layout (location = 1) in vec3 aNormal;" "layout (location = 1) in float aPos_y;"
"layout (location = 2) in float aPos_z;"
"layout (location = 3) in float aPos_w;"
"layout (location = 4) in float aNormal_x;"
"layout (location = 5) in float aNormal_y;"
"layout (location = 6) in float aNormal_z;"
"layout (location = 7) in float aNormal_w;"
"uniform float idx;" "uniform float idx;"
"uniform mat4 fix;" "uniform mat4 fix;"
@@ -16,6 +22,8 @@ const char * vs =
"void main()" "void main()"
"{" "{"
" index=idx;" " index=idx;"
" vec3 aNormal = vec3(aNormal_x,aNormal_y,aNormal_z);"
" vec3 aPos = vec3(aPos_x,aPos_y,aPos_z);"
" Normal = mat3(transpose(inverse(rot*mdl))) * aNormal;" " Normal = mat3(transpose(inverse(rot*mdl))) * aNormal;"
" gl_Position = fix * rot * mdl * vec4( aPos, 1.0 );\n" " gl_Position = fix * rot * mdl * vec4( aPos, 1.0 );\n"
" FragPos = vec3( rot * mdl * vec4(aPos, 1.0));" " FragPos = vec3( rot * mdl * vec4(aPos, 1.0));"

View File

@@ -1,6 +1,7 @@
#include "main.h" #include "main.h"
#include <cglm/quat.h> #include <cglm/quat.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <stdio.h>
#define ANGLE ((float)0x01/0xff*2*GLM_PI) #define ANGLE ((float)0x01/0xff*2*GLM_PI)
@@ -17,6 +18,17 @@ vec3 axis[3] =
{0, 0, 1}, {0, 0, 1},
}; };
void __key_callback(GLFWwindow * window, int key, int scancode, int action, int mods )
{
if( action != GLFW_PRESS)
return;
if( GLFW_KEY_0 <= key && key <= GLFW_KEY_9 )
{
printf("%d\n", key-GLFW_KEY_0 );
}
}
void __window_callback(GLFWwindow * window, int w, int h) void __window_callback(GLFWwindow * window, int w, int h)
{ {
int m; int m;
@@ -37,8 +49,8 @@ void __mouse_callback(GLFWwindow* window, int button, int action, int mods)
return; return;
glfwGetCursorPos(window, &xpos, &ypos); glfwGetCursorPos(window, &xpos, &ypos);
glReadPixels((int)xpos, (int)(window_height - ypos), 1, 1, GL_GREEN, GL_UNSIGNED_BYTE, &green_value); glReadPixels((int)xpos, (int)(window_height - ypos), 1, 1, GL_GREEN,
GL_UNSIGNED_BYTE, &green_value);
switch(green_value) switch(green_value)
{ {

View File

@@ -9,6 +9,8 @@
#define WIDTH 512 #define WIDTH 512
#define HEIGHT 512 #define HEIGHT 512
unsigned char coordanate[4] = {0,1,2,3};
unsigned char palette[] = unsigned char palette[] =
{ {
16, 16,
@@ -82,7 +84,7 @@ int main( void )
{ {
float * n_cube; float * n_cube;
n_cube = fill_normal( d_cube ); n_cube = fill_normal( d_cube );
if( !( m_cube = create_mesh( d_cube, n_cube ) ) ) if( !( m_cube = create_mesh( d_cube, n_cube, coordanate ) ) )
goto error_mesh_cube; goto error_mesh_cube;
free( n_cube ); free( n_cube );
} }
@@ -91,7 +93,7 @@ int main( void )
{ {
float * n_axis; float * n_axis;
n_axis = fill_normal( d_axis ); n_axis = fill_normal( d_axis );
if( !( m_axis = create_mesh( d_axis, n_axis ) ) ) if( !( m_axis = create_mesh( d_axis, n_axis, coordanate ) ) )
goto error_mesh_axis; goto error_mesh_axis;
free( n_axis ); free( n_axis );
} }

View File

@@ -22,7 +22,7 @@ int is_open_window(window_t window);
void close_window(window_t window); void close_window(window_t window);
mesh_t create_mesh( float * d, float * n); mesh_t create_mesh( float * d, float * n, unsigned char * coordanate );
void destroy_mesh(mesh_t p); void destroy_mesh(mesh_t p);

View File

@@ -7,7 +7,7 @@ struct obj
unsigned int vertex, vao, n_vbo, d_vbo; unsigned int vertex, vao, n_vbo, d_vbo;
}; };
mesh_t create_mesh( float * d, float * n ) mesh_t create_mesh( float * d, float * n, unsigned char * coordanate )
{ {
struct obj * p; struct obj * p;
@@ -22,15 +22,27 @@ mesh_t create_mesh( float * d, float * n )
glBindBuffer( GL_ARRAY_BUFFER, p->d_vbo ); glBindBuffer( GL_ARRAY_BUFFER, p->d_vbo );
glBufferData( GL_ARRAY_BUFFER, p->vertex*3*sizeof(float), d+1, glBufferData( GL_ARRAY_BUFFER, p->vertex*3*sizeof(float), d+1,
GL_STATIC_DRAW ); GL_STATIC_DRAW );
glVertexAttribPointer( 0,3,GL_FLOAT, 0, 3*sizeof(float), NULL ); glVertexAttribPointer( 0,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[0]*sizeof(float)) );
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glVertexAttribPointer( 1,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[1]*sizeof(float)) );
glEnableVertexAttribArray(1);
glVertexAttribPointer( 2,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[2]*sizeof(float)) );
glEnableVertexAttribArray(2);
glVertexAttribPointer( 3,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[3]*sizeof(float)) );
glEnableVertexAttribArray(3);
glGenBuffers( 1, &p->n_vbo ); glGenBuffers( 1, &p->n_vbo );
glBindBuffer( GL_ARRAY_BUFFER, p->n_vbo ); glBindBuffer( GL_ARRAY_BUFFER, p->n_vbo );
glBufferData( GL_ARRAY_BUFFER, p->vertex*3*sizeof(float), n+1, glBufferData( GL_ARRAY_BUFFER, p->vertex*3*sizeof(float), n+1,
GL_STATIC_DRAW ); GL_STATIC_DRAW );
glVertexAttribPointer( 1,3,GL_FLOAT, 0, 3*sizeof(float), NULL ); glVertexAttribPointer( 4,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[0]*sizeof(float)) );
glEnableVertexAttribArray(1); glEnableVertexAttribArray(4);
glVertexAttribPointer( 5,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[1]*sizeof(float)) );
glEnableVertexAttribArray(5);
glVertexAttribPointer( 6,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[2]*sizeof(float)) );
glEnableVertexAttribArray(6);
glVertexAttribPointer( 7,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[3]*sizeof(float)) );
glEnableVertexAttribArray(7);
return p; return p;
} }

View File

@@ -4,12 +4,11 @@
void __window_callback(GLFWwindow *, int, int); void __window_callback(GLFWwindow *, int, int);
void __mouse_callback(GLFWwindow *, int, int, int); void __mouse_callback(GLFWwindow *, int, int, int);
void __scroll_callback(GLFWwindow *, double, double); void __scroll_callback(GLFWwindow *, double, double);
void __key_callback(GLFWwindow *, int, int, int, int);
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;
@@ -29,6 +28,7 @@ window_t init_window(unsigned int w, unsigned int h, const char * name)
glfwSetWindowSizeCallback(window, __window_callback); glfwSetWindowSizeCallback(window, __window_callback);
glfwSetMouseButtonCallback((GLFWwindow*)window, __mouse_callback); glfwSetMouseButtonCallback((GLFWwindow*)window, __mouse_callback);
glfwSetScrollCallback((GLFWwindow*)window, __scroll_callback); glfwSetScrollCallback((GLFWwindow*)window, __scroll_callback);
glfwSetKeyCallback((GLFWwindow*)window, __key_callback);
__window_callback( window, w, h ); __window_callback( window, w, h );