Beispiel #1
0
/**
 * @brief Gets some information about the OpenGL window.
 *
 *    @return 0 on success.
 */
static int gl_getGLInfo (void)
{
   int doublebuf;

   SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &gl_screen.r );
   SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &gl_screen.g );
   SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &gl_screen.b );
   SDL_GL_GetAttribute( SDL_GL_ALPHA_SIZE, &gl_screen.a );
   SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &doublebuf );
   SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &gl_screen.fsaa );
   if (doublebuf)
      gl_screen.flags |= OPENGL_DOUBLEBUF;
   /* Calculate real depth. */
   gl_screen.depth = gl_screen.r + gl_screen.g + gl_screen.b + gl_screen.a;

   /* Texture information */
   glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_screen.tex_max);
   glGetIntegerv(GL_MAX_TEXTURE_UNITS, &gl_screen.multitex_max);

   /* Debug happiness */
   DEBUG("OpenGL Window Created: %dx%d@%dbpp %s", SCREEN_W, SCREEN_H, gl_screen.depth,
         gl_has(OPENGL_FULLSCREEN)?"fullscreen":"window");
   DEBUG("r: %d, g: %d, b: %d, a: %d, db: %s, fsaa: %d, tex: %d",
         gl_screen.r, gl_screen.g, gl_screen.b, gl_screen.a,
         gl_has(OPENGL_DOUBLEBUF) ? "yes" : "no",
         gl_screen.fsaa, gl_screen.tex_max);
   DEBUG("vsync: %s, vbo: %s, mm: %s, compress: %s, npot: %s",
         gl_has(OPENGL_VSYNC) ? "yes" : "no",
         gl_vboIsHW() ? "yes" : "no",
         gl_texHasMipmaps() ? "yes" : "no",
         gl_texHasCompress() ? "yes" : "no",
         gl_needPOT() ? "no" : "yes" );
   DEBUG("Renderer: %s", glGetString(GL_RENDERER));
   DEBUG("Version: %s", glGetString(GL_VERSION));

   /* Now check for things that can be bad. */
   if (gl_screen.multitex_max < OPENGL_REQ_MULTITEX)
      WARN("Missing texture units (%d required, %d found)",
            OPENGL_REQ_MULTITEX, gl_screen.multitex_max );
   if ((conf.fsaa > 1) && (gl_screen.fsaa != conf.fsaa))
      WARN("Unable to get requested FSAA level (%d requested, got %d)",
            conf.fsaa, gl_screen.fsaa );

   return 0;
}
Beispiel #2
0
/**
 * @brief Small wrapper that handles recursivity limits.
 *
 *    @param iter Iteration of recursivity.
 *    @return 0 on success.
 */
static int nebu_init_recursive( int iter )
{
   int i;
   char nebu_file[PATH_MAX];
   SDL_Surface* nebu_sur;
   int ret;

   /* Avoid too much recursivity. */
   if (iter > 3) {
      WARN("Unable to generate nebula after 3 attempts, something has really gone wrong!");
      return -1;
   }

   /* Special code to regenerate the nebula */
   if ((nebu_w == -9) && (nebu_h == -9))
      nebu_generate();

   /* Set expected sizes */
   nebu_w  = SCREEN_W;
   nebu_h  = SCREEN_H;
   if (gl_needPOT()) {
      nebu_pw = gl_pot(nebu_w);
      nebu_ph = gl_pot(nebu_h);
   }
   else {
      nebu_pw = nebu_w;
      nebu_ph = nebu_h;
   }

   /* Load each, checking for compatibility and padding */
   glGenTextures( NEBULA_Z, nebu_textures );
   for (i=0; i<NEBULA_Z; i++) {
      nsnprintf( nebu_file, PATH_MAX, NEBULA_PATH_BG, nebu_w, nebu_h, i );

      /* Check compatibility. */
      if (nebu_checkCompat( nebu_file ))
         goto no_nebula;

      /* Try to load. */
      nebu_sur = loadNebula( nebu_file );
      if (nebu_sur == NULL)
         goto no_nebula;
      if ((nebu_sur->w != nebu_w) || (nebu_sur->h != nebu_h))
         WARN("Nebula raw size doesn't match expected! (%dx%d instead of %dx%d)",
               nebu_sur->w, nebu_sur->h, nebu_w, nebu_h );

      /* Load the texture */
      ret = nebu_loadTexture( nebu_sur, nebu_pw, nebu_ph, nebu_textures[i] );
      if (ret)
         goto no_nebula;
   }

   /* Generate puffs after the recursivity stuff. */
   nebu_generatePuffs();

   /* Display loaded nebulas. */
   DEBUG("Loaded %d Nebula Layers", NEBULA_Z);

   nebu_vbo_init();
   nebu_loaded = 1;

   return 0;
no_nebula:
   LOG("No nebula found, generating (this may take a while).");

   /* So we generate and reload */
   ret = nebu_generate();
   if (ret != 0) /* An error has happened - break recursivity*/
      return ret;

   return nebu_init_recursive( iter+1 );
}
Beispiel #3
0
/**
 * @brief Prepares the surface to be loaded as a texture.
 *
 *    @param surface to load that is freed in the process.
 *    @return New surface that is prepared for texture loading.
 */
SDL_Surface* gl_prepareSurface( SDL_Surface* surface )
{
   SDL_Surface* temp;
   int potw, poth;
   SDL_Rect rtemp;
#if ! SDL_VERSION_ATLEAST(1,3,0)
   Uint32 saved_flags;
#endif /* ! SDL_VERSION_ATLEAST(1,3,0) */

   /* Make size power of two. */
   potw = gl_pot(surface->w);
   poth = gl_pot(surface->h);
   if (gl_needPOT() && ((potw != surface->w) || (poth != surface->h))) {

      /* we must blit with an SDL_Rect */
      rtemp.x = rtemp.y = 0;
      rtemp.w = surface->w;
      rtemp.h = surface->h;

      /* saves alpha */
#if SDL_VERSION_ATLEAST(1,3,0)
      SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);

      /* create the temp POT surface */
      temp = SDL_CreateRGBSurface( 0, potw, poth,
            surface->format->BytesPerPixel*8, RGBAMASK );
#else /* SDL_VERSION_ATLEAST(1,3,0) */
      saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
      if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
         SDL_SetAlpha( surface, 0, SDL_ALPHA_OPAQUE );
         SDL_SetColorKey( surface, 0, surface->format->colorkey );
      }

      /* create the temp POT surface */
      temp = SDL_CreateRGBSurface( SDL_SRCCOLORKEY,
            potw, poth, surface->format->BytesPerPixel*8, RGBAMASK );
#endif /* SDL_VERSION_ATLEAST(1,3,0) */

      if (temp == NULL) {
         WARN("Unable to create POT surface: %s", SDL_GetError());
         return 0;
      }
      if (SDL_FillRect( temp, NULL,
               SDL_MapRGBA(surface->format,0,0,0,SDL_ALPHA_TRANSPARENT))) {
         WARN("Unable to fill rect: %s", SDL_GetError());
         return 0;
      }

      /* change the surface to the new blitted one */
      SDL_BlitSurface( surface, &rtemp, temp, &rtemp);
      SDL_FreeSurface( surface );
      surface = temp;

#if ! SDL_VERSION_ATLEAST(1,3,0)
      /* set saved alpha */
      if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
         SDL_SetAlpha( surface, 0, 0 );
#endif /* ! SDL_VERSION_ATLEAST(1,3,0) */
   }

   return surface;
}