source: trunk/test-map.cpp @ 13

Last change on this file since 13 was 13, checked in by sam, 11 years ago

fiuwoifeowifoewifoewfew

  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1// Test stuff
2
3#ifdef WIN32
4#   define WIN32_LEAN_AND_MEAN
5#   include <windows.h>
6#endif
7#if defined __APPLE__ && defined __MACH__
8#   include <OpenGL/gl.h>
9#   include <OpenGL/glu.h>
10#else
11#   include <GL/gl.h>
12#   include <GL/glu.h>
13#endif
14
15#include <SDL.h>
16#include <SDL_image.h>
17
18float xrot, yrot, zrot;
19
20/* Storage for one texture  */
21GLuint texture[1];
22
23// Load Bitmaps And Convert To Textures
24void LoadGLTextures(void)
25{       
26    SDL_Surface *image1 = IMG_Load("art/test/groundtest.png");
27
28    if (!image1)
29    {
30        SDL_Quit();
31        exit(1);
32    }
33
34    glGenTextures(1, &texture[0]);
35    glBindTexture(GL_TEXTURE_2D, texture[0]);
36
37    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
38    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
39
40    glTexImage2D(GL_TEXTURE_2D, 0, 4, image1->w, image1->h, 0,
41                 GL_RGBA, GL_UNSIGNED_BYTE, image1->pixels);
42};
43
44void InitGL(int Width, int Height)
45{
46    glViewport(0, 0, Width, Height);
47    LoadGLTextures();
48    glEnable(GL_TEXTURE_2D);
49    glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
50    glClearDepth(1.0);
51    glDepthFunc(GL_LESS);
52    glEnable(GL_DEPTH_TEST);
53    glShadeModel(GL_SMOOTH);
54
55    glMatrixMode(GL_PROJECTION);
56    glLoadIdentity();
57
58    gluPerspective(45.0f, (GLfloat)Width / (GLfloat)Height, 0.1f, 100.0f);
59
60    glMatrixMode(GL_MODELVIEW);
61}
62
63/* The main drawing function. */
64void DrawGLScene()
65{
66    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
67    glLoadIdentity();
68
69    glTranslatef(0.0f, 0.0f, -5.0f);
70
71    glRotatef(xrot, 1.0f, 0.0f, 0.0f);
72    glRotatef(yrot, 0.0f, 1.0f, 0.0f);
73    glRotatef(zrot, 0.0f, 0.0f, 1.0f);
74
75    glBindTexture(GL_TEXTURE_2D, texture[0]);
76
77    glBegin(GL_QUADS);
78
79    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
80    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
81    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
82    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
83
84    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
85    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
86    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
87    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
88
89    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
90    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
91    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
92    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
93
94    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
95    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
96    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
97    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
98
99    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
100    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
101    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
102    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
103
104    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
105    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
106    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
107    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
108
109    glEnd();
110
111    xrot += 0.2f;
112    yrot += 0.2f;
113    zrot += 0.2f;
114
115    SDL_GL_SwapBuffers();
116}
117
118int main(int argc, char **argv)
119{
120  int done;
121
122  /* Initialize SDL for video output */
123  if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
124  {
125    fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
126    exit(1);
127  }
128
129  /* Create a 640x480 OpenGL screen */
130  if ( SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL )
131  {
132    fprintf(stderr, "Unable to create OpenGL screen: %s\n", SDL_GetError());
133    SDL_Quit();
134    exit(2);
135  }
136
137  /* Set the title bar in environments that support it */
138  SDL_WM_SetCaption("Deus Hax", NULL);
139
140  /* Loop, drawing and checking events */
141  InitGL(640, 480);
142  done = 0;
143  while ( !done )
144  {
145    DrawGLScene();
146
147    /* This could go in a separate function */
148    SDL_Event event;
149    while ( SDL_PollEvent(&event) )
150    {
151      if ( event.type == SDL_QUIT )
152        done = 1;
153      if ( event.type == SDL_KEYDOWN )
154        if ( event.key.keysym.sym == SDLK_ESCAPE )
155          done = 1;
156    }
157  }
158  SDL_Quit();
159  return 1;
160}
161
Note: See TracBrowser for help on using the repository browser.