summaryrefslogtreecommitdiffstats
path: root/sdl/pyramid.c
diff options
context:
space:
mode:
Diffstat (limited to 'sdl/pyramid.c')
-rw-r--r--sdl/pyramid.c64
1 files changed, 19 insertions, 45 deletions
diff --git a/sdl/pyramid.c b/sdl/pyramid.c
index 566c976..4fb2b6a 100644
--- a/sdl/pyramid.c
+++ b/sdl/pyramid.c
@@ -26,6 +26,7 @@
#include "gltools.h"
#include "math3d.h"
#include "platform.h"
+#include "sdltools.h"
#include "window.h"
/* function prototypes */
@@ -34,15 +35,16 @@ static void process_events(void);
static void platform_init(void);
static void platform_destroy(void);
static void render(void);
-GLuint gltLoadTGATexture(const char *);
/* global */
int program_running = 1;
-const unsigned int xres = 640;
-const unsigned int yres = 480;
-const unsigned int bpp = 32;
+const int xres_w = 640;
+const int yres_w = 480;
+const int bpp_w = 32;
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
@@ -58,6 +60,9 @@ static struct
GLfloat xrot;
GLfloat yrot;
+
+ SDL_TimerID timer_id;
+ SDL_Cursor *my_cursor;
} p;
static void keys(SDL_keysym *keysym, const unsigned int *keys_held, const int flag)
@@ -90,7 +95,7 @@ static void keys(SDL_keysym *keysym, const unsigned int *keys_held, const int fl
p.yrot -= 5.0f;
if (keys_held[SDLK_d])
p.yrot += 5.0f;
-
+
if (keys_held[SDLK_UP])
glframe_move_forward(&p.camera, 0.05f);
if (keys_held[SDLK_DOWN])
@@ -105,7 +110,7 @@ static void keys(SDL_keysym *keysym, const unsigned int *keys_held, const int fl
if (keys_held[SDLK_m])
glframe_rotate_local_x(&p.camera, -0.02f);
}
-
+
p.xrot = (GLfloat) ((const int) p.xrot % 360);
p.yrot = (GLfloat) ((const int) p.yrot % 360);
}
@@ -155,42 +160,6 @@ static void process_events(void)
flag = !flag;
}
-/* mipmapping enabled by default */
-GLuint gltLoadTGATexture(const char *fname)
-{
- GLuint handle;
-
- /* variables used for texture loading */
- GLbyte *pBytes;
- GLint iWidth, iHeight, iComponents;
- GLenum eFormat;
-
- glGenTextures(1, &handle);
- glBindTexture(GL_TEXTURE_2D, handle);
-
- /* load texture */
- glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-
- pBytes = gltLoadTGA(fname, &iWidth, &iHeight, &iComponents, &eFormat);
- if (!pBytes)
- fprintf(stderr, "gltLoadTGA: failed to load texture!\n");
-
- glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat,
- GL_UNSIGNED_BYTE, pBytes);
- free(pBytes);
-
- /* seems like mipmapping only applies to MIN_FILTER since mipmapping divides
- * current texture into smaller and smaller pieces
- */
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); /* GL_LINEAR to disable mipmapping */
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
- return handle;
-}
-
static void platform_init(void)
{
memset(&p, 0, sizeof(p));
@@ -217,6 +186,13 @@ static void platform_init(void)
glColor3f(1.0f, 1.0f, 1.0f);
glDrawTriangle();
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)
@@ -274,9 +250,7 @@ int main(int argc, char **argv)
process_events();
render();
- fps_control(startclock);
- /* need some sort of a timer to trigger this */
- /* gl_frame_normalize(&p.camera); */
+ sdlFrameControl(startclock);
}
platform_destroy();