1 
2 #ifdef __GNUC__
3 #pragma GCC diagnostic push
4 #pragma GCC diagnostic ignored "-Wunused-parameter"
5 #endif
6 
7 #ifdef _WIN32
8 /*
9 Copyright (c) 2012 Advanced Micro Devices, Inc.
10 
11 This software is provided 'as-is', without any express or implied warranty.
12 In no event will the authors be held liable for any damages arising from the use of this software.
13 Permission is granted to anyone to use this software for any purpose,
14 including commercial applications, and to alter it and redistribute it freely,
15 subject to the following restrictions:
16 
17 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
18 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20 */
21 //Originally written by Erwin Coumans
22 
23 #ifdef _MSC_VER
24 #pragma warning(disable : 4100)
25 #pragma warning(disable : 4267)
26 #endif
27 
28 #include "Win32OpenGLWindow.h"
29 
30 #include "OpenGLInclude.h"
31 
32 //#include "Bullet3Common/b3Vector3.h"
33 
34 #include "Win32InternalWindowData.h"
35 #include <stdio.h>
36 
printGLString(const char * name,GLenum s)37 static void printGLString(const char *name, GLenum s) {
38     const char *v = (const char *) glGetString(s);
39   printf("%s = %s\n",name, v);
40 }
41 
42 bool sOpenGLVerbose = true;
43 
enableOpenGL()44 void Win32OpenGLWindow::enableOpenGL()
45 {
46 
47 	PIXELFORMATDESCRIPTOR pfd;
48 	int format;
49 
50 	// get the device context (DC)
51 	m_data->m_hDC = GetDC( m_data->m_hWnd );
52 
53 	// set the pixel format for the DC
54 	ZeroMemory( &pfd, sizeof( pfd ) );
55 	pfd.nSize = sizeof( pfd );
56 	pfd.nVersion = 1;
57 	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
58 	pfd.iPixelType = PFD_TYPE_RGBA;
59 	pfd.cColorBits = 32;
60 	pfd.cRedBits = 8;
61     pfd.cGreenBits = 8;
62     pfd.cBlueBits = 8;
63     pfd.cAlphaBits = 8;
64 
65 	pfd.cDepthBits = 24;
66 	pfd.cStencilBits = 8;//1;
67 	pfd.iLayerType = PFD_MAIN_PLANE;
68 	format = ChoosePixelFormat( m_data->m_hDC, &pfd );
69 	SetPixelFormat( m_data->m_hDC, format, &pfd );
70 
71 	// create and enable the render context (RC)
72 	m_data->m_hRC = wglCreateContext( m_data->m_hDC );
73 	wglMakeCurrent( m_data->m_hDC, m_data->m_hRC );
74 
75 	if (sOpenGLVerbose)
76 	{
77 		 printGLString("Version", GL_VERSION);
78 		printGLString("Vendor", GL_VENDOR);
79 		printGLString("Renderer", GL_RENDERER);
80 	}
81     //printGLString("Extensions", GL_EXTENSIONS);
82 
83 }
84 
85 
86 
disableOpenGL()87 void Win32OpenGLWindow::disableOpenGL()
88 {
89 	wglMakeCurrent( NULL, NULL );
90 	wglDeleteContext( m_data->m_hRC );
91 //	ReleaseDC( m_data->m_hWnd, m_data->m_hDC );
92 
93 }
94 
95 
96 
97 
98 
createWindow(const b3gWindowConstructionInfo & ci)99 void	Win32OpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
100 {
101 	Win32Window::createWindow(ci);
102 
103 	//VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, this);
104 	enableOpenGL();
105 
106 }
107 
108 
109 
110 
Win32OpenGLWindow()111 Win32OpenGLWindow::Win32OpenGLWindow()
112 {
113 
114 
115 }
116 
~Win32OpenGLWindow()117 Win32OpenGLWindow::~Win32OpenGLWindow()
118 {
119 
120 }
121 
122 
closeWindow()123 void	Win32OpenGLWindow::closeWindow()
124 {
125 	disableOpenGL();
126 
127 	Win32Window::closeWindow();
128 }
129 
130 
131 
startRendering()132 void	Win32OpenGLWindow::startRendering()
133 {
134 		pumpMessage();
135 		//don't clear all 3 buffers because some AMD drivers are buggy
136 		//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
137 		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
138 
139 
140 		//glCullFace(GL_BACK);
141 		//glFrontFace(GL_CCW);
142 		glEnable(GL_DEPTH_TEST);
143 
144 }
145 
146 
renderAllObjects()147 void	Win32OpenGLWindow::renderAllObjects()
148 {
149 }
150 
endRendering()151 void	Win32OpenGLWindow::endRendering()
152  {
153 	SwapBuffers( m_data->m_hDC );
154 
155 }
156 
fileOpenDialog(char * fileName,int maxFileNameLength)157 int Win32OpenGLWindow::fileOpenDialog(char* fileName, int maxFileNameLength)
158 {
159 	//wchar_t wideChars[1024];
160 
161 		OPENFILENAME ofn ;
162 	ZeroMemory( &ofn , sizeof( ofn));
163 	ofn.lStructSize = sizeof ( ofn );
164 	ofn.hwndOwner = NULL  ;
165 
166 #ifdef UNICODE
167 	WCHAR bla[1024];
168 	ofn.lpstrFile = bla;
169 	ofn.lpstrFile[0] = '\0';
170 	ofn.nMaxFile = 1023;
171 	ofn.lpstrFilter = L"All Files\0*.*\0URDF\0*.urdf\0.bullet\0*.bullet\0";
172 #else
173 	ofn.lpstrFile = fileName;
174 	ofn.lpstrFile[0] = '\0';
175 	ofn.nMaxFile = 1023;
176 	//ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
177 	ofn.lpstrFilter = "All Files\0*.*\0URDF\0*.urdf\0.bullet\0*.bullet\0";
178 
179 #endif
180 
181 	ofn.nFilterIndex =1;
182 	ofn.lpstrFileTitle = NULL ;
183 	ofn.nMaxFileTitle = 0 ;
184 	ofn.lpstrInitialDir=NULL ;
185 	ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST ;
186 	GetOpenFileName( &ofn );
187 	return strlen(fileName);
188 
189 
190 	//return 0;
191 }
192 
getWidth() const193 int Win32OpenGLWindow::getWidth() const
194 {
195 	if (m_data)
196 		return m_data->m_openglViewportWidth;
197 	return 0;
198 }
199 
getHeight() const200 int Win32OpenGLWindow::getHeight() const
201 {
202 	if (m_data)
203 		return m_data->m_openglViewportHeight;
204 	return 0;
205 }
206 
207 
208 #endif
209 
210 
211 
212 #ifdef __GNUC__
213 #pragma GCC diagnostic pop
214 #endif