Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/importer/importer/framework.cc @ 2780

Last change on this file since 2780 was 2780, checked in by bensch, 20 years ago

orxonox/branches/importer: added specular, ambient light. Also made some fancy lightshow in framework (LIGHT IS NECESSARY NOW)

File size: 2.5 KB
Line 
1#include "windowHandler.h" // Include the Whandler Basecode
2#include "object.h"
3
4
5WindowHandler wHandler;  // Create an instance of the whandler basecode class
6Object* obj;
7float rotator = 0.0;
8  GLfloat whiteLight[] = {1.0, 1.0, 0.0,1.0};
9
10void DrawGLScene()
11{
12  rotator +=.001;
13 
14  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
15  glLoadIdentity(); // Reset the view
16 
17  glMatrixMode(GL_PROJECTION);                                          // Select The Projection Matrix
18  glLoadIdentity();     
19  gluPerspective(45.0f,500/375,0.1f,100.0f);
20  gluLookAt (5*sin(rotator),7.5,5*cos(rotator), 0,0,0, 0,1,0);
21  whiteLight[1] = .5+.5*sin(rotator*10);
22  whiteLight[2] = .5+.5*sin(rotator*10);
23  glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
24  obj->draw();
25
26  SDL_GL_SwapBuffers(); // Swap the buffers
27}
28
29
30int main(int argc, char *argv[])
31{
32  Uint8* keys; // This variable will be used in the keyboard routine
33  int done=FALSE; // We aren't done yet, are we?
34
35  // Create a new OpenGL window with the title "Cone3D Basecode" at
36  // 640x480x32, fullscreen and check for errors along the way
37  if(wHandler.CreateGLWindow("Whandler Basecode", 500, 375, 32, FALSE) == FALSE)
38  {
39    // If an error is found, display a message, kill the GL and SDL screens (if they were created) and exit
40    printf("Could not initalize OpenGL :(\n\n");
41    wHandler.KillGLWindow();
42    return 0;
43  }
44
45
46  obj = new Object (argv[1]);
47
48  GLfloat lightPosition[] = {10.0, 5.0, 19.0, 0.0};
49  GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0};
50  glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
51  glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
52  glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight);
53  glEnable(GL_LIGHTING);
54  glEnable(GL_LIGHT0);
55  glEnable(GL_DEPTH_TEST);
56
57  // Build the font from a TGA image font.tga in the data directory
58  // Hide the mouse cursor
59  SDL_ShowCursor(0);
60
61  // This is the main loop for the entire program and it will run until done==TRUE
62  while(!done)
63  {
64    // Draw the scene
65    DrawGLScene();
66    // And poll for events
67    SDL_Event event;
68    while ( SDL_PollEvent(&event) ) {
69      switch (event.type) {
70        // If a quit event was recieved
71        case SDL_QUIT:
72          // then we're done and we'll end this program
73          done=TRUE;
74          break;
75        default:
76          break;
77      }
78    }
79
80    // Get the state of the keyboard keys
81    keys = SDL_GetKeyState(NULL);
82
83    // and check if ESCAPE has been pressed. If so then quit
84    if(keys[SDLK_ESCAPE]) done=TRUE;
85  }
86
87  // Kill the GL & SDL screens
88  wHandler.KillGLWindow();
89  // And quit
90  return 0;
91}
Note: See TracBrowser for help on using the repository browser.