[Gcblue-commits] gcb_wx/src/graphics tc3DWindow.cpp,1.13,1.14 tcGraphicsEngine.cpp,1.20,1.21 tcMapVi
Status: Alpha
Brought to you by:
ddcforge
Update of /cvsroot/gcblue/gcb_wx/src/graphics In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18469/src/graphics Modified Files: tc3DWindow.cpp tcGraphicsEngine.cpp tcMapView.cpp tcTerrainView.cpp Removed Files: extgl.c tc2DGraphicsSurface.cpp tcWindow.cpp Log Message: Final GDI+ removal --- tcWindow.cpp DELETED --- Index: tcMapView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcMapView.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** tcMapView.cpp 27 Jan 2005 01:01:49 -0000 1.15 --- tcMapView.cpp 20 Feb 2005 21:54:33 -0000 1.16 *************** *** 303,307 **** } ! /***********************************************************************************/ void tcMapView::SetActive(bool abActive) { --- 303,309 ---- } ! /** ! * ! */ void tcMapView::SetActive(bool abActive) { *************** *** 309,320 **** terrainView->SetActive(abActive); } - /***********************************************************************************/ - /* - void tcMapView::SetWindow(RECT& r) { - tcWindow::SetWindow(r); // call base class to set tcMapView's window - terrainView->SetWindow(r); - } - */ --- 311,320 ---- terrainView->SetActive(abActive); } + void tcMapView::SetBaseRenderBin(int n) + { + tc3DWindow::SetBaseRenderBin(n); + terrainView->SetBaseRenderBin(n - 10); + } *************** *** 620,623 **** --- 620,624 ---- terrainView->SetView(mrectCurrentView); + terrainView->Draw(); tcMapObject::SetMapView(this); *************** *** 681,685 **** vp.mnSurfaceWidth,vp.mnSurfaceHeight, vp.mrectGeo.left,vp.mrectGeo.right,vp.mrectGeo.bottom,vp.mrectGeo.top, ! vp.mrectDisplay.X, vp.mrectDisplay.Y, vp.mrectDisplay.Width, vp.mrectDisplay.Height); DrawTextR(sText.GetBuffer(), leftMargin + 50.0, 80.0, defaultFont.get(), color, 16.0, LEFT_BASE_LINE); --- 682,687 ---- vp.mnSurfaceWidth,vp.mnSurfaceHeight, vp.mrectGeo.left,vp.mrectGeo.right,vp.mrectGeo.bottom,vp.mrectGeo.top, ! vp.mrectDisplay.left, vp.mrectDisplay.bottom, ! vp.mrectDisplay.Width(), vp.mrectDisplay.Height()); DrawTextR(sText.GetBuffer(), leftMargin + 50.0, 80.0, defaultFont.get(), color, 16.0, LEFT_BASE_LINE); *************** *** 2438,2442 **** // done here to avoid artifacts from terrainview being out of sync with mapview terrainView->SetView(mrectCurrentView); ! if (mnWidth == iconSize) --- 2440,2445 ---- // done here to avoid artifacts from terrainview being out of sync with mapview terrainView->SetView(mrectCurrentView); ! ! terrainView->Draw(); if (mnWidth == iconSize) Index: tcTerrainView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcTerrainView.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tcTerrainView.cpp 2 Nov 2004 04:23:56 -0000 1.2 --- tcTerrainView.cpp 20 Feb 2005 21:54:33 -0000 1.3 *************** *** 30,36 **** #include "tcTerrainView.h" - #include "aerror.h" - #include "tcGraphicsEngine.h" #include "tcOptions.h" #ifdef _DEBUG --- 30,35 ---- #include "tcTerrainView.h" #include "tcOptions.h" + #include <osg/Texture2D> #ifdef _DEBUG *************** *** 38,45 **** #endif - using namespace Gdiplus; namespace MapView { void tcTerrainView::GetViewParameters(tsTerrainViewParameters& vp) --- 37,52 ---- #endif namespace MapView { + void tcTerrainView::Draw() + { + if (!redraw) return; + DrawZoomedImage(mapImage.get(), 0, 0, (float)mnWidth, (float)mnHeight, + displayRegion, ALIGN_BOTTOM_LEFT); + + FinishDraw(); + redraw = false; + } void tcTerrainView::GetViewParameters(tsTerrainViewParameters& vp) *************** *** 51,92 **** } ! /** ! * If the terrain view is minimized always force ! * abActive to false ! */ ! void tcTerrainView::SetActive(bool abActive) ! { ! if (IsWindowMinimized()) ! { ! tcWindow::SetActive(false); ! } ! tcWindow::SetActive(abActive); ! } /** ! * update display region of mp2DSurface */ ! void tcTerrainView::SetView(tcGeoRect r) { ! RectF rdisp; ! float fSurfaceWidth, fSurfaceHeight; // surface coordinate dimensions ! if (mrectCurrentView == r) return; mrectCurrentView = r; ! if (mp2DSurface == NULL) {return;} ! fSurfaceWidth = (float)mp2DSurface->mnWidth; ! fSurfaceHeight = (float)mp2DSurface->mnHeight; ! // assumes longitude is within [-pi,pi) and lat within [-pi/2,pi/2] ! rdisp.X = (fSurfaceWidth)*(r.left - mrectMap.left)/mrectMap.Width(); ! rdisp.Width = ((fSurfaceWidth)*(r.right - mrectMap.left)/mrectMap.Width()) - rdisp.X; ! rdisp.Y = (fSurfaceHeight)*(r.bottom - mrectMap.bottom)/mrectMap.Height(); ! rdisp.Height = (fSurfaceHeight)*(r.top - mrectMap.bottom)/mrectMap.Height() - rdisp.Y; ! SetDisplayRegion(rdisp); /* ! fprintf(stdout, "setting terrain to view L:%f R:%f T:%f B:%f\n", r.left, r.right, r.top, r.bottom); ! fprintf(stdout, " terrain window L:%d R:%d T:%d B:%d\n", ! mrectWindow.left, mrectWindow.right, mrectWindow.top, mrectWindow.bottom); */ ! //mp2DSurface->SetDisplayRegion(rdisp.x1,rdisp.y1,rdisp.x2,rdisp.y2); } --- 58,106 ---- } ! /** ! * If the terrain view is minimized always force ! * abActive to false ! */ ! void tcTerrainView::SetActive(bool abActive) ! { ! if (IsWindowMinimized()) ! { ! tc3DWindow::SetActive(false); ! } ! tc3DWindow::SetActive(abActive); ! } /** ! * */ ! void tcTerrainView::SetDisplayRegion(tcRect& r) { ! displayRegion = r; ! } ! /** ! * Sets new view, updating display region of map quad ! */ ! void tcTerrainView::SetView(tcGeoRect r) ! { ! if (mrectCurrentView == r) return; // no change, so return mrectCurrentView = r; ! /* ! float surfaceWidth, surfaceHeight; // surface coordinate dimensions ! osg::Image* image = mapImage->getImage(); ! wxASSERT(image); ! ! surfaceWidth = (float)image->s(); ! surfaceHeight = (float)image->t(); */ ! ! // assumes longitude is within [-pi,pi) and lat within [-pi/2,pi/2] ! displayRegion.left = (r.left - mrectMap.left)/mrectMap.Width(); ! displayRegion.right = (r.right - mrectMap.left)/mrectMap.Width(); ! displayRegion.bottom = (r.bottom - mrectMap.bottom)/mrectMap.Height(); ! displayRegion.top = (r.top - mrectMap.bottom)/mrectMap.Height(); ! ! redraw = true; } *************** *** 100,122 **** /*** Refresh low resolution map surface ***/ ! mnWidth = sMDI.mnLowResWidth; //mrectWindow.right - mrectWindow.left; // assumes SetWindow called first ! mnHeight = sMDI.mnLowResHeight; //mrectWindow.bottom - mrectWindow.top; ! if (yMirror) ! { ! mp2DSurface->SetWindow(mrectWindow.left, yMirror - mrectWindow.bottom, ! mrectWindow.right, yMirror - mrectWindow.top); ! } ! else { ! mp2DSurface->SetWindow(mrectWindow.left, mrectWindow.top, ! mrectWindow.right, mrectWindow.bottom); } mpMapData->GetWorldArea(mrectMap); - if (mp2DSurface->Init(sMDI.mnLowResWidth, sMDI.mnLowResHeight) != true) {return false;} - mp2DSurface->SetDisplayRegion(0,0,(float)sMDI.mnLowResWidth,(float)sMDI.mnLowResHeight); ! UINT32 *pBits; ! mp2DSurface->GetBits(pBits); wxASSERT(pBits != NULL); --- 114,133 ---- /*** Refresh low resolution map surface ***/ ! int width = sMDI.mnLowResWidth; ! int height = sMDI.mnLowResHeight; ! ! osg::Image* image = mapImage->getImage(); ! if (!image) { ! image = new osg::Image(); ! mapImage->setImage(image); } + image->allocateImage(width, height, 1, GL_RGBA, GL_BYTE, 1); + mpMapData->GetWorldArea(mrectMap); ! unsigned int* pBits = (unsigned int*) image->data(); ! wxASSERT(pBits != NULL); *************** *** 124,137 **** { mpMapData->CreateMapImage(mpOptions->mnMapMode, 0, pBits); - mp2DSurface->mbModified = true; } else { ! WTL("tcTerrainView::LoadLowResSurface - called without attached options, using default"); mpMapData->CreateMapImage(1, 0, pBits); } ! mp2DSurface->SetRenderTexture(true); ! mp2DSurface->mbModified = true; return true; --- 135,147 ---- { mpMapData->CreateMapImage(mpOptions->mnMapMode, 0, pBits); } else { ! fprintf(stderr, "tcTerrainView::LoadLowResSurface - " ! "called without attached options, using default\n"); mpMapData->CreateMapImage(1, 0, pBits); } ! redraw = true; return true; *************** *** 154,192 **** mpMapData->GetMapDataInfo(&sMDI); // get size of map data arrays ! /*** Update high resolution map surface ***/ ! if (yMirror) ! { ! mp2DSurface->SetWindow(mrectWindow.left, yMirror - mrectWindow.bottom, ! mrectWindow.right, yMirror - mrectWindow.top); ! } ! else { ! mp2DSurface->SetWindow(mrectWindow.left, mrectWindow.top, ! mrectWindow.right, mrectWindow.bottom); } mpMapData->GetTheaterArea(mrectMap); ! if (mp2DSurface->Init(sMDI.mnHighResWidth,sMDI.mnHighResHeight) != true) {return false;} ! mp2DSurface->SetDisplayRegion(0,0,(float)sMDI.mnHighResWidth,(float)sMDI.mnHighResHeight); ! UINT32 *pBits; ! mp2DSurface->GetBits(pBits); ! wxASSERT(pBits != NULL); ! //mpMapData->CreateHighResMapImage(mpOptions->mnMapMode, pBits); ! mpMapData->CreateMapImage(mpOptions->mnMapMode, 1, pBits); // 1 for high res ! mp2DSurface->mbModified = true; ! mp2DSurface->SetRenderTexture(mbTextureMaps); return true; } ! /** ! * call tcWindow::SetActive(false) on Minimize() ! */ ! void tcTerrainView::Minimize() ! { ! tcWindow::SetActive(false); ! tcWindow::Minimize(); ! } int tcTerrainView::RefreshSurfaces() --- 164,201 ---- mpMapData->GetMapDataInfo(&sMDI); // get size of map data arrays ! int width = sMDI.mnHighResWidth; ! int height = sMDI.mnHighResHeight; ! ! osg::Image* image = mapImage->getImage(); ! if (!image) { ! image = new osg::Image(); ! mapImage->setImage(image); } + image->allocateImage(width, height, 1, GL_RGBA, GL_BYTE, 1); + mpMapData->GetTheaterArea(mrectMap); ! ! unsigned int* pBits = (unsigned int*) image->data(); ! ! wxASSERT(pBits); ! ! mpMapData->CreateMapImage(mpOptions->mnMapMode, 1, pBits); // 1 for high res ! ! redraw = true; return true; } ! /** ! * call tcWindow::SetActive(false) on Minimize() ! */ ! void tcTerrainView::Minimize() ! { ! tc3DWindow::SetActive(false); ! tc3DWindow::Minimize(); ! } int tcTerrainView::RefreshSurfaces() *************** *** 197,201 **** return false; } ! if (mbHighRes) { return LoadHighResSurface(); --- 206,210 ---- return false; } ! if (highRes) { return LoadHighResSurface(); *************** *** 209,215 **** /** ! * overridden to create surface larger than window */ ! int tcTerrainView::CreateSurfaces(tcGraphicsEngine* apGraphicsEngine) { if (mpMapData == NULL) --- 218,224 ---- /** ! * */ ! int tcTerrainView::CreateSurfaces() { if (mpMapData == NULL) *************** *** 218,224 **** return false; } - if (apGraphicsEngine->Create2DSurface(mp2DSurface) == false) {return false;} ! if (mbHighRes) { return LoadHighResSurface(); --- 227,232 ---- return false; } ! if (highRes) { return LoadHighResSurface(); *************** *** 230,247 **** } ! ////////////////////////////////////////////////////////////////////// ! // Construction/Destruction ! ////////////////////////////////////////////////////////////////////// tcTerrainView::tcTerrainView(wxWindow *parent, const wxPoint& pos, const wxSize& size, ! bool isHighRes, ! const wxString& name) : ! mbHighRes(isHighRes), ! tcWindow(parent, pos, size, name) { mpMapData = NULL; ! mpOptions = NULL; SetResizeable2D(false); // do not resize 2D surface on resize } --- 238,258 ---- } ! tcTerrainView::tcTerrainView(wxWindow *parent, const wxPoint& pos, const wxSize& size, ! bool isHighRes, const wxString& name) ! : ! tc3DWindow(parent, pos, size, name, 0), ! highRes(isHighRes), ! displayRegion(0, 1, 0, 1), ! redraw(true) { mpMapData = NULL; ! mpOptions = tcOptions::Get(); SetResizeable2D(false); // do not resize 2D surface on resize + mapImage = new osg::Texture2D(); + + SetBlend(false); } Index: tcGraphicsEngine.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcGraphicsEngine.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** tcGraphicsEngine.cpp 1 Nov 2004 03:17:18 -0000 1.20 --- tcGraphicsEngine.cpp 20 Feb 2005 21:54:33 -0000 1.21 *************** *** 55,151 **** using std::cout; - bool tcGraphicsEngine::Create2DSurface(tc2DGraphicsSurface*& rp2DSurface) - { - if (mn2D >= MAX_2D_SURFACES) - { - wxMessageBox("tcGraphicsEngine - Max 2D surfaces exceeded"); - return false; - } - rp2DSurface = new tc2DGraphicsSurface; - if (rp2DSurface == NULL) - { - wxMessageBox("tcGraphicsEngine - Failed to allocated 2D surface memory"); - return false; - } - rp2DSurface->mnID = mn2D; - ma2D[mn2D++] = rp2DSurface; - return true; - } - - /** - * - */ - void tcGraphicsEngine::DeleteAllSurfaces() - { - unsigned int n; - - for(n=0;n<mn2D;n++) - { - if (ma2D[n] != NULL) - { - delete ma2D[n]; - ma2D[n] = NULL; - } - } - mn2D = 0; - } - - /** - * Moves surface to last in the drawing order so that surface - * is drawn on top of other surfaces. - * @return false if surface not found - */ - bool tcGraphicsEngine::MoveSurfaceToTop(tc2DGraphicsSurface* ap2DSurface) - { - unsigned n, nRaise; - bool bFound; - bFound = false; - for(n=0;(n<mn2D)&&(!bFound);n++) - { - if (ma2D[n] == ap2DSurface) - { - nRaise = n; - bFound = true; - } - } - if (!bFound) {return false;} - - tc2DGraphicsSurface *temp = ma2D[nRaise]; - - // move higher surfaces down one position - for(n=nRaise;n<mn2D-1;n++) - { - ma2D[n] = ma2D[n+1]; - } - ma2D[mn2D-1] = temp; // move to last (top) position - - return true; - } - - bool tcGraphicsEngine::Delete2DSurface(tc2DGraphicsSurface* ap2DSurface) - { - unsigned n, nDelete; - bool bFound; - - bFound = false; - for(n=0;(n<mn2D)&&(!bFound);n++) - { - if (ma2D[n] == ap2DSurface) - { - nDelete = n; - bFound = true; - } - } - if (!bFound) {return false;} - delete ma2D[nDelete]; - ma2D[nDelete] = NULL; - mn2D--; - for(n=nDelete;n<mn2D;n++) - { - ma2D[n] = ma2D[n+1]; - } - return true; - } tcGraphicsEngine* tcGraphicsEngine::Get() --- 55,59 ---- *************** *** 187,211 **** - // creates pixel maps for - bool tcGraphicsEngine::CreatePixelMaps() - { - const int nMapSize = 1024; - GLfloat afMap[nMapSize]; - - for(int n=0;n<nMapSize;n++) - { - afMap[n] = (float)n/(float)nMapSize; - } - glPixelMapfv(GL_PIXEL_MAP_I_TO_R,nMapSize,afMap); - glPixelMapfv(GL_PIXEL_MAP_I_TO_G,nMapSize,afMap); - glPixelMapfv(GL_PIXEL_MAP_I_TO_B,nMapSize,afMap); - - for(int n=0;n<nMapSize;n++) - { - afMap[n] = 1.0f; - } - glPixelMapfv(GL_PIXEL_MAP_I_TO_A,nMapSize,afMap); - return true; - } /** --- 95,98 ---- *************** *** 289,748 **** - /** - * loads a bmp image - */ - AUX_RGBImageRec* tcGraphicsEngine::LoadBmp(char *szFileName) - { - tcFile file; - - if (szFileName==NULL) {return NULL;} - if (file.Open(szFileName,tcFile::modeRead)) // check if file exists - { - file.Close(); - } - else - { - return NULL; - } - return auxDIBImageLoad(szFileName); // load the bmp and return ptr to bmp - } - - void tcGraphicsEngine::GetInfo(tsGraphicsEngineInfo& asGI) - { - asGI.mbTexture = mbTexture; - asGI.mbWireFrame = mbWireFrame; - } - - - - void tcGraphicsEngine::ConfigureFor2D() - { - if (meGraphicsMode == MODE_2D) {return;} - - // see Google groups: "Re: OpenGL PixelDraw slow??" Allen Akin, 1995/07/14 - glDisable(GL_ALPHA_TEST); - glDisable(GL_DEPTH_TEST); - glDisable(GL_DITHER); - glDisable(GL_FOG); - glDisable(GL_LIGHTING); - glDisable(GL_LOGIC_OP); - glDisable(GL_STENCIL_TEST); - glDisable(GL_TEXTURE_1D); - glDisable(GL_TEXTURE_2D); - glPixelTransferi(GL_MAP_COLOR, GL_FALSE); - glPixelTransferi(GL_RED_SCALE, 1); - glPixelTransferi(GL_RED_BIAS, 0); - glPixelTransferi(GL_GREEN_SCALE, 1); - glPixelTransferi(GL_GREEN_BIAS, 0); - glPixelTransferi(GL_BLUE_SCALE, 1); - glPixelTransferi(GL_BLUE_BIAS, 0); - glPixelTransferi(GL_ALPHA_SCALE, 1); - glPixelTransferi(GL_ALPHA_BIAS, 0); - - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background - glEnable(GL_SCISSOR_TEST); - - if (mbBlend) - { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - else - { - glDisable(GL_BLEND); // Turn Blending Off - } - meGraphicsMode = MODE_2D; - } - - - void tcGraphicsEngine::ConfigureForTexture2D() - { - if (meGraphicsMode == MODE_TEXTURE2D) {return;} - glMatrixMode(GL_PROJECTION); // Select The Projection Matrix - glLoadIdentity(); // Reset The Projection Matrix - glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix - glLoadIdentity(); - - glClearColor(0.00f, 0.00f, 0.00f, 0.0f); // Black Background - glDisable(GL_DEPTH_TEST); - glDisable(GL_ALPHA_TEST); - glDisable(GL_DITHER); - glEnable(GL_SCISSOR_TEST); - - // glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations - glEnable(GL_TEXTURE_2D); // Enable texture mapping - glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); - - glDisable(GL_LIGHTING); - if (mbBlend) - { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - else - { - glDisable(GL_BLEND); - } - - meGraphicsMode = MODE_TEXTURE2D; - - CheckGLError("ConfigureForTexture2D - end"); - } - - - #if 0 - void tcGraphicsEngine::RenderBorder(ts3dGraphicsData *apGD) - { - if (apGD == NULL) {return;} - - int nWidth = apGD->r.right - apGD->r.left; - int nHeight = apGD->r.bottom-apGD->r.top; - - glMatrixMode(GL_PROJECTION); // Select The Projection Matrix - glLoadIdentity(); // Reset The Projection Matrix - gluOrtho2D((GLint)0, (GLint)nWidth, - (GLint)0, (GLint)nHeight); // Set the current viewport - - glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix - glLoadIdentity(); - - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - - glDisable(GL_LIGHTING); - glDisable(GL_DEPTH_TEST); - - glColor4f(1.0f,1.0f,1.0f,1.0f); - - glBegin(GL_QUADS); - glVertex2i(0,0); - glVertex2i(nWidth,0); - glVertex2i(nWidth,nHeight); - glVertex2i(0,nHeight); - glEnd(); - - - if (!mbWireFrame) - { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - } - if (mbLight) - { - glEnable(GL_LIGHTING); - } - glEnable(GL_DEPTH_TEST); - } - #endif - - - /** - * glDrawPixels rendering of 2D surface - */ - void tcGraphicsEngine::Render2D(unsigned anSurface) - { - tsGraphicsParameters gp; - int nViewWidth,nViewHeight; - static float fz = 0; - - if (anSurface >= mn2D) {return;} - if (ma2D[anSurface] == NULL) {return;} - ma2D[anSurface]->GetParameters(gp); // retrieve window info and pixel pointer - if (gp.mbActive == false) {return;} // return without drawing if mbActive is false - nViewWidth = gp.rviewport.right-gp.rviewport.left; - nViewHeight = gp.rviewport.bottom-gp.rviewport.top; - - ConfigureFor2D(); - if (gp.mbBlend) - { - glEnable(GL_BLEND); - } - else - { - glDisable(GL_BLEND); - } - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluOrtho2D (0, (GLfloat)gp.mnSurfaceWidth, 0 , (GLfloat)gp.mnSurfaceHeight); - glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix - glLoadIdentity(); - glScissor((GLint)gp.rviewport.left, (GLint)gp.rviewport.top, - (GLsizei)nViewWidth, (GLsizei)nViewHeight); // Set the current viewport - glViewport((GLint)gp.rviewport.left, (GLint)gp.rviewport.top, - (GLsizei)nViewWidth, (GLsizei)nViewHeight); // Set the current viewport - if (gp.mbClearViewport) { - glClear(GL_COLOR_BUFFER_BIT); - } - glRasterPos2i(0,0); - if (gp.mbZoomActive) { - float fX,fY,fZoomX,fZoomY; // lower left corner to render - // zooming subpixel causes problems, improve this later - if ((gp.rdisplay.x2 - gp.rdisplay.x1) <= 2.0f) { - gp.rdisplay.x2 = gp.rdisplay.x1 + 1.5f; - } - if ((gp.rdisplay.y2 - gp.rdisplay.y1) <= 2.0f) { - gp.rdisplay.y2 = gp.rdisplay.y1 + 1.5f; - } - fZoomX = ((GLfloat)nViewWidth)/(gp.rdisplay.x2 - gp.rdisplay.x1); - fZoomY = ((GLfloat)nViewHeight)/(gp.rdisplay.y2 - gp.rdisplay.y1); - if (gp.mbFlipUpDown) { - fX = -fZoomX*gp.rdisplay.x1; - fY = -fZoomY*(gp.rdisplay.y1-(GLfloat)nViewHeight); - } - else { - fX = -fZoomX*gp.rdisplay.x1; //*(GLfloat)gp.mnSurfaceWidth/(GLfloat)nViewWidth; - fY = -fZoomY*gp.rdisplay.y1; //*(GLfloat)gp.mnSurfaceHeight/(GLfloat)nViewHeight; - } - glBitmap (0, 0, 0, 0, fX, fY, NULL); // can't use glRasterPos for this - if (gp.mbFlipUpDown) { - glPixelZoom((GLfloat)fZoomX,(GLfloat)-fZoomY); - } - else { - glPixelZoom((GLfloat)fZoomX,(GLfloat)fZoomY); - } - } - else { - glPixelZoom((GLfloat)1.0,(GLfloat)1.0); - } - if (gp.ppixels != NULL) { - if (gp.mePixelFormat == RGBA) - { - // actually using BGRA which is supposed to be faster on windows - glDrawPixels(gp.mnSurfaceWidth,gp.mnSurfaceHeight, - GL_BGRA_EXT,GL_UNSIGNED_BYTE,gp.ppixels); - } - else if (gp.mePixelFormat == I16) { - glDrawPixels(gp.mnSurfaceWidth/2,gp.mnSurfaceHeight, - GL_BGRA_EXT,GL_UNSIGNED_BYTE,gp.ppixels); // error caused if read out of bounds!? - - } - - } - } - - /** - * texture mapped rendering of 2D surface - */ - void tcGraphicsEngine::RenderTexture2D(unsigned anSurface) - { - int m,n; - int nWidth,nHeight; - tsGraphicsParameters gp; - static int nCounter = 0; - - if ((unsigned)anSurface >= mn2D) {return;} - if (ma2D[anSurface] == NULL) {return;} - ma2D[anSurface]->GetParameters(gp); // retrieve window info and pixel pointer - if (gp.mbActive == false) {return;} // return without drawing if mbActive is false - nWidth = gp.rviewport.right-gp.rviewport.left; - nHeight = gp.rviewport.bottom-gp.rviewport.top; - - ConfigureForTexture2D(); - - glScissor((GLint)gp.rviewport.left, (GLint)gp.rviewport.top, - (GLsizei)nWidth, (GLsizei)nHeight); // Set the current viewport - glViewport((GLint)gp.rviewport.left, (GLint)gp.rviewport.top, - (GLsizei)nWidth, (GLsizei)nHeight); // Set the current viewport - - CheckGLError("RenderTexture2D - viewport"); - - //glClear(GL_COLOR_BUFFER_BIT); // glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); - glMatrixMode(GL_PROJECTION); // Select The Projection Matrix - glLoadIdentity(); // Reset The Projection Matrix - - gluOrtho2D (gp.rdisplay.x1, gp.rdisplay.x2, - gp.rdisplay.y1, gp.rdisplay.y2); - - glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix - glLoadIdentity(); - - CheckGLError("RenderTexture2D - matrix"); - - float mfPaneX,mfPaneY,mfPaneZ; - float x1,y1,x2,y2,xstart,ystart; - int nTextureIdx; - mfPaneZ = 0; - mfPaneX = (float)(gp.pTextureData->mnTextureSize-gp.pTextureData->mnTextureOverlap); - mfPaneY = (float)(gp.pTextureData->mnTextureSize-gp.pTextureData->mnTextureOverlap); - xstart = 0.5f*(float)gp.pTextureData->mnTextureOverlap; - ystart = xstart; - //int nTexOverlap = gp.pTextureData->mnTextureOverlap; - // float doverlap = nTexOverLap - tcString s; - - if (!gp.pTextureData->mbLoaded) { - Load2DSurfaceTextures(anSurface); - } - else if (gp.mbModified) { - Load2DSurfaceTextures(anSurface); - ma2D[anSurface]->ClearModified(); - } - - float texa = xstart/mfPaneX; - float texb = 1.0f - texa; - - for(m=0;m<gp.pTextureData->mnRows;m++) { - y1 = ystart + (float)m*mfPaneY; - y2 = y1 + mfPaneY; - // textop = (m == 0) ? 1.0f : - for(n=0;n<gp.pTextureData->mnCols;n++) { - nTextureIdx = m*gp.pTextureData->mnCols + n; - x1 = xstart + (float)n*mfPaneX; - x2 = x1 + mfPaneX; - - glBindTexture(GL_TEXTURE_2D,gp.pTextureData->maTexture[nTextureIdx]); - glBegin(GL_QUADS); - /* - glTexCoord2f(0.00f, 0.00f); glVertex3f(x1, y1, 0); - glTexCoord2f(1.00f, 0.00f); glVertex3f(x2, y1, 0); - glTexCoord2f(1.00f, 1.00f); glVertex3f(x2, y2, 0); - glTexCoord2f(0.00f, 1.00f); glVertex3f(x1, y2, 0); - */ - glTexCoord2f(texa, texa); glVertex3f(x1, y1, 0); - glTexCoord2f(texb, texa); glVertex3f(x2, y1, 0); - glTexCoord2f(texb, texb); glVertex3f(x2, y2, 0); - glTexCoord2f(texa, texb); glVertex3f(x1, y2, 0); - - glEnd(); - - } - } - CheckGLError("RenderTexture2D - end"); - } - - /** - * update msTextureData structure of surface with surface bitmap data - * delete old textures if loaded - */ - void tcGraphicsEngine::Load2DSurfaceTextures(int anSurface) - { - tsGraphicsParameters gp; - int m,n; - int nWidth,nHeight; - tsBmp32 sBmp32; - UINT32 *aTextureData; - int nTextureSize, nTextureIdx; - - if ((unsigned)anSurface >= mn2D) {return;} - if (ma2D[anSurface] == NULL) {return;} - ma2D[anSurface]->GetParameters(gp); // retrieve window info and pixel pointer - nWidth = gp.mnSurfaceWidth; //gp.rviewport.right-gp.rviewport.left; - nHeight = gp.mnSurfaceHeight; //gp.rviewport.bottom-gp.rviewport.top; - - nTextureSize = gp.pTextureData->mnTextureSize; - sBmp32.mnWidth = nWidth; - sBmp32.mnHeight = nHeight; - sBmp32.mpPixels = (UINT32*)gp.ppixels; - int nTexSpacing = gp.pTextureData->mnTextureSize - - gp.pTextureData->mnTextureOverlap; - aTextureData = new UINT32[nTextureSize*nTextureSize]; - if (aTextureData == NULL) {return;} - - // delete old textures if they exist - if (gp.pTextureData->mbLoaded) { - glDeleteTextures(gp.pTextureData->mnTextures,gp.pTextureData->maTexture); - } - // generate new texture IDs - glGenTextures(gp.pTextureData->mnTextures,gp.pTextureData->maTexture); - // load texture data with glTextImage2D - for(m=0;m<gp.pTextureData->mnRows;m++) { - for(n=0;n<gp.pTextureData->mnCols;n++) { - nTextureIdx = m*gp.pTextureData->mnCols + n; - glBindTexture(GL_TEXTURE_2D, gp.pTextureData->maTexture[nTextureIdx]); - - ExtractTile(&aTextureData[0], sBmp32, nTextureSize, m*nTexSpacing, n*nTexSpacing); - - if (mbMipMapTextures) { - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); - gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA8, nTextureSize, nTextureSize, - GL_RGBA, GL_UNSIGNED_BYTE, &aTextureData[0]); - } - else { - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nTextureSize, nTextureSize, 0, - GL_RGBA, GL_UNSIGNED_BYTE, &aTextureData[0]); - } - - } - } - delete aTextureData; - gp.pTextureData->mbLoaded = true; - - } - - void tcGraphicsEngine::ExtractTile(UINT32 *apTile, tsBmp32 asBmp, - unsigned anTileSize, int anStartRow, int anStartCol) - { - int nWidth,nHeight; - int nRow,nCol,nStartRow,nStartCol; - UINT32 *pPixels; // assumed 32 bits per pixel bitmap format - if ((apTile==NULL)||(asBmp.mpPixels==NULL)) {return;} - - nWidth = asBmp.mnWidth; - nHeight = asBmp.mnHeight; - - - pPixels = (UINT32*)asBmp.mpPixels; - nStartRow = anStartRow; - nStartCol = anStartCol; - /* - for (nRow=nStartRow;(nRow<nStartRow+anTileSize)&&(nRow<(unsigned)nHeight);nRow++) { - memcpy(apTile+(nRow-nStartRow)*anTileSize,pPixels+(nRow*nWidth)+nStartCol, - sizeof(UINT32)*anTileSize); - // memcpy(apTile+(nRow-nStartRow)*anTileSize,pPixels,anTileSize); - } - */ - for (nRow=nStartRow;nRow<nStartRow+(int)anTileSize;nRow++) { - for (nCol=nStartCol;nCol<nStartCol+(int)anTileSize;nCol++) { - if ((nRow < nHeight)&&(nCol < nWidth)) { - *(apTile + (nRow-nStartRow)*anTileSize + nCol - nStartCol) = - *(pPixels + (nRow*nWidth) + nCol); - } - else { - *(apTile + (nRow-nStartRow)*anTileSize + nCol - nStartCol) = 0xFF000000; - } - } - } - } - - - - bool tcGraphicsEngine::RenderAll() - { - unsigned n; - static unsigned nCounter = 0; - - if (!mbInitialized) {return false;} - - - CheckGLError("pre render"); - - // save GL state so as not to interfere with OSG, may not need all of these flags - glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_FOG_BIT | GL_LIGHTING_BIT); - glPushMatrix(); - - meGraphicsMode = MODE_NONE; // clear mode to set state properly after OSG rendering - - // render 2d windows - for(n=0;n<mn2D;n++) - { - if (mbTexture2D&&(ma2D[n]->mbRenderTexture)) - { - RenderTexture2D(n); - } - else - { - Render2D(n); - } - } - - glPopMatrix(); - glPopAttrib(); - - CheckGLError("post render"); - - return true; - } --- 176,179 ---- *************** *** 824,850 **** } - ////////////////////////////////////////////////////////////////////// - // Construction/Destruction - ////////////////////////////////////////////////////////////////////// tcGraphicsEngine::tcGraphicsEngine() { - int n; - - for(n=0;n<MAX_2D_SURFACES;n++) - { - ma2D[n] = NULL; - } - - mn2D = 0; - mbInitialized = true; - mbBlend = true; - mbTexture = true; - mbTexture2D = true; - mbPerspective2D = false; - mbWireFrame = false; - mbMipMapTextures = true; - meGraphicsMode = MODE_NONE; LogGLInfo(); --- 255,262 ---- *************** *** 880,886 **** tcGraphicsEngine::~tcGraphicsEngine() { - /* will cause exception if called after Gdiplus is unintialized - if there are any surfaces remaining */ - DeleteAllSurfaces(); } --- 292,295 ---- --- tc2DGraphicsSurface.cpp DELETED --- --- extgl.c DELETED --- Index: tc3DWindow.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tc3DWindow.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** tc3DWindow.cpp 21 Dec 2004 02:26:17 -0000 1.13 --- tc3DWindow.cpp 20 Feb 2005 21:54:33 -0000 1.14 *************** *** 859,862 **** --- 859,930 ---- } + /** + * This version draws a zoomed image on a quad, zoom rectangle specified by r + * @see tc3DWindow::DrawImage + */ + void tc3DWindow::DrawZoomedImage(osg::Texture2D* texture, float x, float y, float width, float height, + const tcRect& r, int alignMode) + { + wxASSERT(texture); + if (!texture) return; + + osg::Geometry* quad = GetImageQuadObject(); + wxASSERT(quad); + wxASSERT(texture); + + // set the texture coordinates using zoom rect, r + osg::Vec2Array* texcoords = dynamic_cast<osg::Vec2Array*>(quad->getTexCoordArray(0)); + wxASSERT(texcoords); + + float x1 = r.left; + float x2 = r.right; + float y1 = r.bottom; + float y2 = r.top; + + (*texcoords)[0].set(x1, y2); + (*texcoords)[1].set(x1, y1); + (*texcoords)[2].set(x2, y1); + (*texcoords)[3].set(x2, y2); + + + + if (osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(quad->getVertexArray())) + { + float left, right, top, bottom; + if (alignMode == CENTER) + { + const float half_width = 0.5f * width; + const float half_height = 0.5f * height; + left = x - half_width; + right = x + half_width; + top = y + half_height; + bottom = y - half_height; + } + else + { + left = x; + right = x + width; + top = y + height; + bottom = y; + } + + (*vertices)[0] = osg::Vec3(left, top, 0); + (*vertices)[1] = osg::Vec3(left, bottom, 0); + (*vertices)[2] = osg::Vec3(right, bottom, 0); + (*vertices)[3] = osg::Vec3(right, top, 0); + } + else + { + fprintf(stderr, "tc3DWindow::DrawZoomedImage - corrupt vertex array\n"); + wxASSERT(0); + } + + osg::StateSet* stateset = quad->getOrCreateStateSet(); + stateset->setTextureAttributeAndModes(0, texture, + osg::StateAttribute::ON); + } + + + /** *************** *** 873,876 **** --- 941,956 ---- } + /** + * This method is used for inverted y coordinate system used by wxWindows + * y = 0 is at top of screen. + */ + void tc3DWindow::DrawZoomedImageR(osg::Texture2D* texture, float x, float y, float width, float height, + const tcRect& r, int alignMode) + { + const float h = float(mnHeight); + + DrawZoomedImage(texture, x, h - y - height, width, height, r, alignMode); + } + /** *************** *** 1170,1177 **** * @return alpha blending state for window. */ ! bool tc3DWindow::GetBlend() { ! // return mp2DSurface->GetBlend(); ! return false; } --- 1250,1256 ---- * @return alpha blending state for window. */ ! bool tc3DWindow::GetBlend() const { ! return blendingOn; } *************** *** 1180,1186 **** * for window. */ ! void tc3DWindow::SetBlend(bool blendingOn) { ! // mp2DSurface->SetBlend(blendingOn); } --- 1259,1291 ---- * for window. */ ! void tc3DWindow::SetBlend(bool blend) { ! blendingOn = blend; ! ! ! osg::StateAttribute::GLModeValue value; ! if (blendingOn) ! { ! value = osg::StateAttribute::ON; ! } ! else ! { ! value = osg::StateAttribute::OFF; ! } ! ! osg::StateSet* stateSet = root->getOrCreateStateSet(); ! stateSet->setMode(GL_BLEND, value); ! ! osg::StateSet* groupStateSet = groupRoot->getOrCreateStateSet(); ! groupStateSet->setMode(GL_BLEND, value); ! ! osg::StateSet* textStateSet = textRoot->getOrCreateStateSet(); ! textStateSet->setMode(GL_BLEND, value); ! ! osg::StateSet* backgroundStateSet = backgroundRoot->getOrCreateStateSet(); ! backgroundStateSet->setMode(GL_BLEND, value); ! ! osg::StateSet* lineStateSet = lineRoot->getOrCreateStateSet(); ! lineStateSet->setMode(GL_BLEND, value); } *************** *** 1448,1452 **** ! #ifdef _DEBUG if (osg::StateSet* stateSet = textRoot->getStateSet()) { --- 1553,1557 ---- ! #if 0 if (osg::StateSet* stateSet = textRoot->getStateSet()) { *************** *** 1783,1787 **** fontSizeLarge(18.0), fontSizeSmall(9.0), ! hostParent(graphicsHost) { --- 1888,1893 ---- fontSizeLarge(18.0), fontSizeSmall(9.0), ! hostParent(graphicsHost), ! blendingOn(true) { |