1 /* Emacs style mode select   -*- C++ -*-
2  *-----------------------------------------------------------------------------
3  *
4  *
5  *  PrBoom: a Doom port merged with LxDoom and LSDLDoom
6  *  based on BOOM, a modified and improved DOOM engine
7  *  Copyright (C) 1999 by
8  *  id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9  *  Copyright (C) 1999-2000 by
10  *  Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
11  *  Copyright 2005, 2006 by
12  *  Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
13  *
14  *  This program is free software; you can redistribute it and/or
15  *  modify it under the terms of the GNU General Public License
16  *  as published by the Free Software Foundation; either version 2
17  *  of the License, or (at your option) any later version.
18  *
19  *  This program is distributed in the hope that it will be useful,
20  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *  GNU General Public License for more details.
23  *
24  *  You should have received a copy of the GNU General Public License
25  *  along with this program; if not, write to the Free Software
26  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27  *  02111-1307, USA.
28  *
29  * DESCRIPTION:
30  *
31  *---------------------------------------------------------------------
32  */
33 
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
37 
38 #include "gl_opengl.h"
39 
40 #include "v_video.h"
41 #include "gl_intern.h"
42 #include "m_random.h"
43 #include "lprintf.h"
44 #include "e6y.h"
45 
46 static GLuint wipe_scr_start_tex = 0;
47 static GLuint wipe_scr_end_tex = 0;
48 
CaptureScreenAsTexID(void)49 GLuint CaptureScreenAsTexID(void)
50 {
51   GLuint id;
52 
53   gld_EnableTexture2D(GL_TEXTURE0_ARB, true);
54 
55   glGenTextures(1, &id);
56   glBindTexture(GL_TEXTURE_2D, id);
57 
58   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
59   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
60   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
61   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
62 
63   glTexImage2D(GL_TEXTURE_2D, 0, 3,
64     gld_GetTexDimension(SCREENWIDTH), gld_GetTexDimension(SCREENHEIGHT),
65     0, GL_RGB, GL_UNSIGNED_BYTE, 0);
66 
67   glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, SCREENWIDTH, SCREENHEIGHT);
68 
69   return id;
70 }
71 
gld_wipe_doMelt(int ticks,int * y_lookup)72 int gld_wipe_doMelt(int ticks, int *y_lookup)
73 {
74   int i;
75   int total_w, total_h;
76   float fU1, fU2, fV1, fV2;
77 
78   total_w = gld_GetTexDimension(SCREENWIDTH);
79   total_h = gld_GetTexDimension(SCREENHEIGHT);
80 
81   fU1 = 0.0f;
82   fV1 = (float)SCREENHEIGHT / (float)total_h;
83   fU2 = (float)SCREENWIDTH / (float)total_w;
84   fV2 = 0.0f;
85 
86   gld_EnableTexture2D(GL_TEXTURE0_ARB, true);
87 
88   glBindTexture(GL_TEXTURE_2D, wipe_scr_end_tex);
89   glColor3f(1.0f, 1.0f, 1.0f);
90 
91   glBegin(GL_TRIANGLE_STRIP);
92   {
93     glTexCoord2f(fU1, fV1); glVertex2f(0.0f, 0.0f);
94     glTexCoord2f(fU1, fV2); glVertex2f(0.0f, (float)SCREENHEIGHT);
95     glTexCoord2f(fU2, fV1); glVertex2f((float)SCREENWIDTH, 0.0f);
96     glTexCoord2f(fU2, fV2); glVertex2f((float)SCREENWIDTH, (float)SCREENHEIGHT);
97   }
98   glEnd();
99 
100   glBindTexture(GL_TEXTURE_2D, wipe_scr_start_tex);
101   glColor3f(1.0f, 1.0f, 1.0f);
102 
103   glBegin(GL_QUAD_STRIP);
104 
105   for (i=0; i <= SCREENWIDTH; i++)
106   {
107     int yoffs = MAX(0, y_lookup[i]);
108 
109     float tx = (float) i / total_w;
110     float sx = (float) i;
111     float sy = (float) yoffs;
112 
113     glTexCoord2f(tx, fV1); glVertex2f(sx, sy);
114     glTexCoord2f(tx, fV2); glVertex2f(sx, sy + (float)SCREENHEIGHT);
115   }
116 
117   glEnd();
118 
119   return 0;
120 }
121 
gld_wipe_exitMelt(int ticks)122 int gld_wipe_exitMelt(int ticks)
123 {
124   if (wipe_scr_start_tex != 0)
125   {
126     glDeleteTextures(1, &wipe_scr_start_tex);
127     wipe_scr_start_tex = 0;
128   }
129   if (wipe_scr_end_tex != 0)
130   {
131     glDeleteTextures(1, &wipe_scr_end_tex);
132     wipe_scr_end_tex = 0;
133   }
134 
135   gld_ResetLastTexture();
136 
137   return 0;
138 }
139 
gld_wipe_StartScreen(void)140 int gld_wipe_StartScreen(void)
141 {
142   wipe_scr_start_tex = CaptureScreenAsTexID();
143 
144   return 0;
145 }
146 
gld_wipe_EndScreen(void)147 int gld_wipe_EndScreen(void)
148 {
149   glFlush();
150   wipe_scr_end_tex = CaptureScreenAsTexID();
151 
152   return 0;
153 }
154