1 /******************************************************************************
2 * Arachnoid Graphics Plugin for Mupen64Plus
3 * http://bitbucket.org/wahrhaft/mupen64plus-video-arachnoid/
5 * Copyright (C) 2007 Kristofer Karlsson, Rickard Niklasson
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *****************************************************************************/
22 #include "OpenGL2DRenderer.h"
27 //-----------------------------------------------------------------------------
29 //! Saves pointer to video interface
30 //-----------------------------------------------------------------------------
31 bool OpenGL2DRenderer::initialize(VI* vi)
37 //-----------------------------------------------------------------------------
39 //! Renders a 2D rectangle in HUD.
40 //! @todo Set Viewport
41 //! @todo Reset Viewport
42 //-----------------------------------------------------------------------------
43 void OpenGL2DRenderer::renderQuad( const float color[4],
49 GLboolean scissor = glIsEnabled(GL_SCISSOR_TEST);
50 GLboolean cull = glIsEnabled(GL_CULL_FACE);
53 glDisable( GL_SCISSOR_TEST );
54 glDisable( GL_CULL_FACE );
56 //Set Othographic Projection Matrix
57 glMatrixMode(GL_PROJECTION);
60 glOrtho(0, m_vi->getWidth(), m_vi->getHeight(), 0, 1.0f, -1.0f);
63 //glViewport(0, glheightOffset, glwidth, glheight);
64 //glDepthRange( 0.0f, 1.0f );
76 GLboolean glcol = glIsEnabled(GL_COLOR_ARRAY);
77 if (glcol) glDisableClientState(GL_COLOR_ARRAY);
78 GLboolean glvtx = glIsEnabled(GL_VERTEX_ARRAY);
80 glEnableClientState(GL_VERTEX_ARRAY);
81 glVertexPointer(3,GL_FLOAT, 0,&vtx);
82 glActiveTexture( GL_TEXTURE1 );
83 GLboolean gltex1 = glIsEnabled(GL_TEXTURE_2D);
84 if (gltex1) glDisable(GL_TEXTURE_2D);
85 glActiveTexture( GL_TEXTURE0 );
86 GLboolean gltex = glIsEnabled(GL_TEXTURE_2D);
87 if (gltex) glDisable(GL_TEXTURE_2D);
89 glDrawArrays(GL_TRIANGLE_FAN,0,4);
91 if (glcol) glEnableClientState(GL_COLOR_ARRAY);
92 glActiveTexture( GL_TEXTURE1 );
93 if (gltex1) glEnable(GL_TEXTURE_2D);
94 glActiveTexture( GL_TEXTURE0 );
95 if (gltex) glEnable(GL_TEXTURE_2D);
97 glDisableClientState(GL_VERTEX_ARRAY);
99 glVertexPointer(glsav_vtx_size, glsav_vtx_type, glsav_vtx_stride, glsav_vtx_array );
103 glVertex3f(x0, y0, depth);
104 glVertex3f(x1, y0, depth);
105 glVertex3f(x1, y1, depth);
106 glVertex3f(x0, y1, depth);
109 //Reset Projection Matrix
110 glMatrixMode(GL_PROJECTION);
112 glMatrixMode(GL_MODELVIEW);
115 if ( scissor ) glEnable(GL_SCISSOR_TEST);
116 if ( cull ) glEnable(GL_CULL_FACE);
118 //TODO Reset viewport?
122 //-----------------------------------------------------------------------------
123 //* Render Textured Quad
124 //! Renders a textured 2D rectangle in HUD.
125 //! @todo Set Viewport
126 //! @todo Reset Viewport
127 //-----------------------------------------------------------------------------
128 void OpenGL2DRenderer::renderTexturedQuad( const float color[4],
129 const float secondaryColor[4],
133 float t0s0, float t0t0,
134 float t0s1, float t0t1,
135 float t1s0, float t1t0,
136 float t1s1, float t1t1 )
139 GLboolean cull = glIsEnabled(GL_CULL_FACE);
140 GLboolean fog = glIsEnabled(GL_FOG);
143 glDisable(GL_CULL_FACE);
146 //Set Orthographic Projection
147 glMatrixMode(GL_PROJECTION);
150 glOrtho(0, m_vi->getWidth(), m_vi->getHeight(), 0, 1.0f, -1.0f);
153 //glViewport(0, glheightOffset, glwidth, glheight);
154 //glDepthRange( 0.0f, 1.0f );
178 GLboolean glcol = glIsEnabled(GL_COLOR_ARRAY);
179 if (glcol) glDisableClientState(GL_COLOR_ARRAY);
180 GLboolean glvtx = glIsEnabled(GL_VERTEX_ARRAY);
182 glEnableClientState(GL_VERTEX_ARRAY);
183 glVertexPointer(3,GL_FLOAT, 0,&vtx);
184 /* glActiveTexture( GL_TEXTURE1 );
185 GLboolean gltex1 = glIsEnabled(GL_TEXTURE_2D);
186 if (gltex1) glDisable(GL_TEXTURE_2D);*/
187 glClientActiveTexture( GL_TEXTURE1 );
188 glTexCoordPointer(2, GL_FLOAT, 0, &tex1);
189 glClientActiveTexture( GL_TEXTURE0 );
190 glTexCoordPointer(2, GL_FLOAT, 0, &tex);
192 glDrawArrays(GL_TRIANGLE_FAN,0,4);
194 if (glcol) glEnableClientState(GL_COLOR_ARRAY);
195 // if (gltex1) glEnable(GL_TEXTURE_2D);
197 glDisableClientState(GL_VERTEX_ARRAY);
198 if (glsav_vtx_type==GL_FLOAT) glVertexPointer(glsav_vtx_size, glsav_vtx_type, glsav_vtx_stride, glsav_vtx_array );
199 glClientActiveTexture( GL_TEXTURE1 );
200 if (glsav_tex1_type==GL_FLOAT) glTexCoordPointer( glsav_tex1_size, glsav_tex1_type, glsav_tex1_stride, glsav_tex1_array );
201 glClientActiveTexture( GL_TEXTURE0 );
202 if (glsav_tex_type==GL_FLOAT) glTexCoordPointer( glsav_tex_size, glsav_tex_type, glsav_tex_stride, glsav_tex_array );
208 glTexCoord2f(t0s0, t0t0);
209 glVertex3f(x0, y0, depth);
212 glTexCoord2f(t0s1, t0t0);
213 glVertex3f(x1, y0, depth);
216 glTexCoord2f(t0s1, t0t1 );
217 glVertex3f(x1, y1, depth);
220 glTexCoord2f(t0s0, t0t1 );
221 glVertex3f(x0, y1, depth);
225 //Reset Projection Matrix
226 glMatrixMode(GL_PROJECTION);
228 glMatrixMode(GL_MODELVIEW);
231 if ( cull ) glEnable(GL_CULL_FACE);
232 if ( fog ) glEnable(GL_FOG);
234 //TODO Reset viewport?
238 //-----------------------------------------------------------------------------
239 //Render Flipped Textured Quad
240 //! Renders a flipped textured 2D rectangle in HUD.
241 //! @todo Set Viewport
242 //! @todo Reset Viewport
243 //-----------------------------------------------------------------------------
244 void OpenGL2DRenderer::renderFlippedTexturedQuad( const float color[4],
245 const float secondaryColor[4],
249 float t0s0, float t0t0,
250 float t0s1, float t0t1,
251 float t1s0, float t1t0,
252 float t1s1, float t1t1 )
255 GLboolean cull = glIsEnabled(GL_CULL_FACE);
256 GLboolean fog = glIsEnabled(GL_FOG);
259 glDisable(GL_CULL_FACE);
262 //Set Orthographic Projection
263 glMatrixMode(GL_PROJECTION);
266 glOrtho(0, m_vi->getWidth(), m_vi->getHeight(), 0, 1.0f, -1.0f);
269 //glViewport(0, glheightOffset, glwidth, glheight);
270 //glDepthRange( 0.0f, 1.0f );
295 GLboolean glcol = glIsEnabled(GL_COLOR_ARRAY);
296 if (glcol) glDisableClientState(GL_COLOR_ARRAY);
297 GLboolean glvtx = glIsEnabled(GL_VERTEX_ARRAY);
299 glEnableClientState(GL_VERTEX_ARRAY);
300 glVertexPointer(3,GL_FLOAT, 0,&vtx);
301 /* glActiveTexture( GL_TEXTURE1 );
302 GLboolean gltex1 = glIsEnabled(GL_TEXTURE_2D);
303 if (gltex1) glDisable(GL_TEXTURE_2D);*/
304 glClientActiveTexture( GL_TEXTURE1 );
305 glTexCoordPointer(2, GL_FLOAT, 0, &tex1);
306 glClientActiveTexture( GL_TEXTURE0 );
307 glTexCoordPointer(2, GL_FLOAT, 0, &tex);
309 glDrawArrays(GL_TRIANGLE_FAN,0,4);
311 if (glcol) glEnableClientState(GL_COLOR_ARRAY);
312 // if (gltex1) glEnable(GL_TEXTURE_2D);
313 glVertexPointer(glsav_vtx_size, glsav_vtx_type, glsav_vtx_stride, glsav_vtx_array );
314 glClientActiveTexture( GL_TEXTURE1 );
315 glTexCoordPointer( glsav_tex1_size, glsav_tex1_type, glsav_tex1_stride, glsav_tex1_array );
316 glClientActiveTexture( GL_TEXTURE0 );
317 glTexCoordPointer( glsav_tex_size, glsav_tex_type, glsav_tex_stride, glsav_tex_array );
318 #else //Render Rectangle
322 glTexCoord2f(t0s0, t0t0); //00
323 glVertex3f(x0, y0, depth);
326 glTexCoord2f(t0s0, t0t1); //01 !
327 glVertex3f(x1, y0, depth);
330 glTexCoord2f(t0s1, t0t1); //11
331 glVertex3f(x1, y1, depth);
334 glTexCoord2f(t0s1, t0t0); //10 !
335 glVertex3f(x0, y1, depth);
339 //Reset Projection Matrix
340 glMatrixMode(GL_PROJECTION);
342 glMatrixMode(GL_MODELVIEW);
345 if ( cull ) glEnable(GL_CULL_FACE);
346 if ( fog ) glEnable(GL_FOG);
348 //TODO Reset viewport?