summaryrefslogtreecommitdiff
path: root/src/scene01.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scene01.c')
-rw-r--r--src/scene01.c79
1 files changed, 35 insertions, 44 deletions
diff --git a/src/scene01.c b/src/scene01.c
index 7a6aed1..f8027c4 100644
--- a/src/scene01.c
+++ b/src/scene01.c
@@ -22,7 +22,7 @@
// Mostly inspired by CC0 https://gist.github.com/koute/7391344
typedef float t_mat4x4[16];
-static inline void mat4x4_ortho( t_mat4x4 out, float left, float right, float bottom, float top, float znear, float zfar )
+static inline void mat4x4_ortho(t_mat4x4 out, float left, float right, float bottom, float top, float znear, float zfar)
{
#define T(a, b) (a * 4 + b)
@@ -57,7 +57,7 @@ static const char * vertex_shader =
"uniform mat4 u_projection_matrix;\n"
"void main() {\n"
" v_color = i_color;\n"
- " gl_Position = u_projection_matrix * vec4( i_position, 0.0, 1.0 );\n"
+ " gl_Position = u_projection_matrix * vec4(i_position, 0.0, 1.0);\n"
"}\n";
static const char * fragment_shader =
@@ -77,59 +77,50 @@ typedef enum t_attrib_id
int scene01_init_gl(graphical_env_t *ge, scene01_env_t *se) {
GLuint vs, fs, program;
- vs = glCreateShader( GL_VERTEX_SHADER );
- fs = glCreateShader( GL_FRAGMENT_SHADER );
+ vs = glCreateShader(GL_VERTEX_SHADER);
+ fs = glCreateShader(GL_FRAGMENT_SHADER);
- int length = strlen( vertex_shader );
- glShaderSource( vs, 1, ( const GLchar ** )&vertex_shader, &length );
- glCompileShader( vs );
+ int length = strlen(vertex_shader);
+ glShaderSource(vs, 1, (const GLchar **)&vertex_shader, &length);
+ glCompileShader(vs);
GLint status;
- glGetShaderiv( vs, GL_COMPILE_STATUS, &status );
- if( status == GL_FALSE )
- {
- fprintf( stderr, "vertex shader compilation failed\n" );
- return 1;
- }
+ glGetShaderiv(vs, GL_COMPILE_STATUS, &status);
+ if(status == GL_FALSE) return 40;
- length = strlen( fragment_shader );
- glShaderSource( fs, 1, ( const GLchar ** )&fragment_shader, &length );
- glCompileShader( fs );
+ length = strlen(fragment_shader);
+ glShaderSource(fs, 1, (const GLchar **)&fragment_shader, &length);
+ glCompileShader(fs);
- glGetShaderiv( fs, GL_COMPILE_STATUS, &status );
- if( status == GL_FALSE )
- {
- fprintf( stderr, "fragment shader compilation failed\n" );
- return 1;
- }
+ glGetShaderiv(fs, GL_COMPILE_STATUS, &status);
+ if(status == GL_FALSE) return 41;
program = glCreateProgram();
- glAttachShader( program, vs );
- glAttachShader( program, fs );
+ glAttachShader(program, vs);
+ glAttachShader(program, fs);
- glBindAttribLocation( program, attrib_position, "i_position" );
- glBindAttribLocation( program, attrib_color, "i_color" );
- glLinkProgram( program );
+ glBindAttribLocation(program, attrib_position, "i_position");
+ glBindAttribLocation(program, attrib_color, "i_color");
+ glLinkProgram(program);
- glUseProgram( program );
+ glUseProgram(program);
- glDisable( GL_DEPTH_TEST );
- //glClearColor( 0.5, 0.0, 0.0, 0.0 );
- glClearColor( 0.5, 0.5, 0.0, 0.0 );
- glViewport( 0, 0, FBUF_W, FBUF_H );
+ glDisable(GL_DEPTH_TEST);
+ glClearColor(0.5, 0.0, 0.0, 0.0);
+ glViewport(0, 0, FBUF_W, FBUF_H);
GLuint vbo;
- glGenVertexArrays( 1, &(se->vao) );
- glGenBuffers( 1, &vbo );
- glBindVertexArray( se->vao );
- glBindBuffer( GL_ARRAY_BUFFER, vbo );
+ glGenVertexArrays(1, &(se->vao));
+ glGenBuffers(1, &vbo);
+ glBindVertexArray(se->vao);
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glEnableVertexAttribArray( attrib_position );
- glEnableVertexAttribArray( attrib_color );
+ glEnableVertexAttribArray(attrib_position);
+ glEnableVertexAttribArray(attrib_color);
- glVertexAttribPointer( attrib_color, 4, GL_FLOAT, GL_FALSE, sizeof( float ) * 6, 0 );
- glVertexAttribPointer( attrib_position, 2, GL_FLOAT, GL_FALSE, sizeof( float ) * 6, ( void * )(4 * sizeof(float)) );
+ glVertexAttribPointer(attrib_color, 4, GL_FLOAT, GL_FALSE, sizeof(float)*6, 0);
+ glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, sizeof(float)*6, (void *)(4*sizeof(float)));
const GLfloat g_vertex_buffer_data[] = {
/* R, G, B, A, X, Y */
@@ -142,11 +133,11 @@ int scene01_init_gl(graphical_env_t *ge, scene01_env_t *se) {
1, 1, 1, 1, 0, FBUF_H
};
- glBufferData( GL_ARRAY_BUFFER, sizeof( g_vertex_buffer_data ), g_vertex_buffer_data, GL_STATIC_DRAW );
+ glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
t_mat4x4 projection_matrix;
- mat4x4_ortho( projection_matrix, 0.0f, (float)FBUF_W, (float)FBUF_H, 0.0f, 0.0f, 100.0f );
- glUniformMatrix4fv( glGetUniformLocation( program, "u_projection_matrix" ), 1, GL_FALSE, projection_matrix );
+ mat4x4_ortho(projection_matrix, 0.0f, (float)FBUF_W, (float)FBUF_H, 0.0f, 0.0f, 100.0f);
+ glUniformMatrix4fv(glGetUniformLocation(program, "u_projection_matrix"), 1, GL_FALSE, projection_matrix);
return 0;
}
@@ -205,7 +196,7 @@ int scene01_next_caca(graphical_env_t *ge, scene01_env_t *se) {
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK);
caca_put_str(cv, (w-17)/2, h/2, "This is a message");
- if ( frame >= 300 ) {
+ if (frame >= 300) {
return 1;
}
return 0;