Import Geant4 5.2.0 source tree
This commit is contained in:
@@ -21,80 +21,254 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4OpenGLWin32Viewer.cc,v 1.5 2002/10/16 10:44:16 johna Exp $
|
||||
// GEANT4 tag $Name: geant4-05-01 $
|
||||
// $Id: G4OpenGLWin32Viewer.cc,v 1.9 2003/06/25 09:01:12 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-05-02 $
|
||||
//
|
||||
//
|
||||
// G4OpenGLWin32Viewer : Class to provide WindowsNT specific
|
||||
// functionality for OpenGL in GEANT4
|
||||
//
|
||||
// 27/06/2003 : G.Barrand : implementation (at last !).
|
||||
|
||||
#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
|
||||
|
||||
#include "G4OpenGLWin32Viewer.hh"
|
||||
|
||||
#include <GL/gl.h>
|
||||
//#include <GL/glx.h> Change this for Win32
|
||||
|
||||
#include "G4ios.hh"
|
||||
|
||||
#include "G4VisExtent.hh"
|
||||
#include "G4LogicalVolume.hh"
|
||||
#include "G4VSolid.hh"
|
||||
#include "G4Point3D.hh"
|
||||
#include "G4Normal3D.hh"
|
||||
|
||||
void G4OpenGLWin32Viewer::FinishView () {
|
||||
|
||||
//Wait for GL commands to exit before going on...
|
||||
//Swap buffers if double buffered...
|
||||
//Flush GL commands...
|
||||
|
||||
}
|
||||
|
||||
void G4OpenGLWin32Viewer::GetWin32Connection () {
|
||||
// get a connection.
|
||||
}
|
||||
|
||||
void G4OpenGLWin32Viewer::CreateGLWin32Context () {
|
||||
// create a GL context
|
||||
// set attributes of window now the GL context has been created
|
||||
G4cout <<
|
||||
"ERROR: G4OpenGLWin32Viewer::CreateGLWin32Context:"
|
||||
"\n **** WIN32 VIEWER NOT YET IMPLEMENTED ****"
|
||||
<< G4endl;
|
||||
}
|
||||
|
||||
void G4OpenGLWin32Viewer::CreateMainWindow () {
|
||||
|
||||
// create a window
|
||||
// connect the context to a window
|
||||
|
||||
}
|
||||
|
||||
G4OpenGLWin32Viewer::G4OpenGLWin32Viewer (G4OpenGLSceneHandler& scene):
|
||||
G4VViewer (scene, -1),
|
||||
G4OpenGLViewer (scene)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void G4OpenGLWin32Viewer::SetView (
|
||||
)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
GetWin32Connection ();
|
||||
if (fViewId < 0) return;
|
||||
|
||||
// Try for a visual suitable for OpenGLImmediate..
|
||||
// first try for a single buffered RGB window
|
||||
// next try for a double buffered RGB, but Draw to top buffer
|
||||
|
||||
|
||||
// Now try for a visual suitable for OpenGLStored...
|
||||
// Try for a double buffered RGB window
|
||||
|
||||
if(!fHDC) return;
|
||||
if(!fHGLRC) return;
|
||||
::wglMakeCurrent(fHDC,fHGLRC);
|
||||
G4OpenGLViewer::SetView ();
|
||||
}
|
||||
|
||||
G4OpenGLWin32Viewer::~G4OpenGLWin32Viewer () {
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void G4OpenGLWin32Viewer::ShowView (
|
||||
)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
glFlush ();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void G4OpenGLWin32Viewer::FinishView (
|
||||
)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
if(!fHDC) return;
|
||||
::SwapBuffers(fHDC);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void G4OpenGLWin32Viewer::GetWin32Connection (
|
||||
)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void G4OpenGLWin32Viewer::CreateGLWin32Context (
|
||||
)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void G4OpenGLWin32Viewer::CreateMainWindow (
|
||||
)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
if(fWindow) return; //Done.
|
||||
|
||||
// Bill Gates stuff...
|
||||
static const char className[] = "G4OpenGLWin32";
|
||||
static bool done = false;
|
||||
if(done==false) {
|
||||
WNDCLASS wc;
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wc.lpfnWndProc = (WNDPROC)WindowProc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = ::GetModuleHandle(NULL);
|
||||
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
|
||||
wc.hCursor = LoadCursor(NULL,IDC_CROSS);
|
||||
wc.hbrBackground = NULL;
|
||||
wc.lpszMenuName = className;
|
||||
wc.lpszClassName = className;
|
||||
::RegisterClass(&wc);
|
||||
done = true;
|
||||
}
|
||||
|
||||
WinSize_x = 400;
|
||||
WinSize_y = 400;
|
||||
if (WinSize_x < fVP.GetWindowSizeHintX ())
|
||||
WinSize_x = fVP.GetWindowSizeHintX ();
|
||||
if (WinSize_y < fVP.GetWindowSizeHintY ())
|
||||
WinSize_y = fVP.GetWindowSizeHintY ();
|
||||
|
||||
fWindow = ::CreateWindow(className,fName.c_str(),
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
//WS_CHILD | WS_VISIBLE,
|
||||
0,0,
|
||||
WinSize_x,WinSize_y,
|
||||
NULL, NULL,
|
||||
::GetModuleHandle(NULL),
|
||||
NULL);
|
||||
if(!fWindow) return;
|
||||
|
||||
::SetWindowLong(fWindow,GWL_USERDATA,LONG(this));
|
||||
|
||||
// initialize OpenGL rendering :
|
||||
fHDC = ::GetDC(fWindow);
|
||||
if( fHDC && (SetWindowPixelFormat(fHDC)==TRUE) ) {
|
||||
fHGLRC = ::wglCreateContext(fHDC);
|
||||
}
|
||||
|
||||
if(fHDC && fHGLRC) {
|
||||
::wglMakeCurrent(fHDC,fHGLRC);
|
||||
}
|
||||
|
||||
::SetForegroundWindow(fWindow);
|
||||
::ShowWindow(fWindow,SW_SHOWDEFAULT);
|
||||
::UpdateWindow(fWindow);
|
||||
::DrawMenuBar(fWindow);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
G4OpenGLWin32Viewer::G4OpenGLWin32Viewer (
|
||||
G4OpenGLSceneHandler& scene
|
||||
)
|
||||
:G4VViewer (scene, -1)
|
||||
,G4OpenGLViewer (scene)
|
||||
,fWindow(0)
|
||||
,fHDC(0)
|
||||
,fHGLRC(0)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
G4OpenGLWin32Viewer::~G4OpenGLWin32Viewer (
|
||||
)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
// This is the end (Jim Morisson).
|
||||
if (fViewId >= 0) {
|
||||
//Close a window from here
|
||||
//destroy GL context
|
||||
//make NULL context current
|
||||
//destroy the Win32 window
|
||||
if(wglGetCurrentContext()!=NULL) wglMakeCurrent(NULL,NULL);
|
||||
if(fHGLRC) {
|
||||
wglDeleteContext(fHGLRC);
|
||||
fHGLRC = NULL;
|
||||
}
|
||||
|
||||
if(fWindow) {
|
||||
::SetWindowLong(fWindow,GWL_USERDATA,LONG(NULL));
|
||||
if(fHDC) ::ReleaseDC(fWindow,fHDC);
|
||||
::DestroyWindow(fWindow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
LRESULT CALLBACK G4OpenGLWin32Viewer::WindowProc (
|
||||
HWND aWindow
|
||||
,UINT aMessage
|
||||
,WPARAM aWParam
|
||||
,LPARAM aLParam
|
||||
)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
switch (aMessage) {
|
||||
case WM_PAINT:{
|
||||
G4OpenGLWin32Viewer* This =
|
||||
(G4OpenGLWin32Viewer*)::GetWindowLong(aWindow,GWL_USERDATA);
|
||||
HDC hDC;
|
||||
PAINTSTRUCT ps;
|
||||
hDC = BeginPaint(aWindow,&ps);
|
||||
if(This) {
|
||||
// FIXME : To have an automatic refresh someone have to redraw here.
|
||||
}
|
||||
EndPaint(aWindow, &ps);
|
||||
}
|
||||
return 0;
|
||||
default:
|
||||
return DefWindowProc(aWindow,aMessage,aWParam,aLParam);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool G4OpenGLWin32Viewer::SetWindowPixelFormat(
|
||||
HDC aHdc
|
||||
)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
// The ungessable...
|
||||
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
||||
pfd.nVersion = 1;
|
||||
pfd.dwFlags =
|
||||
PFD_DRAW_TO_WINDOW |
|
||||
PFD_SUPPORT_OPENGL |
|
||||
PFD_DOUBLEBUFFER |
|
||||
PFD_STEREO_DONTCARE;
|
||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||
pfd.cColorBits = 32;
|
||||
pfd.cRedBits = 8;
|
||||
pfd.cRedShift = 16;
|
||||
pfd.cGreenBits = 8;
|
||||
pfd.cGreenShift = 8;
|
||||
pfd.cBlueBits = 8;
|
||||
pfd.cBlueShift = 0;
|
||||
pfd.cAlphaBits = 0;
|
||||
pfd.cAlphaShift = 0;
|
||||
pfd.cAccumBits = 64;
|
||||
pfd.cAccumRedBits = 16;
|
||||
pfd.cAccumGreenBits = 16;
|
||||
pfd.cAccumBlueBits = 16;
|
||||
pfd.cAccumAlphaBits = 0;
|
||||
pfd.cDepthBits = 32;
|
||||
pfd.cStencilBits = 8;
|
||||
pfd.cAuxBuffers = 0;
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
pfd.bReserved = 0;
|
||||
pfd.dwLayerMask = 0;
|
||||
pfd.dwVisibleMask = 0;
|
||||
pfd.dwDamageMask = 0;
|
||||
|
||||
int pixelIndex = ::ChoosePixelFormat(aHdc,&pfd);
|
||||
if (pixelIndex==0) {
|
||||
pixelIndex = 1;
|
||||
if (::DescribePixelFormat(aHdc,
|
||||
pixelIndex,
|
||||
sizeof(PIXELFORMATDESCRIPTOR),
|
||||
&pfd)==0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (::SetPixelFormat(aHdc,pixelIndex,&pfd)==FALSE) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user