Ticket #8196: fb2opengl.h.patch

File fb2opengl.h.patch, 14.7 KB (added by SF/luke_br, 18 years ago)

More human readable fb2opengl.h

Line 
122c22
2< // Andre Souza <asouza@olinux.com.br>
3---
4> // Andre Souza <asouza_luke@yahoo.com.br>
545a46
6> SDL_Surface *screen;
747,48c48,49
8< unsigned char ogl_fb[256][256];
9< unsigned char ogl_fbb[256][64];
10---
11> unsigned char palettedFrameBuffer1[256][256];
12> unsigned char palettedFrameBuffer2[256][64];
1350,51c51,52
14< unsigned char ogl_fb1[256][256][4];
15< unsigned char ogl_fb2[256][64][4];
16---
17> unsigned char RGBAFrameBuffer1[256][256][4];
18> unsigned char RGBAFrameBuffer2[256][64][4];
1953,54c54,55
20< unsigned char fb1[256 * 256 * 4]; // Enough room for RGBA
21< unsigned char fb2[64 * 256 * 4]; // Enough room for RGBA
22---
23> unsigned char *blitFrameBuffer1;
24> unsigned char *blitFrameBuffer2;
2556,57c57,58
26< GLuint texture;
27< GLuint textureb;
28---
29> GLuint texture1;
30> GLuint texture2;
3159c60
32< GLuint dlist;
33---
34> GLuint displayList;
3561,62c62,63
36< char ogl_ctable[256][3];
37< char ogl_temp_ctable[256][3]; // Support for OpenGL 1.1
38---
39> char colorTable[256][3];
40> char tempColorTable[256][3]; // Support for OpenGL 1.1
4164,65c65,67
42< void maketex();
43< void makedlist(int xf, int yf);
44---
45> void makeTextures();
46> void makeDisplayList(int xf, int yf);
47>
4867c69
49< SDL_Surface *screen;
50---
51>
5270a73,74
53> blitFrameBuffer1 = (unsigned char *)RGBAFrameBuffer1;
54> blitFrameBuffer2 = (unsigned char *)RGBAFrameBuffer2;
5571a76,84
56>
57> SDL_Surface *getScreen() {
58> return screen;
59> };
60>
61> void setScreen(SDL_Surface *s) {
62> screen = s;
63> };
64>
6580,82c93,95
66< void FB2GL::maketex() {
67< glGenTextures(0,&texture);
68< glBindTexture(GL_TEXTURE_2D,texture);
69---
70> void FB2GL::makeTextures() {
71> glGenTextures(0,&texture1);
72> glBindTexture(GL_TEXTURE_2D,texture1);
7396c109
74< glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, ogl_fb1);
75---
76> glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, RGBAFrameBuffer1);
7799c112
78< glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX, 256, 256, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, ogl_fb);
79---
80> glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX, 256, 256, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, palettedFrameBuffer1);
81103,104c116,117
82< glGenTextures(1, &textureb);
83< glBindTexture(GL_TEXTURE_2D, textureb);
84---
85> glGenTextures(1, &texture2);
86> glBindTexture(GL_TEXTURE_2D, texture2);
87119c132
88< GL_UNSIGNED_BYTE, ogl_fb2);
89---
90> GL_UNSIGNED_BYTE, RGBAFrameBuffer2);
91123c136
92< GL_UNSIGNED_BYTE, ogl_fbb);
93---
94> GL_UNSIGNED_BYTE, palettedFrameBuffer2);
95128c141
96< void FB2GL::makedlist(int xf, int yf) {
97---
98> void FB2GL::makeDisplayList(int xf, int yf) {
99134,135c147,148
100< if (glIsList(dlist))
101< glDeleteLists(dlist, 1);
102---
103> if (glIsList(displayList))
104> glDeleteLists(displayList, 1);
105137,138c150,151
106< dlist=glGenLists(1);
107< glNewList(dlist, GL_COMPILE);
108---
109> displayList = glGenLists(1);
110> glNewList(displayList, GL_COMPILE);
111142c155
112< glBindTexture(GL_TEXTURE_2D, texture);
113---
114> glBindTexture(GL_TEXTURE_2D, texture1);
115146,150c159,166
116< glTexCoord2f(0.0, 1.0); glVertex2f(-1.0, -1.0 - yfix); // upper left
117< glTexCoord2f(0.0, 0.0); glVertex2f(-1.0, 1.0); // lower left
118< glTexCoord2f(1.0, 0.0); glVertex2f(1.0 + xfix, 1.0); // lower right
119< glTexCoord2f(1.0, 1.0); glVertex2f(1.0 + xfix, -1.0 - yfix); // upper right
120< glEnd();
121---
122> // upper left
123> glTexCoord2f(0.0, 1.0); glVertex2f(-1.0, -1.0 - yfix);
124> // lower left
125> glTexCoord2f(0.0, 0.0); glVertex2f(-1.0, 1.0);
126> // lower right
127> glTexCoord2f(1.0, 0.0); glVertex2f(1.0 + xfix, 1.0);
128> // upper right
129> glTexCoord2f(1.0, 1.0); glVertex2f(1.0 + xfix, -1.0 - yfix); glEnd();
130156,159c172,179
131< glTexCoord2f(0.0, 1.0); glVertex2f( -1.0, -1.0 - yfix); // upper left
132< glTexCoord2f(0.0, 0.0); glVertex2f(-1.0, 1.0); // lower left
133< glTexCoord2f(1.0, 0.0); glVertex2f(texend + xfix, 1.0); // lower right
134< glTexCoord2f(1.0, 1.0); glVertex2f(texend + xfix, -1.0 - yfix); // upper right
135---
136> // upper left
137> glTexCoord2f(0.0, 1.0); glVertex2f( -1.0, -1.0 - yfix);
138> // lower left
139> glTexCoord2f(0.0, 0.0); glVertex2f(-1.0, 1.0);
140> // lower right
141> glTexCoord2f(1.0, 0.0); glVertex2f(texend + xfix, 1.0);
142> // upper right
143> glTexCoord2f(1.0, 1.0); glVertex2f(texend + xfix, -1.0 - yfix);
144163c183
145< glBindTexture(GL_TEXTURE_2D, textureb);
146---
147> glBindTexture(GL_TEXTURE_2D, texture2);
148166,169c186,193
149< glTexCoord2f(0.0, 1.0); glVertex2f(texend + xfix, -1.0 - yfix); // upper left
150< glTexCoord2f(0.0, 0.0); glVertex2f(texend + xfix, 1.0); // lower left
151< glTexCoord2f(1.0, 0.0); glVertex2f(1.0 + xfix, 1.0); // lower right
152< glTexCoord2f(1.0, 1.0); glVertex2f(1.0 + xfix, -1.0 - yfix); // upper right
153---
154> // upper left
155> glTexCoord2f(0.0, 1.0); glVertex2f(texend + xfix, -1.0 - yfix);
156> // lower left
157> glTexCoord2f(0.0, 0.0); glVertex2f(texend + xfix, 1.0);
158> // lower right
159> glTexCoord2f(1.0, 0.0); glVertex2f(1.0 + xfix, 1.0);
160> // upper right
161> glTexCoord2f(1.0, 1.0); glVertex2f(1.0 + xfix, -1.0 - yfix);
162191c215
163< warning("Screen BitsPerPixel: %d\n",screen->format->BitsPerPixel);
164---
165> // warning("Screen BitsPerPixel: %d\n",screen->format->BitsPerPixel);
166194c218
167< fprintf(stderr, "Couldn't start video res %dx%d\n", width, height);
168---
169> warning("Couldn't start video res %dx%d\n", width, height);
170198c222
171<
172---
173> /*
174211c235,236
175<
176---
177> */
178>
179213,214c238,239
180< maketex();
181< makedlist(xfix, yfix);
182---
183> makeTextures();
184> makeDisplayList(xfix, yfix);
185216,220d240
186< /* glEnable(GL_ALPHA_TEST);
187< glEnable(GL_BLEND);
188< glAlphaFunc(GL_GREATER,0);
189< glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);*/
190<
191226c246
192< glCallList(dlist);
193---
194> glCallList(displayList);
195231,232c251,252
196< unsigned char *fb1=(unsigned char *)fb;
197< int x,y,scr_pitch,byte=0;
198---
199> unsigned char *tempFrameBuffer = (unsigned char *)fb;
200> int x, y, scr_pitch, byte = 0;
201234c254
202< if (flags & FB2GL_PITCH) scr_pitch=pitch;
203---
204> if (flags & FB2GL_PITCH) scr_pitch = pitch;
205236c256
206< scr_pitch=w*pitch;
207---
208> scr_pitch = w * pitch;
209244,250c264,270
210< for (y=yskip; y<h; y++) {
211< for (x=xskip; x<w; x++) {
212< if (x<256) {
213< ogl_fb1[y][x][0] = ogl_ctable[*(fb1+x)][0];
214< ogl_fb1[y][x][1] = ogl_ctable[*(fb1+x)][1];
215< ogl_fb1[y][x][2] = ogl_ctable[*(fb1+x)][2];
216< ogl_fb1[y][x][3] = 255;
217---
218> for (y = yskip; y < h; y++) {
219> for (x = xskip; x < w; x++) {
220> if (x < 256) {
221> RGBAFrameBuffer1[y][x][0] = colorTable[*(tempFrameBuffer+x)][0];
222> RGBAFrameBuffer1[y][x][1] = colorTable[*(tempFrameBuffer+x)][1];
223> RGBAFrameBuffer1[y][x][2] = colorTable[*(tempFrameBuffer+x)][2];
224> RGBAFrameBuffer1[y][x][3] = 255;
225253,256c273,276
226< ogl_fb2[y][x-256][0] = ogl_ctable[*(fb1+x)][0];
227< ogl_fb2[y][x-256][1] = ogl_ctable[*(fb1+x)][1];
228< ogl_fb2[y][x-256][2] = ogl_ctable[*(fb1+x)][2];
229< ogl_fb2[y][x-256][3] = 255;
230---
231> RGBAFrameBuffer2[y][x-256][0] = colorTable[*(tempFrameBuffer+x)][0];
232> RGBAFrameBuffer2[y][x-256][1] = colorTable[*(tempFrameBuffer+x)][1];
233> RGBAFrameBuffer2[y][x-256][2] = colorTable[*(tempFrameBuffer+x)][2];
234> RGBAFrameBuffer2[y][x-256][3] = 255;
235259c279
236< fb1 += scr_pitch;
237---
238> tempFrameBuffer += scr_pitch; // Next row (like y++)
239263,268c283,288
240< for (y=yskip; y<h; y++) {
241< for (x=xskip; x<w; x++) {
242< if (x<256) {
243< ogl_fb1[y-yskip][x-xskip][0] = *(fb1+(x*byte));
244< ogl_fb1[y-yskip][x-xskip][1] = *(fb1+(x*byte)+1);
245< ogl_fb1[y-yskip][x-xskip][2] = *(fb1+(x*byte)+2);
246---
247> for (y = yskip; y < h; y++) {
248> for (x = xskip; x < w; x++) {
249> if (x < 256) {
250> RGBAFrameBuffer1[y-yskip][x-xskip][0] = *(tempFrameBuffer+(x*byte));
251> RGBAFrameBuffer1[y-yskip][x-xskip][1] = *(tempFrameBuffer+(x*byte)+1);
252> RGBAFrameBuffer1[y-yskip][x-xskip][2] = *(tempFrameBuffer+(x*byte)+2);
253271,273c291,293
254< ogl_fb2[y-yskip][x-256][0] = *(fb1+(x*byte));
255< ogl_fb2[y-yskip][x-256][1] = *(fb1+(x*byte)+1);
256< ogl_fb2[y-yskip][x-256][2] = *(fb1+(x*byte)+2);
257---
258> RGBAFrameBuffer2[y-yskip][x-256][0] = *(tempFrameBuffer+(x*byte));
259> RGBAFrameBuffer2[y-yskip][x-256][1] = *(tempFrameBuffer+(x*byte)+1);
260> RGBAFrameBuffer2[y-yskip][x-256][2] = *(tempFrameBuffer+(x*byte)+2);
261276c296
262< fb1 += scr_pitch;
263---
264> tempFrameBuffer += scr_pitch; // Next row (like y++)
265281c301
266< glBindTexture(GL_TEXTURE_2D,texture);
267---
268> glBindTexture(GL_TEXTURE_2D, texture1);
269283,284c303,305
270< glTexSubImage2D(GL_TEXTURE_2D,0,xskip,yskip,256-xskip,256-yskip,GL_RGBA,
271< GL_UNSIGNED_BYTE,ogl_fb1);
272---
273> glTexSubImage2D(GL_TEXTURE_2D, 0, xskip, yskip,
274> 256-xskip, 256-yskip, GL_RGBA,
275> GL_UNSIGNED_BYTE, RGBAFrameBuffer1);
276288c309
277< glBindTexture(GL_TEXTURE_2D,textureb);
278---
279> glBindTexture(GL_TEXTURE_2D, texture2);
280290,291c311,313
281< glTexSubImage2D(GL_TEXTURE_2D,0,xskip,yskip,64-xskip,256-yskip,GL_RGBA,
282< GL_UNSIGNED_BYTE,ogl_fb2);
283---
284> glTexSubImage2D(GL_TEXTURE_2D, 0, xskip, yskip,
285> 64-xskip, 256-yskip, GL_RGBA,
286> GL_UNSIGNED_BYTE, RGBAFrameBuffer2);
287300c322
288< ogl_fb[ y ][ x ] = *(fb1 + (y)*scr_pitch + x);
289---
290> palettedFrameBuffer1[ y ][ x ] = *(tempFrameBuffer + (y)*scr_pitch + x);
291303c325
292< ogl_fbb[ y ][ x - 256 ] = *(fb1 + y*scr_pitch + x);
293---
294> palettedFrameBuffer2[ y ][ x - 256 ] = *(tempFrameBuffer + y*scr_pitch + x);
295308,310c330,333
296< glBindTexture(GL_TEXTURE_2D,texture);
297< glTexSubImage2D(GL_TEXTURE_2D,0,xskip,yskip,256-xskip,256-yskip,
298< GL_COLOR_INDEX, GL_UNSIGNED_BYTE,ogl_fb);
299---
300> glBindTexture(GL_TEXTURE_2D, texture1);
301> glTexSubImage2D(GL_TEXTURE_2D, 0, xskip, yskip,
302> 256-xskip, 256-yskip, GL_COLOR_INDEX,
303> GL_UNSIGNED_BYTE, palettedFrameBuffer1);
304314,316c337,340
305< glBindTexture(GL_TEXTURE_2D,textureb);
306< glTexSubImage2D(GL_TEXTURE_2D,0,xskip,yskip,64-xskip,256-yskip,
307< GL_COLOR_INDEX, GL_UNSIGNED_BYTE,ogl_fbb);
308---
309> glBindTexture(GL_TEXTURE_2D, texture2);
310> glTexSubImage2D(GL_TEXTURE_2D, 0, xskip, yskip,
311> 64-xskip, 256-yskip, GL_COLOR_INDEX,
312> GL_UNSIGNED_BYTE, palettedFrameBuffer2);
313322d345
314<
315327,328c350,353
316< int rx, ry, rw, rh;
317< int xend=0, yend=0;
318---
319> int rx, ry, rw, rh; // rect[i].x, .y, .w, .h
320> // (0 <= rx <= 320) and (0 <= ry <= 240).
321> // Note: rx may be larger than texture1 width (256).
322> int xend=0, yend=0; // (x + width) and (y + height)
323330,331c355,362
324< int tex1_w = 0, tex2_w = 0, tex2_x = 0;
325<
326---
327>
328> // Width of the rectangle draw in texture1. (256 - rx) > 0
329> unsigned int tex1_w = 0;
330> // Width of the rectangle draw in texture2. (xend - 256) > 0
331> unsigned int tex2_w = 0;
332> // Rectangle's x coordinate in texture2. (rx - 256) > 0
333> unsigned int tex2_x = 0;
334>
335343,346c374,377
336< if (rx < 256) { // Begins before the end of the 1st texture
337< if (xend >= 256) { // Ends after the first texture
338< tex2_w = xend-256; // For the 2nd texture
339< tex1_w = rw - tex2_w; // For the 1st texture
340---
341> if (rx < 256) { // Begins before the end of texture1
342> if (xend >= 256) { // Ends after texture1
343> tex2_w = xend - 256; //Rectangle width on texture2
344> tex1_w = rw - tex2_w; // Width left for texture1
345348c379
346< else tex1_w = rw;
347---
348> else tex1_w = rw; // This rectangle is inside texture1
349351,352c382,383
350< tex2_w = rw;
351< tex2_x = rx - 256;
352---
353> tex2_w = rw; // This rectangle is inside texture2
354> tex2_x = rx - 256; // Relative x coordinate on texture2
355354a386,388
356> // Note: if (tex1_w == 0) then there is no rectangle to draw
357> // in texture1. The same is true for tex2_w.
358>
359359,363c393,400
360< int pos = (x-rx+(y-ry)*tex1_w)*4; // RGBA
361< SDL_GetRGB(((Uint16 *)fb->pixels)[x+y*(pitch)],fb->format,
362< &fb1[pos],
363< &fb1[pos+1],
364< &fb1[pos+2]);
365---
366> int pos = (x-rx+(y-ry)*tex1_w)*4; // (x + (y*pitch)) * RGBAsize
367> SDL_GetRGB(
368> ((Uint16 *)fb->pixels)[x+y*(pitch)],
369> fb->format,
370> &blitFrameBuffer1[pos],
371> &blitFrameBuffer1[pos+1],
372> &blitFrameBuffer1[pos+2]
373> );
374367,371c404,411
375< int pos = (x-rx2+(y-ry)*tex2_w)*4; // RGBA
376< SDL_GetRGB(((Uint16 *)fb->pixels)[x+y*(pitch)],fb->format,
377< &fb2[pos],
378< &fb2[pos+1],
379< &fb2[pos+2]);
380---
381> int pos = (x-rx2+(y-ry)*tex2_w)*4; // (x + (y*pitch)) * RGBAsize
382> SDL_GetRGB(
383> ((Uint16 *)fb->pixels)[x+y*(pitch)],
384> fb->format,
385> &blitFrameBuffer2[pos],
386> &blitFrameBuffer2[pos+1],
387> &blitFrameBuffer2[pos+2]
388> );
389378c418
390< glBindTexture(GL_TEXTURE_2D,texture);
391---
392> glBindTexture(GL_TEXTURE_2D, texture1);
393380,381c420,424
394< glTexSubImage2D(GL_TEXTURE_2D,0,rx+xskip,ry+yskip,tex1_w,rh,GL_RGBA,
395< GL_UNSIGNED_BYTE,fb1);
396---
397> glTexSubImage2D(GL_TEXTURE_2D, 0,
398> rx + xskip,
399> ry + yskip,
400> tex1_w, rh, GL_RGBA,
401> GL_UNSIGNED_BYTE, blitFrameBuffer1);
402385c428
403< glBindTexture(GL_TEXTURE_2D,textureb);
404---
405> glBindTexture(GL_TEXTURE_2D, texture2);
406387,388c430,434
407< glTexSubImage2D(GL_TEXTURE_2D,0,tex2_x+xskip,ry+yskip,tex2_w,rh,GL_RGBA,
408< GL_UNSIGNED_BYTE,fb2);
409---
410> glTexSubImage2D(GL_TEXTURE_2D, 0,
411> tex2_x + xskip,
412> ry + yskip,
413> tex2_w, rh, GL_RGBA,
414> GL_UNSIGNED_BYTE,blitFrameBuffer2);
415395,397c441,443
416< ogl_temp_ctable[i][0]=r;
417< ogl_temp_ctable[i][1]=g;
418< ogl_temp_ctable[i][2]=b;
419---
420> tempColorTable[i][0] = r;
421> tempColorTable[i][1] = g;
422> tempColorTable[i][2] = b;
423400,402c446,448
424< ogl_ctable[i][0]=r;
425< ogl_ctable[i][1]=g;
426< ogl_ctable[i][2]=b;
427---
428> colorTable[i][0] = r;
429> colorTable[i][1] = g;
430> colorTable[i][2] = b;
431406c452
432< void FB2GL::setPalette(int f, int n) {
433---
434> void FB2GL::setPalette(int first, int n) {
435411,414c457,460
436< for (i=f; i<n; i++) {
437< ogl_ctable[i][0] = ogl_temp_ctable[i][0];
438< ogl_ctable[i][1] = ogl_temp_ctable[i][1];
439< ogl_ctable[i][2] = ogl_temp_ctable[i][2];
440---
441> for (i = first; i < n; i++) {
442> colorTable[i][0] = tempColorTable[i][0];
443> colorTable[i][1] = tempColorTable[i][1];
444> colorTable[i][2] = tempColorTable[i][2];
445418,419c464,465
446< glBindTexture(GL_TEXTURE_2D,texture);
447< glGetColorTable(GL_TEXTURE_2D,GL_RGB,GL_UNSIGNED_BYTE,&temp);
448---
449> glBindTexture(GL_TEXTURE_2D, texture1);
450> glGetColorTable(GL_TEXTURE_2D, GL_RGB, GL_UNSIGNED_BYTE, &temp);
451421,424c467,470
452< for (i=f; i<n; i++) {
453< temp[i][0] = ogl_ctable[i][0];
454< temp[i][1] = ogl_ctable[i][1];
455< temp[i][2] = ogl_ctable[i][2];
456---
457> for (i = first; i < n; i++) {
458> temp[i][0] = colorTable[i][0];
459> temp[i][1] = colorTable[i][1];
460> temp[i][2] = colorTable[i][2];
461427c473,474
462< glColorTable(GL_TEXTURE_2D,GL_RGB,256,GL_RGB,GL_UNSIGNED_BYTE,&temp);
463---
464> glColorTable(GL_TEXTURE_2D, GL_RGB, 256, GL_RGB,
465> GL_UNSIGNED_BYTE, &temp);
466430,431c477,479
467< glBindTexture(GL_TEXTURE_2D,textureb);
468< glColorTable(GL_TEXTURE_2D,GL_RGB,256,GL_RGB,GL_UNSIGNED_BYTE,&temp);
469---
470> glBindTexture(GL_TEXTURE_2D, texture2);
471> glColorTable(GL_TEXTURE_2D, GL_RGB, 256, GL_RGB,
472> GL_UNSIGNED_BYTE, &temp);
473435d482
474<