GLE2RICE: Some fixes from muppen64plus-ae
[mupen64plus-pandora.git] / source / gles2rice / src / OGLRenderExt.cpp
1 /*
2 Copyright (C) 2003 Rice1964
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 */
18
19 #include "osal_opengl.h"
20
21 #include "OGLRender.h"
22
23 extern Matrix g_MtxReal;
24 extern uObjMtxReal gObjMtxReal;
25
26 //========================================================================
27
28 void OGLRender::DrawText(const char* str, RECT *rect)
29 {
30     return;
31 }
32
33 void OGLRender::DrawSpriteR_Render()    // With Rotation
34 {
35     glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
36
37     GLboolean cullface = glIsEnabled(GL_CULL_FACE);
38     glDisable(GL_CULL_FACE);
39
40 #if SDL_VIDEO_OPENGL
41
42     glBegin(GL_TRIANGLES);
43     glColor4fv(gRDP.fvPrimitiveColor);
44
45     OGLRender::TexCoord(g_texRectTVtx[0]);
46     glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
47
48     OGLRender::TexCoord(g_texRectTVtx[1]);
49     glVertex3f(g_texRectTVtx[1].x, g_texRectTVtx[1].y, -g_texRectTVtx[1].z);
50
51     OGLRender::TexCoord(g_texRectTVtx[2]);
52     glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
53
54     OGLRender::TexCoord(g_texRectTVtx[0]);
55     glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, -g_texRectTVtx[0].z);
56
57     OGLRender::TexCoord(g_texRectTVtx[2]);
58     glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, -g_texRectTVtx[2].z);
59
60     OGLRender::TexCoord(g_texRectTVtx[3]);
61     glVertex3f(g_texRectTVtx[3].x, g_texRectTVtx[3].y, -g_texRectTVtx[3].z);
62
63     glEnd();
64
65 #elif SDL_VIDEO_OPENGL_ES2
66
67     GLfloat colour[] = {
68             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
69             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
70             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
71
72             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
73             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
74             gRDP.fvPrimitiveColor[0], gRDP.fvPrimitiveColor[1], gRDP.fvPrimitiveColor[2], gRDP.fvPrimitiveColor[3],
75     };
76
77     GLfloat tex[] = {
78             g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
79             g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v,
80             g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
81
82             g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v,
83             g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v,
84             g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v,
85     };
86
87     GLfloat tex2[] = {
88             g_texRectTVtx[0].tcord[1].u,g_texRectTVtx[0].tcord[1].v,
89             g_texRectTVtx[1].tcord[1].u,g_texRectTVtx[1].tcord[1].v,
90             g_texRectTVtx[2].tcord[1].u,g_texRectTVtx[2].tcord[1].v,
91
92             g_texRectTVtx[0].tcord[1].u,g_texRectTVtx[0].tcord[1].v,
93             g_texRectTVtx[2].tcord[1].u,g_texRectTVtx[2].tcord[1].v,
94             g_texRectTVtx[3].tcord[1].u,g_texRectTVtx[3].tcord[1].v,
95     };
96
97  float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f;
98
99     GLfloat vertices[] = {
100             -inv + g_texRectTVtx[0].x/ w, inv - g_texRectTVtx[0].y/ h, -g_texRectTVtx[0].z,1,
101             -inv + g_texRectTVtx[1].x/ w, inv - g_texRectTVtx[1].y/ h, -g_texRectTVtx[1].z,1,
102             -inv + g_texRectTVtx[2].x/ w, inv - g_texRectTVtx[2].y/ h, -g_texRectTVtx[2].z,1,
103
104             -inv + g_texRectTVtx[0].x/ w, inv - g_texRectTVtx[0].y/ h, -g_texRectTVtx[0].z,1,
105             -inv + g_texRectTVtx[2].x/ w, inv - g_texRectTVtx[2].y/ h, -g_texRectTVtx[2].z,1,
106             -inv + g_texRectTVtx[3].x/ w, inv - g_texRectTVtx[3].y/ h, -g_texRectTVtx[3].z,1
107     };
108
109
110     glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_FALSE, 0, &colour );
111     glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices);
112     glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, 0, &tex);
113         glVertexAttribPointer(VS_TEXCOORD1,2,GL_FLOAT,GL_FALSE, 0, &tex2);
114     //OPENGL_CHECK_ERRORS;
115     glDrawArrays(GL_TRIANGLES,0,6);
116     //OPENGL_CHECK_ERRORS;
117
118     //Restore old pointers
119     glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
120     glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0]));
121     glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u));
122         glVertexAttribPointer(VS_TEXCOORD1,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u));
123
124 #endif
125
126     if( cullface ) glEnable(GL_CULL_FACE);
127 }
128
129
130 void OGLRender::DrawObjBGCopy(uObjBg &info)
131 {
132     if( IsUsedAsDI(g_CI.dwAddr) )
133     {
134         DebugMessage(M64MSG_WARNING, "Unimplemented: write into Z buffer.  Was mostly commented out in Rice Video 6.1.0");
135         return;
136     }
137     else
138     {
139         CRender::LoadObjBGCopy(info);
140         CRender::DrawObjBGCopy(info);
141     }
142 }
143
144