Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3338 in orxonox.OLD for orxonox/branches/parenting


Ignore:
Timestamp:
Jan 5, 2005, 4:13:50 AM (20 years ago)
Author:
patrick
Message:

orxonox/branches/parenting: implemented a simple LoadScreen that just displays a bmp image (format will change - not important yet). You must copy a bmp file to the src directory to see the effect. if there is no bmp file, the LoadScreen won't appear. I have made a little bmp, that can be found on the server

Location:
orxonox/branches/parenting/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/parenting/src/campaign.cc

    r3336 r3338  
    8989  while( se != NULL && this->running)
    9090    {
    91       //se->displayLoadScreen();
     91      se->displayLoadScreen();
    9292      se->load();
    9393      se->init();
    94       //se->releaseLoadScreen();
     94      se->releaseLoadScreen();
    9595      se->start();
    9696      se->destroy();
  • orxonox/branches/parenting/src/orxonox.cc

    r3336 r3338  
    115115  // Set video mode
    116116  // TO DO: parse arguments for settings
    117   SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
    118   SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
    119   SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
    120   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    121  
     117  //SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
     118  //SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
     119  //SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
     120  //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
     121 
     122
     123  SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );   
     124  SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16);   
     125  SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0); 
     126  SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0);
     127  SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0);
     128  SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0);
     129  SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0);
     130
     131
     132
    122133  int bpp = 16;
    123134  int width = 640;
     
    138149  if( videoInfo->hw_available)
    139150    videoFlags |= SDL_HWSURFACE;
    140   else
     151  else 
    141152    videoFlags |= SDL_SWSURFACE;
    142153  /*
     
    153164 
    154165  // Set window labeling
    155   SDL_WM_SetCaption("Orxonox " PACKAGE_VERSION, "Orxonox " PACKAGE_VERSION);
     166  SDL_WM_SetCaption ("Orxonox " PACKAGE_VERSION, "Orxonox " PACKAGE_VERSION);
    156167 
    157168  // TO DO: Create a cool icon and use it here
     
    159170
    160171  // OpenGL stuff
    161   glClearColor(0.0, 0.0, 0.0, 0.0);
    162   glEnable(GL_DEPTH_TEST);
     172  glClearColor (0.0, 0.0, 0.0, 0.0);
     173  glEnable (GL_DEPTH_TEST);
    163174 
    164175  // LIGHTING
     
    167178  GLfloat lightPosition[] = {10.0, 10, 19.0, 0.0};
    168179
    169   glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
    170   glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight);
    171   glEnable(GL_LIGHTING);
    172   glEnable(GL_LIGHT0);
    173   glEnable(GL_DEPTH_TEST);
    174   glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
    175   glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
     180  glLightfv (GL_LIGHT0, GL_DIFFUSE, whiteLight);
     181  glLightfv (GL_LIGHT0, GL_SPECULAR, whiteLight);
     182  glEnable (GL_LIGHTING);
     183  glEnable (GL_LIGHT0);
     184  glEnable (GL_DEPTH_TEST);
     185  glLightfv (GL_LIGHT0, GL_POSITION, lightPosition);
     186  glLightfv (GL_LIGHT0, GL_DIFFUSE, whiteLight);
    176187   
     188  glEnable (GL_TEXTURE_2D);
    177189  //  glEnable(GL_COLOR);
    178190  //  glShadeModel(GL_SMOOTH);
  • orxonox/branches/parenting/src/stdincl.h

    r3326 r3338  
    1010
    1111#define null 0   //!< null
     12
     13typedef unsigned char byte;
    1214
    1315// this includes the information from configure/makefiles
  • orxonox/branches/parenting/src/world.cc

    r3337 r3338  
    145145{
    146146  printf ("World::displayLoadScreen - start\n");
    147   SDL_Surface *screen;
    148   SDL_RWops *rwop;
    149   int i;
    150  
    151   //SDL_FreeSurface (Orxonox::getInstance()->getScreen ());
    152  
    153   /* load the image */
    154   rwop = SDL_RWFromFile("load_screen.png", "rb");
    155   this->loadImage = IMG_LoadPNG_RW (rwop);
    156   if( !this->loadImage)
    157     {
    158       /* image failed to load */
    159       printf ("IMG_Load: %s\n", IMG_GetError());
    160     }
    161   printf("loaded %s: %dx%d %dbpp\n", "load_screen.png",
    162          this->loadImage->w, this->loadImage->h, this->loadImage->format->BitsPerPixel);
    163  
    164 
    165   //  screen = SDL_SetVideoMode(this->loadImage->w, this->loadImage->h, this->loadImage->format->BitsPerPixel, SDL_ANYFORMAT);
    166   screen = Orxonox::getInstance()->getScreen ();
    167   if( !screen)
    168     {
    169       printf ("SDL_SetVideoMode: %s\n", SDL_GetError());
    170       SDL_FreeSurface (this->loadImage);
     147 
     148  int w = 680;
     149  int h = 480;
     150
     151  glViewport(0,0,w,h);
     152 
     153  glMatrixMode(GL_PROJECTION);
     154  glLoadIdentity();
     155  gluPerspective(45.0f,(GLfloat)w/(GLfloat)h, .5f ,150.0f);
     156  glMatrixMode(GL_MODELVIEW);
     157
     158
     159  SDL_Surface *pBitmap[1];
     160  unsigned int textureArray[1];
     161  char *strFileName = "orx_tex.bmp";
     162  int textureID = 0;
     163 
     164  pBitmap[0] = SDL_LoadBMP (strFileName);
     165  if( pBitmap[0] == NULL)
     166    return;
     167 
     168  if(pBitmap[0] == NULL)                                // If we can't load the file, quit!
     169    {
     170      printf (" Failed loading %s\n", strFileName);
    171171      SDL_Quit ();
    172       return;
    173     }
    174  
    175   /* print some info about the obtained screen */
    176   printf("screen is %dx%d %dbpp\n", screen->w, screen->h, screen->format->BitsPerPixel);
    177 
    178   /* do the initial image display */
    179   SDL_BlitSurface (this->loadImage, 0, screen, 0);
    180  
    181   if (SDL_Flip (screen) != 0)
    182     printf("World::displayLoadScreen - couldn't filp buffers");
    183  
    184   //image = IMG_Load ("load_screen.png");
    185   printf ("World::displayLoadScreen - end\n");
     172    }
     173  glGenTextures(1, &textureArray[textureID]);
     174  /* Bind the texture to the texture arrays index and init the texture */
     175  glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);
     176 
     177  /* Rearrange the pixelData since openGL has a different pixel orientation */
     178  int width  = pBitmap[0]->w;
     179  int height = pBitmap[0]->h;
     180  unsigned char * data = (unsigned char *)(pBitmap[0]->pixels);
     181  unsigned char * newData = new unsigned char[width * height * 3];
     182  int channels = 3; /* RGB channel number*/
     183 
     184  int bytesPerPixel = pBitmap[0]->format->BytesPerPixel;
     185 
     186  /* this is the real swapping algorithm */
     187  for( int i = 0 ; i < (height / 2) ; ++i )
     188    for( int j = 0 ; j < width * bytesPerPixel; j += bytesPerPixel )
     189      for(int k = 0; k < bytesPerPixel; ++k)
     190        swap( data[ (i * width * bytesPerPixel) + j + k], data[ ( (height - i - 1) * width * bytesPerPixel ) + j + k]);
     191 
     192  // the following lines extract R,G and B values from any bitmap
     193 
     194  for(int i = 0; i < (width * height); ++i)
     195    {
     196      byte r,g,b;
     197      Uint32 pixel_value = 0;     
     198      /* the following loop extracts the pixel (however wide it is 8,16,24 or 32) and
     199         creates a long with all these bytes taken together.
     200      */
     201     
     202      for(int j = bytesPerPixel - 1 ; j >= 0; --j)
     203        {
     204          pixel_value = pixel_value << 8;
     205          pixel_value = pixel_value | data[ (i * bytesPerPixel) + j ];
     206        }                                                             
     207     
     208      SDL_GetRGB(pixel_value, pBitmap[0]->format, (Uint8 *)&r, (Uint8 *)&g, (Uint8 *)&b);
     209     
     210      newData[(i * channels) + 0] = r;
     211      newData[(i * channels) + 1] = g;
     212      newData[(i * channels) + 2] = b;
     213   
     214      pixel_value = 0;
     215    }
     216 
     217  /* Build Mipmaps (builds different versions of the picture for distances - looks better) */
     218  gluBuild2DMipmaps (GL_TEXTURE_2D, 3, pBitmap[0]->w, pBitmap[0]->h, GL_RGB, GL_UNSIGNED_BYTE, newData);
     219  //glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   
     220  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
     221
     222  delete [] newData;   
     223  SDL_FreeSurface(pBitmap[0]);
     224
     225
     226  /* ------------painten */
     227
     228  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     229  glLoadIdentity();
     230  gluLookAt(0, 0, 6,     0, 0, 0,     0, 1, 0);
     231
     232  // Bind the texture stored at the zero index of g_Texture[]
     233  //glBindTexture(GL_TEXTURE_2D, g_Texture[0]);
     234 
     235  // Display a quad texture to the screen
     236  glBegin(GL_QUADS);
     237 
     238  // glTexCoord2f() takes the X and Y offset (or U and V) into the bitmap.
     239  // Then, the next point sent to be rendered attaches that part of the bitmap
     240  // to itself.  The (U, V) coordinates range from (0, 0) being the top left corner
     241  // of the bitmap, to (1, 1) being the bottom left corner of the bitmap.
     242  // You can go above 1 but it just is wrapped around back to zero and repeats the texture.
     243  // Try setting the 1's to 2's and see what it does, then try setting them to 0.5's.
     244  // The higher the number, the more instances of the texture will appear on the square,
     245  // Where the lower the number, it stretches the incomplete texture over the surface of the square.
     246  // For every vertice we need a U V coordinate, as shown below.  You might have to play
     247  // around with the values to make it texture correctly, otherwise it will be flipped, upside down,
     248  // or skewed.  It also depends on where you are looking at it.  We are looking down the -Z axis.
     249 
     250  // Display the top left vertice
     251  glTexCoord2f(0.0f, 1.0f);
     252  glVertex3f(-2.5, 2.5, 0);
     253 
     254  // Display the bottom left vertice
     255  glTexCoord2f(0.0f, 0.0f);
     256  glVertex3f(-2.5, -2.5, 0);
     257 
     258  // Display the bottom right vertice
     259  glTexCoord2f(1.0f, 0.0f);
     260  glVertex3f(2.5, -2.5, 0);
     261 
     262  // Display the top right vertice
     263  glTexCoord2f(1.0f, 1.0f);
     264  glVertex3f(2.5, 2.5, 0);
     265
     266  glEnd();
     267 
     268  SDL_GL_SwapBuffers();                   
     269
     270  glDisable (GL_TEXTURE_2D);
     271  glDeleteTextures (1, &textureArray[textureID]);
     272  SDL_Delay (5000);
     273  printf ("World::displayLoadScreen - end\n");
    186274}
    187275
     
    191279  printf ("World::releaseLoadScreen - start\n");
    192280
    193   //if( SDL_Flip (Orxonox::getInstance()->getScreen ()) != 0)
    194   //  printf("World::displayLoadScreen - culdn't filp buffers");
    195 
    196   SDL_Delay (1000);
    197 
    198   SDL_FreeSurface (this->loadImage);
    199   SDL_FreeSurface (Orxonox::getInstance()->getScreen ());
    200 
    201   SDL_Flip (Orxonox::getInstance()->getScreen ());
    202 
    203   SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
    204   SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
    205   SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
    206   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    207 
    208   int bpp = 16;
    209   int width = 640;
    210   int height = 480;
    211   Uint32 flags = SDL_HWSURFACE | SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
    212  
    213   SDL_Surface* screen = SDL_SetVideoMode (width, height, bpp, flags);
    214 
    215   // OpenGL stuff
    216   glClearColor(0.0, 0.0, 0.0, 0.0);
    217   glEnable(GL_DEPTH_TEST);
    218  
    219   // LIGHTING
    220   GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0};
    221   GLfloat whiteLight[] = {1.0, 1.0, 1.0,1.0};
    222   GLfloat lightPosition[] = {10.0, 10, 19.0, 0.0};
    223 
    224   glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
    225   glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight);
    226   glEnable(GL_LIGHTING);
    227   glEnable(GL_LIGHT0);
    228   glEnable(GL_DEPTH_TEST);
    229   glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
    230   glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
    231 
    232   //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
    233 
    234   //SDL_Flip (screen);
    235281
    236282
     
    825871      this->display ();
    826872 
    827       for( int i = 0; i < 10000000; i++) {}
     873      for( int i = 0; i < 5000000; i++) {}
     874      /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/
    828875    }
    829876  printf("World::mainLoop() - Exiting the main loop\n");
     
    9751022}
    9761023
     1024
     1025
     1026
     1027void World::swap (unsigned char &a, unsigned char &b)
     1028{
     1029  unsigned char temp;
     1030  temp = a;
     1031  a    = b;
     1032  b    = temp;
     1033}
  • orxonox/branches/parenting/src/world.h

    r3336 r3338  
    9393  void display ();
    9494  void debug ();
     95
     96  void swap (unsigned char &a, unsigned char &b); /* \todo: this function doesn't belong here, this should be part of a image class*/
    9597};
    9698
Note: See TracChangeset for help on using the changeset viewer.