Got rid of the TEXTURE_RECTANGLE NVIDIA extension for the OpenGl mode.
[supertux.git] / src / screen.c
index 5f0be62..bbd2c60 100644 (file)
 #include <SDL.h>
 #include <SDL_image.h>
 
-#ifndef NOSOUND
-#include <SDL_mixer.h>
-#endif
-
 #ifdef LINUX
 #include <pwd.h>
 #include <sys/types.h>
@@ -32,7 +28,7 @@
 #include "globals.h"
 #include "screen.h"
 #include "setup.h"
-
+#include "type.h"
 
 /* --- LOAD AND DISPLAY AN IMAGE --- */
 
@@ -48,9 +44,48 @@ void load_and_display_image(char * file)
 
 /* --- CLEAR SCREEN --- */
 
-void clearscreen(int r, int g, int b)
+void clearscreen(float r, float g, float b)
 {
+#ifndef NOOPENGL
+  if(use_gl)
+  {
+  glClearColor(r/256, g/256, b/256, 1.0);
+  glClear(GL_COLOR_BUFFER_BIT);
+  }
+  else
+#endif
   SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
+}
+
+/* --- FILL A RECT --- */
+
+void fillrect(float x, float y, float w, float h, float r, float g, float b)
+{
+#ifndef NOOPENGL
+if(use_gl)
+       {
+       glBegin(GL_QUADS);
+               glColor3ub(r, g, b);
+               glVertex2i(x, y);
+               glVertex2i(x+w, y);
+               glVertex2i(x+w, y+h);
+               glVertex2i(x, y+h);
+       glEnd();
+       }
+else
+       {
+#endif
+       SDL_Rect rect;
+       rect.x = x;
+       rect.y = y;
+       rect.w = w;
+       rect.h = h;
+
+       SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, r, g, b));
+#ifndef NOOPENGL
+       }
+#endif
 }
 
 
@@ -58,25 +93,42 @@ void clearscreen(int r, int g, int b)
 
 void updatescreen(void)
 {
-  SDL_UpdateRect(screen, 0, 0, 640, 480);
+  if(use_gl)  /*clearscreen(0,0,0);*/
+  SDL_GL_SwapBuffers();
+  else
+    SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
 }
 
+void flipscreen(void)
+{
+if(use_gl)
+SDL_GL_SwapBuffers();
+else
+SDL_Flip(screen);
+}
 
 /* --- LOAD AN IMAGE --- */
 
 SDL_Surface * load_image(char * file, int use_alpha)
 {
+/*
+if(!faccessible(file))
+{
+if(!faccessible(st_dir,
+*/
+
   SDL_Surface * temp, * surf;
   
   temp = IMG_Load(file);
+
   if (temp == NULL)
     st_abort("Can't load", file);
-  
+    
   surf = SDL_DisplayFormatAlpha(temp);
 
   if (surf == NULL)
     st_abort("Can't covert to display format", file);
-
+    
   if (use_alpha == IGNORE_ALPHA)
     SDL_SetAlpha(surf, 0, 0);
   
@@ -85,179 +137,38 @@ SDL_Surface * load_image(char * file, int use_alpha)
   return(surf);
 }
 
-
-/* --- DRAW AN IMAGE ONTO THE SCREEN --- */
-
-void drawimage(SDL_Surface * surf, int x, int y, int update)
-{
-  SDL_Rect dest;
-  
-  dest.x = x;
-  dest.y = y;
-  dest.w = surf->w;
-  dest.h = surf->h;
-  
-  SDL_BlitSurface(surf, NULL, screen, &dest);
-  
-  if (update == UPDATE)
-    SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
-}
-
-
-/* --- DRAW PART OF AN IMAGE ONTO THE SCREEN --- */
-
-void drawpart(SDL_Surface * surf, int x, int y, int w, int h, int update)
-{
-  SDL_Rect src, dest;
-  
-  src.x = x;
-  src.y = y;
-  src.w = w;
-  src.h = h;
-
-  dest.x = x;
-  dest.y = y;
-  dest.w = w;
-  dest.h = h;
-  
-  SDL_BlitSurface(surf, &src, screen, &dest);
-  
-  if (update == UPDATE)
-    SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
-}
-
-
-/* --- DRAW TEXT ONTO THE SCREEN --- */
-
-void drawtext(char * text, int x, int y, SDL_Surface * surf, int update)
-{
-  int i;
-  char c;
-  SDL_Rect src, dest;
-  
-  
-  /* For each letter in the string... */
-  
-  for (i = 0; i < strlen(text); i++)
-    {
-      /* Set source rectangle: */
-      
-      c = text[i];
-      
-      if (c >= 'A' && c <= 'Z')
-       {
-         /* Capital letter - first row: */
-         
-         src.x = (c - 'A') * 16;
-         src.y = 0;
-       }
-      else if (c >= 'a' && c <= 'z')
-       {
-         /* Lowercase letter - first row: */
-         
-         src.x = (c - 'a') * 16;
-         src.y = 16;
-       }
-      else if (c >= '!' && c <= '9')
-       {
-         /* Punctuation (except '?') or number - third row: */
-         
-         src.x = (c - '!') * 16;
-         src.y = 32;
-       }
-      else if (c == '?')
-       {
-         /* Question mark - third row, last character: */
-         
-         src.x = 400;
-         src.y = 24;
-       }
-      else
-       src.x = -1;
-      
-      src.w = 16;
-      src.h = 16;
-      
-
-      /* Draw character: */
-      
-      if (src.x != -1)
-       {
-         /* Set destination rectangle for shadow: */
-         
-         dest.x = x + (i * 16) + 1;
-         dest.y = y + 1;
-         dest.w = src.w;
-         dest.h = src.h;
-         
-         
-         /* Shadow: */
-         
-         SDL_BlitSurface(letters_black, &src, screen, &dest);
-         
-         
-         /* Set destination rectangle for text: */
-         
-         dest.x = x + (i * 16);
-         dest.y = y;
-         dest.w = src.w;
-         dest.h = src.h;
-         
-         
-         /* Shadow: */
-         
-         SDL_BlitSurface(surf, &src, screen, &dest);
-       }
-    }
-  
-  
-  /* Update */
-  
-  if (update == UPDATE)
-    {
-      dest.w = strlen(text) * 16 + 1;
-      
-      if (dest.w > 640)
-       dest.w = 640;
-      
-      SDL_UpdateRect(screen, x, y, dest.w, 17);
-    }
-}
-
-
-/* --- DRAW HORIZONTALLY-CENTERED TEXT: --- */
-
-void drawcenteredtext(char * text, int y, SDL_Surface * surf, int update)
+void update_rect(SDL_Surface *scr, Sint32 x, Sint32 y, Sint32 w, Sint32 h)
 {
-  drawtext(text, 320 - (strlen(text) * 8), y, surf, update);
+if(!use_gl)
+SDL_UpdateRect(scr, x, y, w, h);
 }
 
 
 /* --- ERASE TEXT: --- */
 
-void erasetext(char * text, int x, int y, SDL_Surface * surf, int update)
+void erasetext(char * text, int x, int y, texture_type * ptexture, int update, int shadowsize)
 {
   SDL_Rect dest;
   
   
   dest.x = x;
   dest.y = y;
-  dest.w = strlen(text) * 16 + 1;
+  dest.w = strlen(text) * 16 + shadowsize;
   dest.h = 17;
   
-  if (dest.w > 640)
-    dest.w = 640;
+  if (dest.w > screen->w)
+    dest.w = screen->w;
   
-  SDL_BlitSurface(surf, &dest, screen, &dest);
+  texture_draw_part(ptexture,dest.x,dest.y,dest.x,dest.y,dest.w,dest.h,update);
   
   if (update == UPDATE)
-    SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
+    update_rect(screen, dest.x, dest.y, dest.w, dest.h);
 }
 
 
 /* --- ERASE CENTERED TEXT: --- */
 
-void erasecenteredtext(char * text, int y, SDL_Surface * surf, int update)
+void erasecenteredtext(char * text, int y, texture_type * ptexture, int update, int shadowsize)
 {
-  erasetext(text, 320 - (strlen(text) * 8), y, surf, update);
+  erasetext(text, screen->w / 2 - (strlen(text) * 8), y, ptexture, update, shadowsize);
 }