Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: third_party/gles_book_examples/Common/Source/Win32/esUtil_win32.c

Issue 525070: Resubmit 35500: Added an application framework for demos. Ported hellotriangl... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 //
2 // Book: OpenGL(R) ES 2.0 Programming Guide
3 // Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner
4 // ISBN-10: 0321502795
5 // ISBN-13: 9780321502797
6 // Publisher: Addison-Wesley Professional
7 // URLs: http://safari.informit.com/9780321563835
8 // http://www.opengles-book.com
9 //
10
11 // esUtil_win32.c
12 //
13 // This file contains the Win32 implementation of the windowing functions.
14
15
16 ///
17 // Includes
18 //
19 #define WIN32_LEAN_AND_MEAN
20 #include <windows.h>
21 #include "esUtil.h"
22
23 //////////////////////////////////////////////////////////////////
24 //
25 // Private Functions
26 //
27 //
28
29 ///
30 // ESWindowProc()
31 //
32 // Main window procedure
33 //
34 LRESULT WINAPI ESWindowProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
35 {
36 LRESULT lRet = 1;
37
38 switch (uMsg)
39 {
40 case WM_CREATE:
41 break;
42
43 case WM_PAINT:
44 {
45 ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWn d, GWL_USERDATA );
46
47 if ( esContext && esContext->drawFunc )
48 esContext->drawFunc ( esContext );
49
50 ValidateRect( esContext->hWnd, NULL );
51 }
52 break;
53
54 case WM_DESTROY:
55 PostQuitMessage(0);
56 break;
57
58 case WM_CHAR:
59 {
60 POINT point;
61 ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWn d, GWL_USERDATA );
62
63 GetCursorPos( &point );
64
65 if ( esContext && esContext->keyFunc )
66 esContext->keyFunc ( esContext, (unsigned char) wParam,
67 (int) point.x, (int) point.y );
68 }
69 break;
70
71 default:
72 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
73 break;
74 }
75
76 return lRet;
77 }
78
79 //////////////////////////////////////////////////////////////////
80 //
81 // Public Functions
82 //
83 //
84
85 ///
86 // WinCreate()
87 //
88 // Create Win32 instance and window
89 //
90 GLboolean WinCreate ( ESContext *esContext, const char *title )
91 {
92 WNDCLASS wndclass = {0};
93 DWORD wStyle = 0;
94 RECT windowRect;
95 HINSTANCE hInstance = GetModuleHandle(NULL);
96
97
98 wndclass.style = CS_OWNDC;
99 wndclass.lpfnWndProc = (WNDPROC)ESWindowProc;
100 wndclass.hInstance = hInstance;
101 wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
102 wndclass.lpszClassName = "opengles2.0";
103
104 if (!RegisterClass (&wndclass) )
105 return FALSE;
106
107 wStyle = WS_VISIBLE | WS_POPUP | WS_BORDER | WS_SYSMENU | WS_CAPTION;
108
109 // Adjust the window rectangle so that the client area has
110 // the correct number of pixels
111 windowRect.left = 0;
112 windowRect.top = 0;
113 windowRect.right = esContext->width;
114 windowRect.bottom = esContext->height;
115
116 AdjustWindowRect ( &windowRect, wStyle, FALSE );
117
118
119
120 esContext->hWnd = CreateWindow(
121 "opengles2.0",
122 title,
123 wStyle,
124 0,
125 0,
126 windowRect.right - windowRect.left,
127 windowRect.bottom - windowRect.top,
128 NULL,
129 NULL,
130 hInstance,
131 NULL);
132
133 // Set the ESContext* to the GWL_USERDATA so that it is available to the
134 // ESWindowProc
135 SetWindowLongPtr ( esContext->hWnd, GWL_USERDATA, (LONG) (LONG_PTR) esContex t );
136
137
138 if ( esContext->hWnd == NULL )
139 return GL_FALSE;
140
141 ShowWindow ( esContext->hWnd, TRUE );
142
143 return GL_TRUE;
144 }
145
146 ///
147 // winLoop()
148 //
149 // Start main windows loop
150 //
151 void WinLoop ( ESContext *esContext )
152 {
153 MSG msg = { 0 };
154 int done = 0;
155 DWORD lastTime = GetTickCount();
156
157 while (!done)
158 {
159 int gotMsg = (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != 0);
160 DWORD curTime = GetTickCount();
161 float deltaTime = (float)( curTime - lastTime ) / 1000.0f;
162 lastTime = curTime;
163
164 if ( gotMsg )
165 {
166 if (msg.message==WM_QUIT)
167 {
168 done=1;
169 }
170 else
171 {
172 TranslateMessage(&msg);
173 DispatchMessage(&msg);
174 }
175 }
176 else
177 SendMessage( esContext->hWnd, WM_PAINT, 0, 0 );
178
179 // Call update function if registered
180 if ( esContext->updateFunc != NULL )
181 esContext->updateFunc ( esContext, deltaTime );
182 }
183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698