00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "Core/precomp.h"
00016 #ifdef USE_OPENGL
00017
00018 #include "displaycard_gl_generic.h"
00019 #include "blit_gl_generic.h"
00020 #include "API/Core/System/cl_assert.h"
00021 #include "API/Application/clanapp.h"
00022
00023 void CL_GL_DisplayCard_Generic::set_palette(CL_Palette *palette)
00024 {
00025 memcpy(
00026 this->palette.palette,
00027 palette->palette,
00028 palette->num_colors);
00029 }
00030
00031 CL_Palette *CL_GL_DisplayCard_Generic::get_palette()
00032 {
00033 return &palette;
00034 }
00035
00036 const std::list<CL_VidMode*> &CL_GL_DisplayCard_Generic::get_videomodes()
00037 {
00038 static std::list<CL_VidMode*> modes;
00039 return modes;
00040 }
00041
00042 CL_Target *CL_GL_DisplayCard_Generic::get_target()
00043 {
00044
00045 return NULL;
00046 }
00047
00048 CL_Target *CL_GL_DisplayCard_Generic::get_frontbuffer()
00049 {
00050
00051 return NULL;
00052 }
00053
00054 void CL_GL_DisplayCard_Generic::sync_buffers()
00055 {
00056
00057 }
00058
00059 void CL_GL_DisplayCard_Generic::clear_display(
00060 float red,
00061 float green,
00062 float blue,
00063 float alpha)
00064 {
00065 glClearColor(red, green, blue, 1-alpha);
00066 glClear(GL_COLOR_BUFFER_BIT);
00067 }
00068
00069 void CL_GL_DisplayCard_Generic::fill_rect(
00070 int x1,
00071 int y1,
00072 int x2,
00073 int y2,
00074 float r,
00075 float g,
00076 float b,
00077 float a)
00078 {
00079 begin_2d();
00080 glDisable(GL_TEXTURE_2D);
00081
00082 glColor4f(r,g,b,a);
00083 glRecti(x1 + 0.375, y1 + 0.375, x2 + 0.375, y2 + 0.375);
00084 glColor4f(1.0, 1.0, 1.0, 1.0);
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 glEnable(GL_TEXTURE_2D);
00096 end_2d();
00097 }
00098
00099 void CL_GL_DisplayCard_Generic::draw_rect(
00100 int x1,
00101 int y1,
00102 int x2,
00103 int y2,
00104 float r,
00105 float g,
00106 float b,
00107 float a)
00108 {
00109 begin_2d();
00110
00111
00112 draw_line(x1, y1, x2 - 1, y1, r, g, b, a);
00113 draw_line(x2 - 1, y1, x2 - 1, y2 - 1, r, g, b, a);
00114 draw_line(x1 + 1, y2 - 1, x2, y2 - 1, r, g, b, a);
00115 draw_line(x1, y1 + 1, x1, y2, r, g, b, a);
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 end_2d();
00131 }
00132
00133 void CL_GL_DisplayCard_Generic::draw_line(
00134 int x1,
00135 int y1,
00136 int x2,
00137 int y2,
00138 float r,
00139 float g,
00140 float b,
00141 float a)
00142 {
00143 begin_2d();
00144 glDisable(GL_TEXTURE_2D);
00145
00146 glBegin(GL_LINES);
00147 glColor4f(r,g,b,a);
00148 glVertex2f(x1 + 0.375, y1 + 0.375);
00149 glVertex2f(x2 + 0.375, y2 + 0.375);
00150 glColor4f(1.0, 1.0, 1.0, 1.0);
00151 glEnd();
00152
00153 glEnable(GL_TEXTURE_2D);
00154 end_2d();
00155 }
00156
00157 void CL_GL_DisplayCard_Generic::enable_2d_projection()
00158 {
00159 cl_assert(uses_count == 0);
00160 use_2d_projection = true;
00161 }
00162
00163 void CL_GL_DisplayCard_Generic::disable_2d_projection()
00164 {
00165 cl_assert(uses_count == 0);
00166 use_2d_projection = false;
00167 }
00168
00169 void CL_GL_DisplayCard_Generic::begin_2d()
00170 {
00171 uses_count--;
00172 if (uses_count==-1)
00173 {
00174 glPushAttrib(GL_ALL_ATTRIB_BITS);
00175
00176 glEnable(GL_TEXTURE_2D);
00177 glEnable(GL_BLEND);
00178 glDisable(GL_FOG);
00179 glDisable(GL_DEPTH_TEST);
00180
00181 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
00182 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
00183 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
00184 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
00185 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
00186
00187 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00188
00189 glColor4f(1.0, 1.0, 1.0, 1.0);
00190
00191 if (use_2d_projection)
00192 {
00193 glMatrixMode(GL_PROJECTION);
00194 glPushMatrix();
00195 glLoadIdentity();
00196
00197 GLdouble viewport[4];
00198 glGetDoublev(GL_VIEWPORT, viewport);
00199
00200 GLdouble &width = viewport[2];
00201 GLdouble &height = viewport[3];
00202
00203 gluOrtho2D(0.0, width, height, 0.0);
00204 }
00205
00206 glMatrixMode(GL_MODELVIEW);
00207 if (use_2d_projection)
00208 {
00209 glPushMatrix();
00210 glLoadIdentity();
00211 }
00212
00213 glPushMatrix();
00214 glTranslatef(get_translate_offset_x(), get_translate_offset_y(), 0);
00215
00216 m_uses_gl = false;
00217 }
00218 }
00219
00220 void CL_GL_DisplayCard_Generic::end_2d()
00221 {
00222 uses_count++;
00223 if (uses_count==0)
00224 {
00225 glPopMatrix();
00226 if (use_2d_projection) glPopMatrix();
00227 glMatrixMode(GL_PROJECTION);
00228 glPopMatrix();
00229
00230 glPopAttrib();
00231
00232 m_uses_gl = true;
00233 }
00234 }
00235
00236 CL_Blitters CL_GL_DisplayCard_Generic::create_hw_blitters(CL_SurfaceProvider *provider)
00237 {
00238
00239 CL_Blit_GLTexture *blitter = new CL_Blit_GLTexture(this, provider);
00240
00241 CL_Blitters hw;
00242 hw.set_noclip(blitter);
00243 hw.set_clip(blitter);
00244 hw.set_scale_noclip(blitter);
00245 hw.set_scale_clip(blitter);
00246
00247 return hw;
00248 }
00249
00250 CL_Blitters CL_GL_DisplayCard_Generic::create_hw_dynamic_blitters(CL_SurfaceProvider *provider)
00251 {
00252
00253 CL_Blit_GLTexture *blitter = new CL_Blit_GLTexture(this, provider);
00254
00255 CL_Blitters hw;
00256 hw.set_noclip(blitter);
00257 hw.set_clip(blitter);
00258 hw.set_scale_noclip(blitter);
00259 hw.set_scale_clip(blitter);
00260
00261 return hw;
00262 }
00263
00264 void CL_GL_DisplayCard_Generic::push_translate_offset()
00265 {
00266 translate_stack.push(translate_stack.top());
00267 }
00268
00269 void CL_GL_DisplayCard_Generic::push_translate_offset(int x, int y)
00270 {
00271 std::pair<int,int> cur = translate_stack.top();
00272 cur.first += x;
00273 cur.second += y;
00274
00275 translate_stack.push(cur);
00276
00277 if (uses_count != 0)
00278 {
00279 glPopMatrix();
00280 glPushMatrix();
00281 glTranslatef(get_translate_offset_x(), get_translate_offset_y(), 0);
00282 }
00283 }
00284
00285 int CL_GL_DisplayCard_Generic::get_translate_offset_x()
00286 {
00287 return translate_stack.top().first;
00288 }
00289
00290 int CL_GL_DisplayCard_Generic::get_translate_offset_y()
00291 {
00292 return translate_stack.top().second;
00293 }
00294
00295 void CL_GL_DisplayCard_Generic::set_translate_offset(int x, int y)
00296 {
00297 translate_stack.top() = std::pair<int,int>(x, y);
00298
00299 if (uses_count != 0)
00300 {
00301 glPopMatrix();
00302 glPushMatrix();
00303 glTranslatef(get_translate_offset_x(), get_translate_offset_y(), 0);
00304 }
00305 }
00306
00307 void CL_GL_DisplayCard_Generic::pop_translate_offset()
00308 {
00309 translate_stack.pop();
00310
00311 if (uses_count != 0)
00312 {
00313 glPopMatrix();
00314 glPushMatrix();
00315 glTranslatef(get_translate_offset_x(), get_translate_offset_y(), 0);
00316 }
00317 }
00318
00319 #endif