Created
February 1, 2014 16:01
-
-
Save asmuth/8754141 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This file is part of the "plgl" project | |
* (c) 2014 Paul Asmuth <[email protected]> | |
* | |
* All rights reserved. Please contact me to obtain a license. | |
*/ | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <math.h> | |
#include <plgl/engine.h> | |
#include <plgl/camera.h> | |
#include <plgl/mesh.h> | |
#include <plgl/shader.h> | |
#include <plgl/vmath.h> | |
/** | |
* Minimal plgl engine example. Open a window and draw a rotating teapot with | |
* the debug shader. | |
*/ | |
int main(int argc, char** argv) { | |
double dt; | |
engine_t engine; | |
entity_t* teapot; | |
mesh_t teapot_mesh; | |
camera_t camera; | |
/* initialize the engine */ | |
engine_init(&engine); | |
if (engine_start(&engine)) { | |
goto exit; | |
} | |
/* initialize the teapot mesh (use DEBUG shader) */ | |
mesh_init(&teapot_mesh); | |
mesh_mkteapot(&teapot_mesh); | |
mesh_setshader(&teapot_mesh, engine.shaders[SHADER_DEFAULT_DEBUG]); | |
/* intialize the teapot entity */ | |
entity_init(&teapot); | |
entity_setmesh(teapot, &teapot_mesh); | |
/* setup our camera */ | |
camera_init(&camera); | |
camera.w_pos.d[0] = 0.0f; | |
camera.w_pos.d[1] = -25.0f; | |
camera.w_pos.d[2] = -27.0f; | |
camera.rot.d[1] = 0.7f; | |
camera_mkview(&camera); | |
/* fixpaul remove me */ | |
glUseProgram(engine.shaders[SHADER_DEFAULT_DEBUG]); | |
glUniformMatrix4fv(glGetUniformLocation(engine.shaders[SHADER_DEFAULT_DEBUG], "proj"), 1, GL_FALSE, (const float *) &camera.m_proj); | |
glUniformMatrix4fv(glGetUniformLocation(engine.shaders[SHADER_DEFAULT_DEBUG], "view"), 1, GL_FALSE, (const float *) &camera.m_view); | |
/* game loop */ | |
for (;;) { | |
/** | |
* engine_tick must be called at the beginnning of the game | |
* loop and returns the delta time since the last frame. | |
*/ | |
dt = engine_tick(&engine); | |
/* rotate the teapot a bit */ | |
teapot->rot.d[0] += fmod(1.0f * dt, VMATH_TAU); | |
/* clear the screen */ | |
engine_clearscr(&engine, NULL); | |
/* draw the teapot */ | |
mesh_draw_entity(teapot); | |
/* swap the buffers */ | |
engine_swapscr(&engine); | |
} | |
exit: | |
engine_stop(&engine); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment