[Scummvm-cvs-logs] CVS: scummvm sdl_gl.cpp,1.7,1.8 fb2opengl.h,1.3,1.4
Max Horn
fingolfin at users.sourceforge.net
Thu Jul 25 15:28:03 CEST 2002
Update of /cvsroot/scummvm/scummvm
In directory usw-pr-cvs1:/tmp/cvs-serv24339
Modified Files:
sdl_gl.cpp fb2opengl.h
Log Message:
patch #586167: fixed support for systems that do not implement paletted textures
Index: sdl_gl.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sdl_gl.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- sdl_gl.cpp 25 Jul 2002 21:33:43 -0000 1.7
+++ sdl_gl.cpp 25 Jul 2002 22:27:25 -0000 1.8
@@ -34,12 +34,16 @@
#include <SDL_thread.h>
#ifdef WIN32
+int glColorTable(int, int, int, int, int, void *){ return 0; }
+int glGetColorTable(int, int, int, void *){ return 0; }
/* Use OpenGL 1.1 */
-#define OGL_1_1
+bool OGL_1_1=true;
+#else
+bool OGL_1_1=false;
#endif
#include "fb2opengl.h"
-
+FB2GL fb2gl;
class OSystem_SDL : public OSystem {
public:
@@ -238,7 +242,7 @@
uint i;
for(i=0;i!=num;i++) {
- fb2gl_palette(i+start,b[0],b[1],b[2]);
+ fb2gl.palette(i+start,b[0],b[1],b[2]);
b += 4;
}
@@ -271,11 +275,16 @@
if (_full_screen) gl_flags |= (FB2GL_FS);
- #ifdef OGL_1_1
- gl_flags |= (FB2GL_RGBA | FB2GL_EXPAND);
- #endif
-
- fb2gl_init(640,480,0,70,gl_flags);
+ if (OGL_1_1) { // OpenGL 1.1
+ gl_flags |= (FB2GL_RGBA | FB2GL_EXPAND);
+ fb2gl.init(640,480,0,70,gl_flags );
+ }
+ else { // OpenGL 1.2
+ if (!fb2gl.init(640,480,0,70,gl_flags)) { // Try to use 8bpp textures
+ gl_flags |= (FB2GL_RGBA | FB2GL_EXPAND); // using RGBA textures
+ fb2gl.init(640,480,0,70,gl_flags);
+ }
+ }
SDL_SetGamma(1.25,1.25,1.25);
@@ -480,13 +489,13 @@
* and we want to avoid any ugly effects.
*/
if (_palette_changed_last != 0) {
- fb2gl_set_palette(_palette_changed_first,
+ fb2gl.setPalette(_palette_changed_first,
_palette_changed_last - _palette_changed_first);
_palette_changed_last = 0;
}
- fb2gl_update(sdl_tmpscreen->pixels,320,200,320,0,_current_shake_pos);
+ fb2gl.update(sdl_tmpscreen->pixels,320,200,320,0,_current_shake_pos);
}
@@ -688,8 +697,8 @@
unload_gfx_mode();
load_gfx_mode();
- fb2gl_set_palette(0,256);
- fb2gl_update(sdl_tmpscreen->pixels,320,200,320,0,_current_shake_pos);
+ fb2gl.setPalette(0,256);
+ fb2gl.update(sdl_tmpscreen->pixels,320,200,320,0,_current_shake_pos);
/* blit image */
OSystem_SDL::copy_rect(bak_mem, SCREEN_WIDTH, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
@@ -703,7 +712,7 @@
case PROP_TOGGLE_FULLSCREEN:
_full_screen ^= true;
- SDL_WM_ToggleFullScreen(screen);
+ SDL_WM_ToggleFullScreen(fb2gl.screen);
return 1;
case PROP_GET_FULLSCREEN:
Index: fb2opengl.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/fb2opengl.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- fb2opengl.h 4 Jul 2002 10:17:56 -0000 1.3
+++ fb2opengl.h 25 Jul 2002 22:27:25 -0000 1.4
@@ -18,58 +18,61 @@
*
*/
-/* FrameBuffer renderer in an OpenGL texture
- Andre Souza <asouza at olinux.com.br> */
+// FrameBuffer renderer in an OpenGL texture
+// Andre Souza <asouza at olinux.com.br>
#include <SDL.h>
#include <SDL_opengl.h>
#include <stdlib.h>
#include <string.h>
-/* FLAGS */
-#define FB2GL_FS 1 /* FULLSCREEN */
-#define FB2GL_RGBA 2 /* Use RGBA (else use palette) */
-#define FB2GL_320 4 /* 320x256 texture (else use 256x256) */
-#define FB2GL_AUDIO 8 /* Activate SDL Audio */
-#define FB2GL_PITCH 16 /* On fb2l_update, use pitch (else bytes per pixel) */
-#define FB2GL_EXPAND 32 /* Create a RGB fb with the color lookup table*/
+// FLAGS
+#define FB2GL_FS 1 // FULLSCREEN
+#define FB2GL_RGBA 2 // Use RGBA (else use palette)
+#define FB2GL_320 4 // 320x256 texture (else use 256x256)
+#define FB2GL_AUDIO 8 // Activate SDL Audio
+#define FB2GL_PITCH 16 // On fb2l_update, use pitch (else bytes per pixel)
+#define FB2GL_EXPAND 32 // Create a RGB fb with the color lookup table
-/* Framebuffer for 8 bpp */
-unsigned char ogl_fb[256][256];
-unsigned char ogl_fbb[256][64];
-/* Framebuffer for RGBA */
-unsigned char ogl_fb1[256][256][4];
-unsigned char ogl_fb2[256][64][4];
-/* Texture(s) */
-GLuint texture;
-GLuint textureb;
-/* Display list */
-GLuint dlist;
-/* Color Table (256 colors, RGB) */
-char ogl_ctable[256][3];
-char ogl_temp_ctable[256][3]; /* Support for OpenGL 1.1 */
-/* Use RGBA? */
-char fb2gl_RGBA=0;
-/* If so, expand the 8 bit fb to RGB? */
-char fb2gl_expand=0;
-/* 320x256? */
-char fb2gl_t320=0;
-/* Use pitch? Else, bytes per pixel */
-char use_pitch=0;
-/* Methods */
-void fb2gl_maketex();
-void fb2gl_makedlist(int xf, int yf);
-void fb2gl_display();
+// This extension isn't defined in OpenGL 1.1
+#ifndef GL_EXT_paletted_texture
+#define GL_EXT_paletted_texture 1
+#endif
-/* Public */
-SDL_Surface *screen;
-void fb2gl_init(int width, int height, int xfix, int yfix, char flags);
-void fb2gl_update(void *fb, int width, int height, int pitch, int xskip, int yskip);
-void fb2gl_palette(int index, int r, int g, int b);
-void fb2gl_set_palette(int first, int ncolors);
+class FB2GL {
+ private:
+ // Framebuffer for 8 bpp
+ unsigned char ogl_fb[256][256];
+ unsigned char ogl_fbb[256][64];
+ // Framebuffer for RGBA */
+ unsigned char ogl_fb1[256][256][4];
+ unsigned char ogl_fb2[256][64][4];
+ // Texture(s)
+ GLuint texture;
+ GLuint textureb;
+ // Display list
+ GLuint dlist;
+ // Color Table (256 colors, RGB)
+ char ogl_ctable[256][3];
+ char ogl_temp_ctable[256][3]; // Support for OpenGL 1.1
+ char flags;
+ void maketex();
+ void makedlist(int xf, int yf);
+ void display();
+ public:
+ SDL_Surface *screen;
+ FB2GL() {
+ flags=0;
+ screen=NULL;
+ }
+ int init(int width, int height, int xfix, int yfix, char _flags);
+ void update(void *fb, int width, int height, int pitch, int xskip, int yskip);
+ void palette(int index, int r, int g, int b);
+ void setPalette(int first, int ncolors);
+};
-void fb2gl_maketex()
+void FB2GL::maketex()
{
glGenTextures(0,&texture);
glBindTexture(GL_TEXTURE_2D,texture);
@@ -77,33 +80,37 @@
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ // Bilinear filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
/*
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
*/
- if (fb2gl_RGBA) {
+
+ if (flags & FB2GL_RGBA) {
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,256,256,0,GL_RGBA, GL_UNSIGNED_BYTE, ogl_fb1);
}
else {
glTexImage2D(GL_TEXTURE_2D,0,GL_COLOR_INDEX,256,256,0,GL_COLOR_INDEX, GL_UNSIGNED_BYTE, ogl_fb);
}
- if (fb2gl_t320) {
+ if (flags & FB2GL_320) {
glGenTextures(1,&textureb);
glBindTexture(GL_TEXTURE_2D,textureb);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ // Bilinear filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
/*
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
*/
- if (fb2gl_RGBA) {
+
+ if (flags & FB2GL_RGBA) {
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,64,256,0,GL_RGBA,
GL_UNSIGNED_BYTE, ogl_fb2);
}
@@ -115,12 +122,13 @@
}
-void fb2gl_makedlist(int xf, int yf)
+void FB2GL::makedlist(int xf, int yf)
{
- double xfix=(double)xf/128; /* 128 = 256/2 (half texture => 0.0 to 1.0) */
+ double xfix=(double)xf/128; // 128 = 256/2 (half texture => 0.0 to 1.0)
double yfix=(double)yf/128;
- double texend = (double)615/1024; /* End of 256x256 (from -1.0 to 1.0) */
-
+ // End of 256x256 (from -1.0 to 1.0)
+ double texend = (double)96/160; // 160=320/2 (== 0.0), 256-160=96.
+
dlist=glGenLists(1);
glNewList(dlist,GL_COMPILE);
@@ -128,32 +136,32 @@
glBindTexture(GL_TEXTURE_2D, texture);
- if (!fb2gl_t320) { /* Normal 256x256 */
+ if (!(flags & FB2GL_320)) { // Normal 256x256
glBegin(GL_QUADS);
- glTexCoord2f(0.0,1.0); glVertex2f(-1.0,-1.0-yfix); /* upper left */
- glTexCoord2f(0.0,0.0); glVertex2f(-1.0,1.0); /* lower left */
- glTexCoord2f(1.0,0.0); glVertex2f(1.0+xfix,1.0); /* lower right */
- glTexCoord2f(1.0,1.0); glVertex2f(1.0+xfix,-1.0-yfix); /* upper right */
+ glTexCoord2f(0.0,1.0); glVertex2f(-1.0,-1.0-yfix); // upper left
+ glTexCoord2f(0.0,0.0); glVertex2f(-1.0,1.0); // lower left
+ glTexCoord2f(1.0,0.0); glVertex2f(1.0+xfix,1.0); // lower right
+ glTexCoord2f(1.0,1.0); glVertex2f(1.0+xfix,-1.0-yfix); // upper right
glEnd();
}
- else { /* 320x256 */
+ else { // 320x256
- /* First, the 256x256 texture */
+ // First, the 256x256 texture
glBegin(GL_QUADS);
- glTexCoord2f(0.0,1.0); glVertex2f(-1.0,-1.0-yfix); /* upper left */
- glTexCoord2f(0.0,0.0); glVertex2f(-1.0,1.0); /* lower left */
- glTexCoord2f(1.0,0.0); glVertex2f(texend+xfix,1.0); /* lower right */
- glTexCoord2f(1.0,1.0); glVertex2f(texend+xfix,-1.0-yfix); /* upper right*/
+ glTexCoord2f(0.0,1.0); glVertex2f(-1.0,-1.0-yfix); // upper left
+ glTexCoord2f(0.0,0.0); glVertex2f(-1.0,1.0); // lower left
+ glTexCoord2f(1.0,0.0); glVertex2f(texend+xfix,1.0); // lower right
+ glTexCoord2f(1.0,1.0); glVertex2f(texend+xfix,-1.0-yfix); // upper right
glEnd();
- /* 64x256 */
+ // 64x256
glBindTexture(GL_TEXTURE_2D, textureb);
glBegin(GL_QUADS);
- glTexCoord2f(0.0,1.0); glVertex2f(texend+xfix,-1.0-yfix); /* upper left */
- glTexCoord2f(0.0,0.0); glVertex2f(texend+xfix,1.0); /* lower left */
- glTexCoord2f(1.0,0.0); glVertex2f(1.0+xfix,1.0); /* lower right */
- glTexCoord2f(1.0,1.0); glVertex2f(1.0+xfix,-1.0-yfix); /* upper right */
+ glTexCoord2f(0.0,1.0); glVertex2f(texend+xfix,-1.0-yfix); // upper left
+ glTexCoord2f(0.0,0.0); glVertex2f(texend+xfix,1.0); // lower left
+ glTexCoord2f(1.0,0.0); glVertex2f(1.0+xfix,1.0); // lower right
+ glTexCoord2f(1.0,1.0); glVertex2f(1.0+xfix,-1.0-yfix); // upper right
glEnd();
}
@@ -162,77 +170,65 @@
glEndList();
}
-void fb2gl_init(int width, int height, int xfix, int yfix, char flags)
+int FB2GL::init(int width, int height, int xfix, int yfix, char _flags)
{
- char fs=0;
- char audio=0;
char gl_ext[4096];
+ gl_ext[0]='\0';
- /* Test the flags */
- if (flags & FB2GL_FS) fs=1; else fs=0;
- if (flags & FB2GL_RGBA) fb2gl_RGBA=1; else fb2gl_RGBA=0;
- if (flags & FB2GL_320) fb2gl_t320=1; else fb2gl_t320=0;
- if (flags & FB2GL_AUDIO) audio=1; else audio=0;
- if (flags & FB2GL_PITCH) use_pitch=1; else use_pitch=0;
- if (flags & FB2GL_EXPAND) fb2gl_expand=1; else fb2gl_expand=0;
-/*
- if (audio) SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
- else SDL_Init(SDL_INIT_VIDEO);
-
- atexit(SDL_Quit);
-*/
-
-
- if (fs) {
+ flags = _flags;
+
+ // Fullscreen?
+ if ((flags & FB2GL_FS) && !screen) {
screen = SDL_SetVideoMode(width, height, 0, SDL_HWSURFACE | SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_FULLSCREEN);
}
- else {
+ else if (!screen) {
screen = SDL_SetVideoMode(width, height, 0, SDL_HWPALETTE | SDL_HWSURFACE | SDL_OPENGL | SDL_GL_DOUBLEBUFFER);
}
if (!screen) {
fprintf(stderr, "Couldn't start video res %dx%d\n", width, height);
+ return 0;
}
-#ifndef OGL_1_1
- if (!fb2gl_RGBA) {
- /* Paletted Texture Extension */
+
+ if (!(flags & FB2GL_RGBA)) { // Check for Paletted Texture Extension
+
strcpy(gl_ext, (char *)glGetString(GL_EXTENSIONS));
-
+ fprintf(stderr,"gl_ext= %s\n",gl_ext);
+
if ( strstr( gl_ext , "GL_EXT_paletted_texture") )
glEnable(GL_EXT_paletted_texture);
else {
fprintf(stderr,"Your OpenGL version doesn't support paletted texture\n");
- exit(0);
+ return 0;
}
}
-#endif
-
- fb2gl_maketex();
- fb2gl_makedlist(xfix, yfix);
+
+ maketex();
+ makedlist(xfix, yfix);
+ return 1;
}
-void fb2gl_display()
+void FB2GL::display()
{
glCallList(dlist);
SDL_GL_SwapBuffers();
}
-/* Changed the way xskip and yskip work for use with scummvm (shaking) */
-void fb2gl_update(void *fb, int w, int h, int pitch, int xskip, int yskip) {
+void FB2GL::update(void *fb, int w, int h, int pitch, int xskip, int yskip) {
unsigned char *fb1=(unsigned char *)fb;
int x,y,scr_pitch,byte=0;
- if (use_pitch) scr_pitch=pitch;
+ if (flags & FB2GL_PITCH) scr_pitch=pitch;
else {
scr_pitch=w*pitch;
- byte = pitch; /* Bytes perl pixel (for RGBA mode) */
+ byte = pitch; // Bytes perl pixel (for RGBA mode)
}
- if (fb2gl_RGBA) {
+ if (flags & FB2GL_RGBA) {
- if (fb2gl_expand) { /* Expand the 8 bit fb into a RGB fb */
+ if (flags & FB2GL_EXPAND) { // Expand the 8 bit fb into a RGB fb
for (y=yskip; y<h; y++) {
for (x=xskip; x<w; x++) {
@@ -240,46 +236,42 @@
ogl_fb1[y][x][0] = ogl_ctable[*(fb1+x)][0];
ogl_fb1[y][x][1] = ogl_ctable[*(fb1+x)][1];
ogl_fb1[y][x][2] = ogl_ctable[*(fb1+x)][2];
- /* ogl_fb1[y-yskip][x-xskip][3]=255; */
}
else {
ogl_fb2[y][x-256][0] = ogl_ctable[*(fb1+x)][0];
ogl_fb2[y][x-256][1] = ogl_ctable[*(fb1+x)][1];
ogl_fb2[y][x-256][2] = ogl_ctable[*(fb1+x)][2];
- /* ogl_fb2[y-yskip][x-256][3]=255; */
}
}
fb1 += scr_pitch;
}
}
- else { /* No expansion */
+ else { // No expansion
for (y=yskip; y<h; y++) {
for (x=xskip; x<w; x++) {
if (x<256) {
ogl_fb1[y-yskip][x-xskip][0] = *(fb1+(x*byte));
ogl_fb1[y-yskip][x-xskip][1] = *(fb1+(x*byte)+1);
ogl_fb1[y-yskip][x-xskip][2] = *(fb1+(x*byte)+2);
- /* ogl_fb1[y-yskip][x-xskip][3]=255; */
}
else {
ogl_fb2[y-yskip][x-256][0] = *(fb1+(x*byte));
ogl_fb2[y-yskip][x-256][1] = *(fb1+(x*byte)+1);
ogl_fb2[y-yskip][x-256][2] = *(fb1+(x*byte)+2);
- /* ogl_fb2[y-yskip][x-256][3]=255; */
}
}
fb1 += scr_pitch;
}
}
- /* Update 256x256 texture */
+ // Update 256x256 texture
glBindTexture(GL_TEXTURE_2D,texture);
glFlush();
glTexSubImage2D(GL_TEXTURE_2D,0,xskip,yskip,256-xskip,256-yskip,GL_RGBA,
GL_UNSIGNED_BYTE,ogl_fb1);
- if (fb2gl_t320) {
- /* Update 64x256 texture */
+ if (flags & FB2GL_320) {
+ // Update 64x256 texture
glBindTexture(GL_TEXTURE_2D,textureb);
glFlush();
glTexSubImage2D(GL_TEXTURE_2D,0,xskip,yskip,64-xskip,256-yskip,GL_RGBA,
@@ -287,7 +279,7 @@
}
}
- else { /* non RGBA */
+ else { // non RGBA (paletted)
for (y=0; y<h; y++)
for (x=0; x<w; x++) {
@@ -299,13 +291,13 @@
}
}
- /* Update 256x256 texture */
+ // Update 256x256 texture
glBindTexture(GL_TEXTURE_2D,texture);
glTexSubImage2D(GL_TEXTURE_2D,0,xskip,yskip,256-xskip,256-yskip,
GL_COLOR_INDEX, GL_UNSIGNED_BYTE,ogl_fb);
- if (fb2gl_t320) {
- /* Update 64x256 texture */
+ if (flags & FB2GL_320) {
+ // Update 64x256 texture
glBindTexture(GL_TEXTURE_2D,textureb);
glTexSubImage2D(GL_TEXTURE_2D,0,xskip,yskip,64-xskip,256-yskip,
GL_COLOR_INDEX, GL_UNSIGNED_BYTE,ogl_fbb);
@@ -313,37 +305,35 @@
}
- fb2gl_display();
+ display();
}
-void fb2gl_palette(int i, int r, int g, int b) {
-#ifdef OGL_1_1
- ogl_temp_ctable[i][0]=r;
- ogl_temp_ctable[i][1]=g;
- ogl_temp_ctable[i][2]=b;
-#else
- ogl_ctable[i][0]=r;
- ogl_ctable[i][1]=g;
- ogl_ctable[i][2]=b;
-#endif
+void FB2GL::palette(int i, int r, int g, int b) {
+ if (flags & FB2GL_EXPAND) {
+ ogl_temp_ctable[i][0]=r;
+ ogl_temp_ctable[i][1]=g;
+ ogl_temp_ctable[i][2]=b;
+ }
+ else { // Paletted texture
+ ogl_ctable[i][0]=r;
+ ogl_ctable[i][1]=g;
+ ogl_ctable[i][2]=b;
+ }
}
-void fb2gl_set_palette(int f, int n) {
+void FB2GL::setPalette(int f, int n) {
char temp[256][3];
int i;
-#ifdef OGL_1_1
- /* No ColorTable Extension. Expand option MUST be set. */
- for (i=f; i<n; i++) {
- ogl_ctable[i][0] = ogl_temp_ctable[i][0];
- ogl_ctable[i][1] = ogl_temp_ctable[i][1];
- ogl_ctable[i][2] = ogl_temp_ctable[i][2];
+ if (flags & FB2GL_EXPAND) {
+ for (i=f; i<n; i++) {
+ ogl_ctable[i][0] = ogl_temp_ctable[i][0];
+ ogl_ctable[i][1] = ogl_temp_ctable[i][1];
+ ogl_ctable[i][2] = ogl_temp_ctable[i][2];
+ }
}
-#else
- if (!fb2gl_expand)
- {
-
+ else { // Paletted texture
glBindTexture(GL_TEXTURE_2D,texture);
glGetColorTable(GL_TEXTURE_2D,GL_RGB,GL_UNSIGNED_BYTE,&temp);
@@ -355,11 +345,11 @@
glColorTable(GL_TEXTURE_2D,GL_RGB,256,GL_RGB,GL_UNSIGNED_BYTE,&temp);
- if (fb2gl_t320) {
+ if (flags & FB2GL_320) {
glBindTexture(GL_TEXTURE_2D,textureb);
glColorTable(GL_TEXTURE_2D,GL_RGB,256,GL_RGB,GL_UNSIGNED_BYTE,&temp);
}
}
-#endif
+
}
More information about the Scummvm-git-logs
mailing list