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

display_ggi.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: display_ggi.cpp,v 1.2 2001/03/17 23:53:24 vaidhy 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 
00015 #include "Core/precomp.h"
00016 
00017 #ifdef USE_GGI
00018 
00019 
00020 #include <stdlib.h>
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <iostream>
00024 
00025 #include <linux/fb.h>
00026 #include <unistd.h>
00027 #include <fcntl.h>
00028 #include <sys/ioctl.h>
00029 #include <sys/mman.h>
00030 
00031 #include <math.h>
00032 
00033 #include <API/Display/Display/mousecursor.h>
00034 #include <API/Display/Display/cliprect.h>
00035 #include <API/Display/Display/palette.h>
00036 #include <API/Display/Display/vidmode.h>
00037 #include <API/Core/System/error.h>
00038 #include <API/Core/System/cl_assert.h>
00039 #include <Display/Display/Generic/colormap.h>
00040 #include <Display/Display/Generic/displaycard_generic.h>
00041 #include <Display/Display/GGI/display_ggi.h>
00042 #include <Display/Display/GGI/target_ggi.h>
00043 #include <Display/Display/GGI/target_ggi_db.h>
00044 #include <Display/Display/GGI/target_ggi_put.h>
00045 
00046 CL_GGI_DisplayCard::CL_GGI_DisplayCard(int card_no) : CL_DisplayCard_Generic(card_no)
00047 {
00048         m_initialized = false;
00049 
00050         m_palette = new CL_Palette();
00051 
00052         m_target = m_target2 = NULL;
00053 
00054         if (ggiInit())
00055         {
00056                 throw CL_Error( "CL_GGI_DisplayCard: Cannot initialize libGGI" );
00057         }
00058 
00059         vis = ggiOpen(NULL);
00060         if (!vis)
00061         {
00062                 ggiExit();
00063                 throw CL_Error( "CL_GGI_DisplayCard: Cannot open default visual, check GGI_DISPLAY env." );
00064         }
00065 }
00066 
00067 CL_GGI_DisplayCard::~CL_GGI_DisplayCard()
00068 {
00069         CL_MouseCursor::hide();
00070         if (m_initialized)
00071         {
00072                 if (m_target)           
00073                         delete m_target;
00074                 if (m_target2)
00075                         delete m_target2;
00076                 ggiClose(vis);
00077                 ggiExit();
00078         }
00079                 
00080         delete m_palette;
00081 }
00082 
00083 void CL_GGI_DisplayCard::flip_display(bool sync)
00084 {
00085         cl_assert(m_initialized); // card not initialized!
00086         
00087         signal_preflip();
00088 
00089 //      ggiFlush(vis);
00090 
00091         if (m_target2) // two frames (DirectBuffer)
00092         {
00093                 // swap them
00094                 CL_Target_GGI* temp;
00095                 temp      = m_target;
00096                 m_target  = m_target2;
00097                 m_target2 = temp;
00098 
00099                 m_target->to_back();   // does a ggiSetWriteFrame
00100                 m_target2->to_front(); // does a ggiSetDisplayFrame and a ggiFlush
00101         } else
00102         {
00103                 // only one frame (system memory)
00104                 m_target->to_back();  // does nothing
00105                 m_target->to_front(); // does a ggiFlush and a ggiPutBox, or first putbox?
00106         }
00107 
00108         signal_postflip();
00109 }
00110 
00111 void CL_GGI_DisplayCard::put_display(const class CL_Rect &rect)
00112 {
00113         cl_assert(m_initialized);
00114 
00115         signal_preflip();
00116 
00117         // not implemented. Someone with ggi knowledge, please do so.
00118         // -- mbn 21. nov 2000
00119         cl_assert(false);
00120 
00121         signal_postflip();
00122 }
00123 
00124 void CL_GGI_DisplayCard::set_palette(CL_Palette *pal)
00125 {
00126         m_palette = new CL_Palette(pal->palette);
00127 }
00128 
00129 CL_Palette *CL_GGI_DisplayCard::get_palette()
00130 {
00131         return m_palette;
00132 }
00133 
00134 void CL_GGI_DisplayCard::set_videomode(
00135         int width,
00136         int height,
00137         int bpp,
00138         bool fullscreen,
00139         bool allow_resize,
00140         bool video_memory)
00141 {
00142         if (m_initialized) // clean up
00143         {
00144                 if (m_target)           
00145                         delete m_target;
00146                 if (m_target2)
00147                         delete m_target2;
00148                 m_target = m_target2 = NULL;
00149         }
00150         
00151         set_gfxmode( width, height, bpp, fullscreen, allow_resize );
00152 
00153         ggiSetFlags( vis, GGIFLAG_ASYNC );
00154         
00155         switch (bpp)
00156         {
00157                 case     8: mode.graphtype = GT_8BIT ; break;
00158                 case    15: mode.graphtype = GT_15BIT; break;
00159                 case    16: mode.graphtype = GT_16BIT; break;
00160                 case    24: mode.graphtype = GT_24BIT; break;
00161                 case    32: mode.graphtype = GT_32BIT; break;
00162         }
00163         
00164         if (ggiSetSimpleMode(vis, get_width(), get_height(), 2, mode.graphtype))
00165         {
00166                 if (ggiSetSimpleMode(vis, get_width(), get_height(), 1, mode.graphtype))
00167                 {
00168                         ggiClose( vis );
00169                         ggiExit();
00170                         throw CL_Error ( "cannot set mode!" );
00171                 } else
00172                 {
00173                         // ok, we got one frame
00174                         m_target = new CL_Target_GGI_Put( vis );
00175                         std::cout << "Using non DirectBuffer capable target (one frame)" << std::endl;
00176                 }
00177         } else
00178         {
00179                 // cool, got two frames
00180                 if (ggiDBGetNumBuffers(vis)) // DirectBuffer capable?
00181                 {
00182                         m_target  = new CL_Target_GGI_DB( vis, 0 );
00183                         m_target2 = new CL_Target_GGI_DB( vis, 1 );
00184                         std::cout << "Using DirectBuffer capable target (two frames)" << std::endl;
00185                 } else
00186                 {
00187                         m_target = new CL_Target_GGI_Put( vis );
00188                         std::cout << "Using non DirectBuffer capable target (two frames, one used)" << std::endl;
00189                 }
00190         }
00191 
00192         m_initialized = true;
00193 }
00194 
00195 bool CL_GGI_DisplayCard::is_initialized()
00196 {
00197         return m_initialized;
00198 }
00199 
00200 const std::list<CL_VidMode*> &CL_GGI_DisplayCard::get_videomodes()
00201 {
00202         cl_assert(false); // not implemented yet!
00203         static std::list<CL_VidMode*> ret;
00204         return ret;
00205 }
00206 
00207 void CL_GGI_DisplayCard::draw_rect(
00208         int x1,
00209         int y1,
00210         int x2,
00211         int y2,
00212         float r,
00213         float g,
00214         float b,
00215         float a)
00216 {
00217         throw CL_Error("draw_rect not implemented in GGI, please tell us to do that");
00218 }
00219 
00220 void CL_GGI_DisplayCard::fill_rect(
00221         int x1,
00222         int y1,
00223         int x2,
00224         int y2,
00225         float r,
00226         float g,
00227         float b,
00228         float a)
00229 {
00230         if (a <= 0.01) return;
00231         if (a <= 0.99
00232                 || m_target2==NULL)
00233         {
00234                 CL_DisplayCard_Generic::fill_rect(x1, y1, x2, y2, r, g, b, a);
00235                 return;
00236         }
00237         
00238         // Translate coords into position:
00239         int trans_x = get_translate_offset_x();
00240         int trans_y = get_translate_offset_y();
00241         x1 += trans_x;
00242         y1 += trans_y;
00243         x2 += trans_x;
00244         y2 += trans_y;
00245 
00246 
00247         CL_ClipRect rect(x1, y1, x2, y2);
00248 
00249         CL_ClipRect cur_clip = get_clip_rect();
00250         if (cur_clip.test_all_clipped(rect))
00251         {
00252                 return;
00253         }
00254 
00255         CL_ClipRect crect = cur_clip.clip(rect);
00256         CL_ColorMap cmap(get_target());
00257         ggi_pixel pixelcolor = cmap.calc_color(r, g, b, a);
00258         
00259         ggiSetGCForeground( vis, pixelcolor );
00260         ggiDrawBox( vis, crect.m_x1, crect.m_y1, crect.m_x2 - crect.m_x1, crect.m_y2 - crect.m_y1 );
00261 }
00262 
00263 void CL_GGI_DisplayCard::draw_line(
00264         int x1,
00265         int y1,
00266         int x2,
00267         int y2,
00268         float r,
00269         float g,
00270         float b,
00271         float a)
00272 {
00273         // Translate coords into position:
00274         int trans_x = get_translate_offset_x();
00275         int trans_y = get_translate_offset_y();
00276         x1 += trans_x;
00277         y1 += trans_y;
00278         x2 += trans_x;
00279         y2 += trans_y;
00280 
00281         CL_ClipRect rect(x1, y1, x2, y2);
00282 
00283         CL_ClipRect cur_clip = get_clip_rect();
00284         if (cur_clip.test_all_clipped(rect))
00285         {
00286                 return;
00287         }
00288 
00289         CL_ClipRect crect = cur_clip.clip(rect);
00290         CL_ColorMap cmap(get_target());
00291         ggi_pixel pixelcolor = cmap.calc_color(r, g, b, a);
00292         
00293         ggiSetGCForeground( vis, pixelcolor );
00294         ggiDrawLine( vis, crect.m_x1, crect.m_y1, crect.m_x2 - crect.m_x1, crect.m_y2 - crect.m_y1 );
00295 }
00296 
00297 
00298 void CL_GGI_DisplayCard::clear_display(
00299         float red,
00300         float green,
00301         float blue,
00302         float alpha)
00303 {
00304 //      if (alpha <= 0.99)
00305         {
00306                 fill_rect(
00307                         0,
00308                         0,
00309                         get_width(),
00310                         get_height(),
00311                         red,
00312                         green,
00313                         blue,
00314                         alpha);
00315                 return;
00316         }
00317         
00318 /*      CL_ColorMap cmap(get_target());
00319         ggi_pixel pixelcolor = cmap.calc_color(red, green, blue, alpha);
00320         
00321         ggiSetGCForeground( vis, pixelcolor );
00322         ggiFillscreen( vis );*/
00323 }
00324 
00325 #endif

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