diff --git a/test-map.cpp b/test-map.cpp new file mode 100644 index 00000000..92dec276 --- /dev/null +++ b/test-map.cpp @@ -0,0 +1,161 @@ +// Test stuff + +#ifdef WIN32 +# define WIN32_LEAN_AND_MEAN +# include +#endif +#if defined __APPLE__ && defined __MACH__ +# include +# include +#else +# include +# include +#endif + +#include +#include + +float xrot, yrot, zrot; + +/* Storage for one texture */ +GLuint texture[1]; + +// Load Bitmaps And Convert To Textures +void LoadGLTextures(void) +{ + SDL_Surface *image1 = IMG_Load("art/test/groundtest.png"); + + if (!image1) + { + SDL_Quit(); + exit(1); + } + + glGenTextures(1, &texture[0]); + glBindTexture(GL_TEXTURE_2D, texture[0]); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glTexImage2D(GL_TEXTURE_2D, 0, 4, image1->w, image1->h, 0, + GL_RGBA, GL_UNSIGNED_BYTE, image1->pixels); +}; + +void InitGL(int Width, int Height) +{ + glViewport(0, 0, Width, Height); + LoadGLTextures(); + glEnable(GL_TEXTURE_2D); + glClearColor(0.0f, 0.0f, 1.0f, 0.0f); + glClearDepth(1.0); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); + glShadeModel(GL_SMOOTH); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + gluPerspective(45.0f, (GLfloat)Width / (GLfloat)Height, 0.1f, 100.0f); + + glMatrixMode(GL_MODELVIEW); +} + +/* The main drawing function. */ +void DrawGLScene() +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glLoadIdentity(); + + glTranslatef(0.0f, 0.0f, -5.0f); + + glRotatef(xrot, 1.0f, 0.0f, 0.0f); + glRotatef(yrot, 0.0f, 1.0f, 0.0f); + glRotatef(zrot, 0.0f, 0.0f, 1.0f); + + glBindTexture(GL_TEXTURE_2D, texture[0]); + + glBegin(GL_QUADS); + + glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); + glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); + glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); + glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); + + glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); + glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); + glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); + glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); + + glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); + glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); + glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); + glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); + + glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); + glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); + glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); + glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); + + glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); + glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); + glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); + glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); + + glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); + glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); + glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); + glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); + + glEnd(); + + xrot += 0.2f; + yrot += 0.2f; + zrot += 0.2f; + + SDL_GL_SwapBuffers(); +} + +int main(int argc, char **argv) +{ + int done; + + /* Initialize SDL for video output */ + if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) + { + fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError()); + exit(1); + } + + /* Create a 640x480 OpenGL screen */ + if ( SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL ) + { + fprintf(stderr, "Unable to create OpenGL screen: %s\n", SDL_GetError()); + SDL_Quit(); + exit(2); + } + + /* Set the title bar in environments that support it */ + SDL_WM_SetCaption("Deus Hax", NULL); + + /* Loop, drawing and checking events */ + InitGL(640, 480); + done = 0; + while ( !done ) + { + DrawGLScene(); + + /* This could go in a separate function */ + SDL_Event event; + while ( SDL_PollEvent(&event) ) + { + if ( event.type == SDL_QUIT ) + done = 1; + if ( event.type == SDL_KEYDOWN ) + if ( event.key.keysym.sym == SDLK_ESCAPE ) + done = 1; + } + } + SDL_Quit(); + return 1; +} +