diff options
Diffstat (limited to 'sdl/pyramid.c')
-rw-r--r-- | sdl/pyramid.c | 91 |
1 files changed, 14 insertions, 77 deletions
diff --git a/sdl/pyramid.c b/sdl/pyramid.c index bc0fd7a..1260dff 100644 --- a/sdl/pyramid.c +++ b/sdl/pyramid.c @@ -14,6 +14,8 @@ * * it might be time to split the code, and make a shader version... * + * ToDo: on linux, update the makefile dependencies, and check out lua-config + * */ #include <SDL/SDL.h> @@ -32,41 +34,21 @@ /* function prototypes */ static void keys(SDL_keysym *, const unsigned int *, const int); static void process_events(void); -static void platform_init(void); -static void platform_destroy(void); static void render(void); -/* global */ +/* globals */ +struct platform p; + +/* sane defaults, these can be overwritten by config.lua */ int program_running = 1; -const unsigned int xres_w = 640; -const unsigned int yres_w = 480; -const unsigned int bpp_w = 32; -const unsigned int af_w = 8; +unsigned int xres_w = 640; +unsigned int yres_w = 480; +unsigned int bpp_w = 32; +unsigned int af_w = 8; const char *window_caption = "Textured Pyramid"; const char *window_icon_path = "tux.png"; const unsigned int sdl_video_flags = SDL_OPENGL | SDL_RESIZABLE; - -/* platform struct */ -static struct -{ - GLFrame camera; - - /* display lists identifiers */ - GLuint ground_list; - GLuint triangle_list; - - /* pyramid texture handle */ - GLuint textures[2]; - - GLfloat xrot; - GLfloat yrot; - - /* SDL surface, our screen */ - SDL_Surface *screen; - - SDL_TimerID timer_id; - SDL_Cursor *my_cursor; -} p; +unsigned int maxfps_w = 60; static void keys(SDL_keysym *keysym, const unsigned int *keys_held, const int flag) { @@ -163,49 +145,6 @@ static void process_events(void) flag = !flag; } -static void platform_init(void) -{ - memset(&p, 0, sizeof(p)); - - /* set the camera to <0,0,0> */ - glframe_reset(&p.camera); - p.textures[0] = gltLoadTGATexture("stone.tga"); - p.textures[1] = gltLoadTGATexture("grass.tga"); - - /* display list, precompile commands */ - p.ground_list = glGenLists(2); - p.triangle_list = p.ground_list + 1; - - /* a triangle with a texture */ - glNewList(p.triangle_list, GL_COMPILE); - glBindTexture(GL_TEXTURE_2D, p.textures[0]); - /* glBindTexture(GL_TEXTURE_2D, p.textures[1]); */ - glColor3f(1.0f, 1.0f, 1.0f); - glDrawTriangle(); - glEndList(); - - /* a ground drawn using magneta lines */ - glNewList(p.ground_list, GL_COMPILE); - glColor3ub(255, 0, 255); - glDrawGround(); - glEndList(); - - /* add a simple timer / callback function */ - p.timer_id = SDL_AddTimer(5000, sdlTimerCallback, &(p.camera)); - - /* apply a custom cursor */ - p.my_cursor = sdlInitCursor(arrow); - SDL_SetCursor(p.my_cursor); -} - -static void platform_destroy(void) -{ - glDeleteTextures(2, p.textures); - glDeleteLists(p.ground_list, 2); - - SDL_FreeSurface(p.screen); -} - static void render(void) { /* clear the window with current clearing color */ @@ -243,10 +182,8 @@ static void render(void) int main(int argc, char **argv) { - p.screen = setup_sdl(); - setup_glew(); - setup_opengl(); - platform_init(); + platform_init(&p); + gltErrorCheck(); gltOpenGLInfo(); @@ -261,7 +198,7 @@ int main(int argc, char **argv) sdlFrameControl(startclock); } - platform_destroy(); + platform_destroy(&p); puts("bye!"); return 0; |