Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

lockable_surface_gl.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: lockable_surface_gl.cpp,v 1.3 2000/05/03 18:29:00 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 */
00014 // THIS IS OUTDATED CRAP, IT'S ONLY PURPOSE HERE IS THAT I CAN COPY & PASTE CODE
00015 // FOR THE NEW DYNAMIC SURFACES
00016 
00017 #include "Core/precomp.h"
00018 
00019 #ifdef VOGEL_VOGEL_VOGEL
00020 
00021 #ifdef USE_OPENGL
00022 #include "displaycard_gl_generic.h"
00023 #include "lockable_surface_gl.h"
00024 #include "API/Core/System/cl_assert.h"
00025 #include "Core/Display/Generic/displaycard_generic.h"
00026 
00027 CL_LockableSurface_GL::CL_LockableSurface_GL(
00028         int width,
00029         int height,
00030         int no_sprs,
00031         int minimum_alpha_mask_size,
00032         CL_GL_DisplayCard_Generic *card)
00033 {
00034         m_width = width;
00035         m_height = height;
00036         m_no_sprs = no_sprs;
00037         m_colorkey = -1;
00038         m_card = card;
00039 
00040         if (minimum_alpha_mask_size > 0) m_alpha_mask = 0x000000ff;
00041         else m_alpha_mask = 0;
00042         
00043         m_data = new int[m_width*m_height*m_no_sprs];
00044         
00045 //      TODO: use TEXTURE PROXY
00046 
00047         m_texture_width = 2;
00048         while (m_texture_width<m_width)
00049                 m_texture_width *= 2;
00050 
00051         m_texture_height = 2;
00052         while (m_texture_height<m_height*m_no_sprs)
00053                 m_texture_height *= 2;
00054                 
00055         int* dummy = new int[m_texture_width*m_texture_height];         
00056 
00057         glGenTextures(1, &m_texture);
00058         glBindTexture(GL_TEXTURE_2D, m_texture);
00059         glTexImage2D(
00060                 GL_TEXTURE_2D,
00061                 0,
00062                 GL_RGBA,
00063                 m_texture_width,
00064                 m_texture_height,
00065                 0,
00066                 GL_RGBA,
00067                 GL_UNSIGNED_BYTE,
00068                 dummy);
00069 
00070         delete[] dummy;
00071 }
00072 
00073 CL_LockableSurface_GL::~CL_LockableSurface_GL()
00074 {
00075         glDeleteTextures(1,&m_texture);
00076         delete[] m_data;
00077 }
00078 
00079 #ifdef VOGEL_IF_IT_IS_OUTDATED_THEN_REMOVE_IT_GODDAMN_YEAH
00080 
00081 void CL_LockableSurface_GL::unlock()
00082 {
00083         glBindTexture(GL_TEXTURE_2D, m_texture);
00084         glTexSubImage2D(
00085                 GL_TEXTURE_2D,
00086                 0,
00087                 0,
00088                 0,
00089                 m_width,
00090                 m_height,
00091                 GL_RGBA,
00092                 GL_UNSIGNED_BYTE,
00093                 m_data);                        
00094 }
00095 
00096 void CL_LockableSurface_GL::set_colorkey(int colorkey)
00097 {
00098         m_colorkey = colorkey;
00099 }
00100 
00101 int CL_LockableSurface_GL::get_colorkey() const
00102 {
00103         return m_colorkey;
00104 }
00105 
00106 unsigned int CL_LockableSurface_GL::get_no_sprs() const
00107 {
00108         return m_no_sprs;
00109 }
00110 
00111 void CL_LockableSurface_GL::put_screen(
00112         int x,
00113         int y,
00114         int spr_no)
00115 {
00116         put_screen(x, y, (int) m_width, (int) m_height, spr_no);
00117 }
00118 
00119 void CL_LockableSurface_GL::put_screen(
00120         int x,
00121         int y,
00122         float scale_x,
00123         float scale_y,
00124         int spr_no)
00125 {
00126         put_screen(x, y, (int) (m_width * scale_x), (int) (m_height * scale_y), spr_no);
00127 }
00128 
00129 void CL_LockableSurface_GL::put_screen(
00130         int x,
00131         int y,
00132         int size_x,
00133         int size_y,
00134         int spr_no)
00135 {
00136         if (m_colorkey == -1)
00137         {
00138                 if (m_card->uses_gl())
00139                 {
00140                         cl_assert(false);
00141                 }
00142                 else
00143                 {
00144                         glBindTexture(GL_TEXTURE_2D, m_texture);
00145                         float h1 = ((float) m_height * spr_no) / m_texture_height;
00146                         float h2 = ((float) m_height * (spr_no+1)) / m_texture_height;
00147                         float w = (float) m_width / m_texture_width;
00148                         glBegin(GL_TRIANGLE_STRIP);
00149                                 glTexCoord2f(0.0, h1); glVertex2i(x, y);
00150                                 glTexCoord2f(  w, h1); glVertex2i(x + size_x, y);
00151                                 glTexCoord2f(0.0, h2); glVertex2i(x, y + size_y);
00152                                 glTexCoord2f(  w, h2); glVertex2i(x + size_x, y + size_y);
00153                         glEnd();
00154                         
00155                 }
00156         }
00157         else
00158         {
00159                 cl_info(info_display, "GL impl. cannot blit colorkey lockable surfaces... yet");
00160         }
00161 }
00162 
00163 #endif //USE_OPENGL
00164 */
00165 
00166 #endif // VOGEL_VOGEL_VOGEL
00167 #endif

Generated at Wed Apr 4 19:54:01 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001