├── Core ├── CoreWindow.h ├── CoreWindow_egl.cpp ├── CoreWindow_egl.h ├── CoreWindow_mac.h ├── CoreWindow_mac.mm ├── CoreWindow_wgl.cpp ├── CoreWindow_wgl.h ├── CoreWindow_x11.cpp └── CoreWindow_x11.h ├── Makefile ├── Makefile.emscripten ├── Makefile.macosx ├── README.md ├── UI ├── SimpleGUI.h ├── SimpleGraphics.h ├── SimpleGraphics_impl.h ├── SimpleShader.h ├── SimpleTex.h ├── SimpleVB.h ├── WGLExtension.cpp ├── WGLExtension.h ├── glext.h ├── icons.h ├── mplus1cmedium.h ├── mplus1pregular.h ├── skBaseGUI.h ├── stb_truetype.h └── wglext.h ├── for_glfw ├── Makefile.cocoa ├── README └── uitest.cpp ├── screenshots ├── screenshot_linux.png ├── screenshot_mac.png └── screenshot_win.png ├── test.cpp ├── vcproj ├── CoreWindowTest.sln ├── CoreWindowTest.vcxproj └── CoreWindowTest.vcxproj.filters └── xcode ├── SimpleUI-Info.plist ├── SimpleUI-Prefix.pch └── SimpleUI.xcodeproj ├── project.pbxproj └── project.xcworkspace └── contents.xcworkspacedata /Core/CoreWindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CoreWindow.h 3 | * 4 | * Created by kioku on 10/08/11. 5 | * Copyright 2010 System K. All rights reserved. 6 | * 7 | */ 8 | 9 | #ifndef INCLUDE_CORE_WINDOW_H 10 | #define INCLUDE_CORE_WINDOW_H 11 | 12 | class CoreWindowPlatform 13 | { 14 | protected: 15 | CoreWindowPlatform() 16 | { 17 | } 18 | public: 19 | virtual ~CoreWindowPlatform() 20 | { 21 | } 22 | 23 | virtual void MouseLeftDown (int x, int y) = 0; 24 | virtual void MouseLeftUp (int x, int y) = 0; 25 | virtual void MouseRightDown (int x, int y) = 0; 26 | virtual void MouseRightUp (int x, int y) = 0; 27 | virtual void MouseMiddleDown(int x, int y) = 0; 28 | virtual void MouseMiddleUp (int x, int y) = 0; 29 | virtual void MouseMove (int x, int y) = 0; 30 | virtual void Wheel (float dx, float dy, float dz) = 0; 31 | virtual void Magnify (float z) = 0; 32 | virtual void Swipe (float dx, float dy, float dz) = 0; 33 | virtual void Rotate (float r) = 0; 34 | virtual void KeyDown (int key) = 0; 35 | virtual void KeyUp (int key) = 0; 36 | virtual void Resize (int w, int h) = 0; 37 | virtual void Close (void) = 0; 38 | virtual void Idle (void) = 0; 39 | virtual void Draw (void) = 0; 40 | virtual void Active (void) = 0; 41 | virtual void Toplevel (bool top) = 0; 42 | virtual void SwapBuffer (void) = 0; 43 | 44 | virtual void GoFullscreen(bool fullscreen, bool cursor=true) = 0; 45 | 46 | virtual int GetWidth() const = 0; 47 | virtual int GetHeight() const = 0; 48 | 49 | virtual const char* GetExePath() const = 0; 50 | virtual const char* FileOpenDialog(const char* ext) const = 0; 51 | virtual const char* FileSaveDialog(const char* ext) const = 0; 52 | 53 | 54 | }; 55 | 56 | #if defined(__EMSCRIPTEN__) 57 | #include "CoreWindow_egl.h" 58 | #elif defined (__APPLE__) 59 | #include "CoreWindow_mac.h" 60 | #elif defined(_WIN32) 61 | #include "CoreWindow_wgl.h" 62 | #else 63 | #include "CoreWindow_x11.h" 64 | #endif 65 | 66 | #endif // INCLUDE_CORE_WINDOW_H 67 | -------------------------------------------------------------------------------- /Core/CoreWindow_egl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CoreWindow_egl.cpp 3 | * 4 | * Created by kioku on 14/06/05. 5 | * Copyright 2013 System K. All rights reserved. 6 | * 7 | */ 8 | 9 | #include "CoreWindow_egl.h" 10 | 11 | //#include "esUtil.h" 12 | //--------------------------------------------------------- 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | 22 | typedef struct _escontext 23 | { 24 | /// Put your user data here... 25 | void* userData; 26 | 27 | /// Window width 28 | GLint width; 29 | 30 | /// Window height 31 | GLint height; 32 | 33 | /// Window handle 34 | EGLNativeWindowType hWnd; 35 | 36 | /// EGL display 37 | EGLDisplay eglDisplay; 38 | 39 | /// EGL context 40 | EGLContext eglContext; 41 | 42 | /// EGL surface 43 | EGLSurface eglSurface; 44 | 45 | /// Callbacks 46 | // void (ESCALLBACK *drawFunc) ( struct _escontext * ); 47 | // void (ESCALLBACK *keyFunc) ( struct _escontext *, unsigned char, int, int ); 48 | // void (ESCALLBACK *updateFunc) ( struct _escontext *, float deltaTime ); 49 | } ESContext; 50 | 51 | 52 | #ifndef FALSE 53 | #define FALSE 0 54 | #endif 55 | #ifndef TRUE 56 | #define TRUE 1 57 | #endif 58 | 59 | /// esCreateWindow flag - RGB color buffer 60 | #define ES_WINDOW_RGB 0 61 | /// esCreateWindow flag - ALPHA color buffer 62 | #define ES_WINDOW_ALPHA 1 63 | /// esCreateWindow flag - depth buffer 64 | #define ES_WINDOW_DEPTH 2 65 | /// esCreateWindow flag - stencil buffer 66 | #define ES_WINDOW_STENCIL 4 67 | /// esCreateWindow flat - multi-sample buffer 68 | #define ES_WINDOW_MULTISAMPLE 8 69 | 70 | namespace { 71 | 72 | static Display *x_display = NULL; 73 | 74 | void esInitContext ( ESContext *esContext ) 75 | { 76 | if ( esContext != NULL ) { 77 | memset( esContext, 0, sizeof( ESContext) ); 78 | } 79 | } 80 | 81 | EGLBoolean CreateEGLContext ( EGLNativeWindowType hWnd, EGLDisplay* eglDisplay, 82 | EGLContext* eglContext, EGLSurface* eglSurface, 83 | EGLint attribList[]) 84 | { 85 | EGLint numConfigs; 86 | EGLint majorVersion; 87 | EGLint minorVersion; 88 | EGLDisplay display; 89 | EGLContext context; 90 | EGLSurface surface; 91 | EGLConfig config; 92 | EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE }; 93 | 94 | // Get Display 95 | display = eglGetDisplay((EGLNativeDisplayType)x_display); 96 | if ( display == EGL_NO_DISPLAY ) 97 | { 98 | return EGL_FALSE; 99 | } 100 | 101 | // Initialize EGL 102 | if ( !eglInitialize(display, &majorVersion, &minorVersion) ) 103 | { 104 | return EGL_FALSE; 105 | } 106 | 107 | // Get configs 108 | if ( !eglGetConfigs(display, NULL, 0, &numConfigs) ) 109 | { 110 | return EGL_FALSE; 111 | } 112 | 113 | // Choose config 114 | if ( !eglChooseConfig(display, attribList, &config, 1, &numConfigs) ) 115 | { 116 | return EGL_FALSE; 117 | } 118 | 119 | // Create a surface 120 | surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)hWnd, NULL); 121 | if ( surface == EGL_NO_SURFACE ) 122 | { 123 | return EGL_FALSE; 124 | } 125 | 126 | // Create a GL context 127 | context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs ); 128 | if ( context == EGL_NO_CONTEXT ) 129 | { 130 | return EGL_FALSE; 131 | } 132 | 133 | // Make the context current 134 | if ( !eglMakeCurrent(display, surface, surface, context) ) 135 | { 136 | return EGL_FALSE; 137 | } 138 | 139 | *eglDisplay = display; 140 | *eglSurface = surface; 141 | *eglContext = context; 142 | return EGL_TRUE; 143 | } 144 | 145 | 146 | /// 147 | // WinCreate() 148 | // 149 | // This function initialized the native X11 display and window for EGL 150 | // 151 | EGLBoolean WinCreate(ESContext *esContext, const char *title) 152 | { 153 | Window root; 154 | XSetWindowAttributes swa; 155 | XSetWindowAttributes xattr; 156 | Atom wm_state; 157 | XWMHints hints; 158 | XEvent xev; 159 | EGLConfig ecfg; 160 | EGLint num_config; 161 | Window win; 162 | 163 | /* 164 | * X11 native display initialization 165 | */ 166 | 167 | x_display = XOpenDisplay(NULL); 168 | if ( x_display == NULL ) 169 | { 170 | return EGL_FALSE; 171 | } 172 | 173 | root = DefaultRootWindow(x_display); 174 | 175 | swa.event_mask = ExposureMask | PointerMotionMask | KeyPressMask; 176 | win = XCreateWindow( 177 | x_display, root, 178 | 0, 0, esContext->width, esContext->height, 0, 179 | CopyFromParent, InputOutput, 180 | CopyFromParent, CWEventMask, 181 | &swa ); 182 | 183 | xattr.override_redirect = FALSE; 184 | XChangeWindowAttributes ( x_display, win, CWOverrideRedirect, &xattr ); 185 | 186 | hints.input = TRUE; 187 | hints.flags = InputHint; 188 | XSetWMHints(x_display, win, &hints); 189 | 190 | // make the window visible on the screen 191 | XMapWindow (x_display, win); 192 | XStoreName (x_display, win, title); 193 | 194 | // get identifiers for the provided atom name strings 195 | wm_state = XInternAtom (x_display, "_NET_WM_STATE", FALSE); 196 | 197 | memset ( &xev, 0, sizeof(xev) ); 198 | xev.type = ClientMessage; 199 | xev.xclient.window = win; 200 | xev.xclient.message_type = wm_state; 201 | xev.xclient.format = 32; 202 | xev.xclient.data.l[0] = 1; 203 | xev.xclient.data.l[1] = FALSE; 204 | XSendEvent ( 205 | x_display, 206 | DefaultRootWindow ( x_display ), 207 | FALSE, 208 | SubstructureNotifyMask, 209 | &xev ); 210 | 211 | esContext->hWnd = (EGLNativeWindowType) win; 212 | return EGL_TRUE; 213 | } 214 | 215 | bool esCreateWindow ( ESContext *esContext, const char* title, GLint width, GLint height, GLuint flags ) 216 | { 217 | EGLint attribList[] = 218 | { 219 | EGL_RED_SIZE, 5, 220 | EGL_GREEN_SIZE, 6, 221 | EGL_BLUE_SIZE, 5, 222 | EGL_ALPHA_SIZE, (flags & ES_WINDOW_ALPHA) ? 8 : EGL_DONT_CARE, 223 | EGL_DEPTH_SIZE, (flags & ES_WINDOW_DEPTH) ? 8 : EGL_DONT_CARE, 224 | EGL_STENCIL_SIZE, (flags & ES_WINDOW_STENCIL) ? 8 : EGL_DONT_CARE, 225 | EGL_SAMPLE_BUFFERS, (flags & ES_WINDOW_MULTISAMPLE) ? 1 : 0, 226 | EGL_NONE 227 | }; 228 | 229 | if ( esContext == NULL ) 230 | { 231 | return GL_FALSE; 232 | } 233 | 234 | esContext->width = width; 235 | esContext->height = height; 236 | 237 | if ( !WinCreate ( esContext, title) ) 238 | { 239 | return GL_FALSE; 240 | } 241 | 242 | 243 | if ( !CreateEGLContext ( esContext->hWnd, 244 | &esContext->eglDisplay, 245 | &esContext->eglContext, 246 | &esContext->eglSurface, 247 | attribList) ) 248 | { 249 | return GL_FALSE; 250 | } 251 | 252 | 253 | return GL_TRUE; 254 | } 255 | 256 | 257 | 258 | } // namespace 259 | 260 | #include 261 | #include 262 | 263 | #include 264 | 265 | 266 | namespace { 267 | const char* gtkFileSaveDialog (const char* ext) 268 | { 269 | return 0; 270 | } 271 | const char* gtkFileOpenDialog (const char* ext) 272 | { 273 | return 0; 274 | } 275 | 276 | CoreWindow* g_win = 0; 277 | 278 | ESContext esContext; 279 | } // namespace 280 | 281 | //-------------------------- 282 | 283 | class CoreWindow::Impl 284 | { 285 | public: 286 | Impl(){} 287 | ~Impl(){} 288 | 289 | int m_w, m_h; 290 | // Window* m_win; 291 | // GLXContext m_ctx; 292 | }; 293 | 294 | CoreWindow::CoreWindow(int x, int y, int width, int height, const char* title, bool fullscreenMode) 295 | { 296 | m_imp = new Impl(); 297 | // m_display = XOpenDisplay(0); 298 | 299 | m_imp->m_w = width; 300 | m_imp->m_h = height; 301 | // bool r = make_window(m_display, title, 32, 24, width, height, &m_imp->m_win, &m_imp->m_ctx); 302 | // XMapWindow(m_display, m_imp->m_win); 303 | // glXMakeCurrent(m_display, m_imp->m_win, m_imp->m_ctx); 304 | 305 | esInitContext ( &esContext ); 306 | esCreateWindow ( &esContext, title, width, height, ES_WINDOW_RGB ); 307 | g_win = this; 308 | glViewport(0,0,width,height); 309 | } 310 | CoreWindow::~CoreWindow() 311 | { 312 | // GL Context 313 | /* if (m_imp->m_ctx) 314 | { 315 | glXDestroyContext(m_display, m_imp->m_ctx); 316 | m_imp->m_ctx = 0; 317 | } 318 | if (m_imp->m_win){ 319 | XDestroyWindow(m_display, m_imp->m_win); 320 | m_imp->m_win = 0; 321 | } 322 | 323 | // XWindow 324 | if (m_display) 325 | { 326 | XCloseDisplay(m_display); 327 | m_display = 0; 328 | }*/ 329 | delete m_imp; 330 | } 331 | void CoreWindow::Active() 332 | { 333 | // glXMakeCurrent(m_display, m_imp->m_win, m_imp->m_ctx); 334 | } 335 | void CoreWindow::Toplevel(bool top) 336 | { 337 | 338 | } 339 | void CoreWindow::SwapBuffer() 340 | { 341 | eglSwapBuffers(esContext.eglDisplay, esContext.eglSurface); 342 | // glXSwapBuffers(m_display, g_win->m_imp->m_win); 343 | } 344 | void CoreWindow::DoEvents(void) 345 | { 346 | printf("Not support function DoEvents() on emscripten platform\n"); 347 | } 348 | 349 | void idleloop() 350 | { 351 | g_win->Idle(); 352 | } 353 | 354 | int keyDownEvent(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData) 355 | { 356 | g_win->KeyDown(keyEvent->keyCode); 357 | return 0; 358 | } 359 | 360 | int keyUpEvent(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData) 361 | { 362 | g_win->KeyUp(keyEvent->keyCode); 363 | return 0; 364 | } 365 | 366 | int mouseEvent(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) 367 | { 368 | static int mx = 0,my = 0; 369 | //printf("MOUSE EVENT = %d, BTN=%d\n",eventType,mouseEvent->button); 370 | switch ( eventType ) { 371 | case EMSCRIPTEN_EVENT_MOUSEDOWN: 372 | mx = mouseEvent->canvasX; 373 | my = mouseEvent->canvasY; 374 | if( mouseEvent->button == 0 ){ 375 | g_win->MouseLeftDown(mx,my); 376 | } else if( mouseEvent->button == 1 ){ 377 | g_win->MouseMiddleDown(mx,my); 378 | } else if( mouseEvent->button == 2 ){ 379 | g_win->MouseRightDown(mx,my); 380 | } else if( mouseEvent->button == 3 ){ 381 | g_win->Wheel(0.0f, 1.0f, 0.0f); 382 | } else if( mouseEvent->button == 4 ){ 383 | g_win->Wheel(0.0f,-1.0f, 0.0f); 384 | } 385 | return 0; 386 | case EMSCRIPTEN_EVENT_MOUSEUP: 387 | mx = mouseEvent->canvasX; 388 | my = mouseEvent->canvasY; 389 | if( mouseEvent->button == 0 ){ 390 | g_win->MouseLeftUp(mx,my); 391 | } else if( mouseEvent->button == 1 ){ 392 | g_win->MouseMiddleUp(mx,my); 393 | } else if( mouseEvent->button == 2 ){ 394 | g_win->MouseRightUp(mx,my); 395 | } 396 | return 0; 397 | 398 | case EMSCRIPTEN_EVENT_MOUSEMOVE: 399 | if (mouseEvent->canvasX != mx 400 | || mouseEvent->canvasY != my){ 401 | mx = mouseEvent->canvasX; 402 | my = mouseEvent->canvasY; 403 | g_win->MouseMove(mx, my); 404 | return 0; 405 | } 406 | return 0; 407 | default: 408 | return 0; 409 | } 410 | } 411 | 412 | int resizeEvent(int eventType, const EmscriptenUiEvent *uiEvent, void *userData) 413 | { 414 | //glViewport(0,0,uiEvent->windowInnerWidth, uiEvent->windowInnerHeight); 415 | //g_win->Resize(uiEvent->windowInnerWidth, uiEvent->windowInnerHeight); 416 | return 0; 417 | } 418 | 419 | 420 | void CoreWindow::MainLoop(void) 421 | { 422 | emscripten_set_keyup_callback("#window", NULL, 0, keyUpEvent); 423 | emscripten_set_keydown_callback("#window", NULL, 0, keyDownEvent); 424 | emscripten_set_mousedown_callback("#window", NULL, 0, mouseEvent); 425 | emscripten_set_mouseup_callback("#window", NULL, 0, mouseEvent); 426 | emscripten_set_mousemove_callback("#window", NULL, 0, mouseEvent); 427 | 428 | emscripten_set_resize_callback("#window", NULL, 0, resizeEvent); 429 | 430 | emscripten_set_main_loop (idleloop, 0, 1); 431 | } 432 | 433 | void CoreWindow::GoFullscreen(bool fullscreen, bool cursor) 434 | { 435 | // TODO 436 | } 437 | 438 | const char* CoreWindow::GetExePath() const 439 | { 440 | return 0; // TODO: 441 | } 442 | 443 | int CoreWindow::GetWidth() const 444 | { 445 | return m_imp->m_w; 446 | } 447 | 448 | int CoreWindow::GetHeight() const 449 | { 450 | return m_imp->m_h; 451 | } 452 | 453 | const char* CoreWindow::FileOpenDialog(const char* ext) const 454 | { 455 | return gtkFileOpenDialog(ext); 456 | } 457 | const char* CoreWindow::FileSaveDialog(const char* ext) const 458 | { 459 | return gtkFileSaveDialog(ext); 460 | } 461 | -------------------------------------------------------------------------------- /Core/CoreWindow_egl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CoreWindow_egl.h 3 | * 4 | * Created by kioku on 14/06/05. 5 | * Copyright 2013 System K. All rights reserved. 6 | * 7 | */ 8 | 9 | #ifndef COREWINDOW_EGL_HEADER 10 | #define COREWINDOW_EGL_HEADER 11 | 12 | #include "CoreWindow.h" 13 | 14 | class CoreWindow : public CoreWindowPlatform 15 | { 16 | protected: 17 | CoreWindow(int x, int y, int width, int height, const char* title, bool fullscreenMode = false); 18 | ~CoreWindow(); 19 | public: 20 | 21 | virtual void MouseLeftDown (int x, int y){} 22 | virtual void MouseLeftUp (int x, int y){} 23 | virtual void MouseRightDown (int x, int y){} 24 | virtual void MouseRightUp (int x, int y){} 25 | virtual void MouseMiddleDown(int x, int y){} 26 | virtual void MouseMiddleUp (int x, int y){} 27 | virtual void MouseMove (int x, int y){} 28 | virtual void Wheel (float dx, float dy, float dz){} 29 | virtual void Magnify (float z) {} 30 | virtual void Swipe (float dx, float dy, float dz){} 31 | virtual void Rotate (float r) {} 32 | virtual void KeyDown (int key) {} 33 | virtual void KeyUp (int key) {} 34 | virtual void Resize (int w, int h){} 35 | virtual void Close (void) {} 36 | virtual void Idle (void) {} 37 | virtual void Draw (void) {} 38 | 39 | void Active(); 40 | void Toplevel(bool top); 41 | void SwapBuffer(); 42 | static void DoEvents(void); 43 | static void MainLoop(void); 44 | 45 | void GoFullscreen(bool fullscreen, bool cursor=true); 46 | 47 | int GetWidth() const; 48 | int GetHeight() const; 49 | 50 | const char* GetExePath() const; 51 | const char* FileOpenDialog(const char* ext) const; 52 | const char* FileSaveDialog(const char* ext) const; 53 | 54 | protected: 55 | class Impl; 56 | Impl* m_imp; 57 | }; 58 | 59 | void CoreWindow_DoEvents(); 60 | 61 | 62 | #endif // COREWINDOW_EGL_HEADER 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Core/CoreWindow_mac.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CoreWindow_mac.h 3 | * 4 | * Created by kioku on 10/08/11. 5 | * Copyright 2010 System K. All rights reserved. 6 | * 7 | */ 8 | 9 | #ifndef COREWINDOW_MAC_HEADER 10 | #define COREWINDOW_MAC_HEADER 11 | 12 | #include "CoreWindow.h" 13 | 14 | #ifdef __OBJC__ 15 | #define ObjC_ID id 16 | #else 17 | #define ObjC_ID void* 18 | #endif 19 | 20 | 21 | class CoreWindow : public CoreWindowPlatform 22 | { 23 | protected: 24 | CoreWindow(int x, int y, int width, int height, const char* title, bool fullscreenMode = false); 25 | ~CoreWindow(); 26 | public: 27 | 28 | virtual void MouseLeftDown (int x, int y){} 29 | virtual void MouseLeftUp (int x, int y){} 30 | virtual void MouseRightDown (int x, int y){} 31 | virtual void MouseRightUp (int x, int y){} 32 | virtual void MouseMiddleDown(int x, int y){} 33 | virtual void MouseMiddleUp (int x, int y){} 34 | virtual void MouseMove (int x, int y){} 35 | virtual void Wheel (float dx, float dy, float dz){} 36 | virtual void Magnify (float z) {} 37 | virtual void Swipe (float dx, float dy, float dz){} 38 | virtual void Rotate (float r) {} 39 | virtual void KeyDown (int key) {} 40 | virtual void KeyUp (int key) {} 41 | virtual void Resize (int w, int h){} 42 | virtual void Close (void) {} 43 | virtual void Idle (void) {} 44 | virtual void Draw (void) {} 45 | 46 | void Active(); 47 | void Toplevel(bool top); 48 | void SwapBuffer(); 49 | static void DoEvents(void); 50 | static void MainLoop(void); 51 | 52 | void GoFullscreen(bool fullscreen, bool cursor=true); 53 | 54 | int GetWidth() const { return m_w; } 55 | int GetHeight() const { return m_h; } 56 | 57 | const char* GetExePath() const; 58 | const char* FileOpenDialog(const char* ext) const; 59 | const char* FileSaveDialog(const char* ext) const; 60 | 61 | protected: 62 | ObjC_ID m_win; 63 | ObjC_ID m_view; 64 | int m_w, m_h; 65 | 66 | }; 67 | 68 | void CoreWindow_DoEvents(); 69 | 70 | 71 | #endif // COREWINDOW_MAC_HEADER 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /Core/CoreWindow_mac.mm: -------------------------------------------------------------------------------- 1 | /* 2 | * CoreWindow_mac.cpp 3 | * 4 | * Created by kioku on 10/08/11. 5 | * Copyright 2010 System K. All rights reserved. 6 | * 7 | */ 8 | 9 | #include "CoreWindow_mac.h" 10 | 11 | #import 12 | #include 13 | #include 14 | 15 | //#define TRACE_ENABLE 16 | 17 | #ifdef TRACE_ENABLE 18 | #define trace printf 19 | #else 20 | #include 21 | inline void trace(const char* f, ...) 22 | { 23 | } 24 | #endif 25 | 26 | #include 27 | #include 28 | 29 | 30 | static CoreWindow* g_mainWin = 0; 31 | 32 | @interface skMacDelegate : NSObject// < NSApplicationDelegate > 33 | /* Example: Fire has the same problem no explanation */ 34 | { 35 | } 36 | @end 37 | 38 | @implementation skMacDelegate 39 | - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication; 40 | { 41 | return YES; 42 | } 43 | @end 44 | 45 | 46 | @interface skOpenGLWindow : NSWindow 47 | { 48 | CoreWindow* m_ownerWin; 49 | } 50 | @end 51 | 52 | @implementation skOpenGLWindow 53 | - (id) initWithContentRect: (NSRect)rect styleMask:(NSUInteger)wndStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferFlg win:(CoreWindow*)ownerWin 54 | { 55 | [super initWithContentRect:rect styleMask:wndStyle backing:bufferingType defer:deferFlg]; 56 | m_ownerWin = ownerWin; 57 | 58 | [[NSNotificationCenter defaultCenter] 59 | addObserver:self 60 | selector:@selector(windowDidResize:) 61 | name:NSWindowDidResizeNotification 62 | object:self]; 63 | 64 | [[NSNotificationCenter defaultCenter] 65 | addObserver:self 66 | selector:@selector(windowWillClose:) 67 | name:NSWindowWillCloseNotification 68 | object:self]; 69 | 70 | [self setAcceptsMouseMovedEvents:YES]; 71 | [self makeFirstResponder:self]; 72 | 73 | trace("%s\n",__FUNCTION__); 74 | return self; 75 | } 76 | 77 | - (void) resizeGL 78 | { 79 | trace("%s\n",__FUNCTION__); 80 | } 81 | 82 | - (void) windowDidResize: (NSNotification *)notification 83 | { 84 | trace("%s\n",__FUNCTION__); 85 | } 86 | 87 | - (void) windowWillClose: (NSNotification *)notification 88 | { 89 | trace("%s\n",__FUNCTION__); 90 | m_ownerWin->Close(); 91 | [NSApp terminate:nil]; // This can also be exit(0); 92 | } 93 | 94 | @end 95 | 96 | 97 | @interface skOpenGLView : NSOpenGLView 98 | { 99 | CoreWindow* m_ownerWin; 100 | int m_width; 101 | int m_height; 102 | NSTrackingRectTag _tag; 103 | bool m_isMouseCursorIn; 104 | } 105 | - (void) drawRect: (NSRect) bounds; 106 | @end 107 | 108 | @implementation skOpenGLView 109 | -(void) setOwnerWindow: (CoreWindow*) win 110 | { 111 | m_isMouseCursorIn = false; 112 | m_ownerWin = win; 113 | } 114 | 115 | - (BOOL)canBecomeKeyView 116 | { 117 | return YES; 118 | } 119 | 120 | - (BOOL)acceptsFirstResponder 121 | { 122 | return YES; 123 | } 124 | 125 | 126 | //トラッキング領域の生成 127 | - (void)viewDidMoveToWindow { 128 | _tag = [self addTrackingRect:[self bounds] owner:self userData:NULL assumeInside:NO]; 129 | } 130 | 131 | - (void)setFrame:(NSRect)frame { 132 | [super setFrame:frame]; 133 | [self removeTrackingRect:_tag]; 134 | _tag = [self addTrackingRect:[self bounds] owner:self userData:NULL assumeInside:NO]; 135 | } 136 | 137 | - (void)setBounds:(NSRect)bounds { 138 | [super setBounds:bounds]; 139 | [self removeTrackingRect:_tag]; 140 | _tag = [self addTrackingRect:[self bounds] owner:self userData:NULL assumeInside:NO]; 141 | } 142 | 143 | - (void)mouseEntered:(NSEvent*)event { 144 | [[self window] setAcceptsMouseMovedEvents:YES]; 145 | [[self window] makeFirstResponder:self]; 146 | m_isMouseCursorIn = true; 147 | } 148 | 149 | - (void)mouseExited:(NSEvent*)event { 150 | [[self window] setAcceptsMouseMovedEvents:NO]; 151 | m_isMouseCursorIn = false; 152 | } 153 | 154 | 155 | -(void) reshape 156 | { 157 | trace("%s\n",__FUNCTION__); 158 | NSRect rect; 159 | rect = [self frame]; 160 | m_width = rect.size.width; 161 | m_height = rect.size.height; 162 | trace("resize -> %d,%d\n", m_width, m_height); 163 | m_ownerWin->Active(); 164 | glViewport(0,0,m_width,m_height); 165 | m_ownerWin->Resize(m_width, m_height); 166 | } 167 | 168 | -(void) drawRect: (NSRect) bounds 169 | { 170 | trace("%s\n",__FUNCTION__); 171 | } 172 | 173 | -(void) prepareOpenGL 174 | { 175 | trace("%s\n",__FUNCTION__); 176 | } 177 | 178 | -(NSMenu *)menuForEvent: (NSEvent *)theEvent 179 | { 180 | trace("%s\n",__FUNCTION__); 181 | return [NSView defaultMenu]; 182 | } 183 | 184 | - (void) keyDown:(NSEvent *)theEvent 185 | { 186 | NSString *chrs;//,*chrsNoMod; 187 | chrs = [theEvent characters]; 188 | int unicode = 0; 189 | if ([chrs length] > 0) 190 | { 191 | unicode=[chrs characterAtIndex:0]; 192 | unicode &= 255; 193 | if (0<=unicode && unicode<128) 194 | m_ownerWin->KeyDown(unicode); 195 | } 196 | trace("%s : %d\n",__FUNCTION__, unicode); 197 | 198 | const int curkey = 256*0xF7; 199 | if ((curkey & unicode) == curkey) 200 | { 201 | int cr = unicode & 0xFF; 202 | trace("special=%d\n",cr); 203 | m_ownerWin->KeyDown(129+cr-4);// UP/DOWN/LEFT/RIGHT 204 | } 205 | } 206 | 207 | - (void) keyUp:(NSEvent *)theEvent 208 | { 209 | NSString *chrs;//,*chrsNoMod; 210 | chrs=[theEvent characters]; 211 | int unicode = 0; 212 | if([chrs length]>0) 213 | { 214 | unicode=[chrs characterAtIndex:0]; 215 | if (0<=unicode && unicode<128) 216 | m_ownerWin->KeyUp(unicode); 217 | } 218 | trace("%s : %d\n",__FUNCTION__, unicode); 219 | 220 | 221 | const int curkey = 256*0xF7; 222 | if ((curkey & unicode) == curkey) 223 | { 224 | int cr = unicode & 0xFF; 225 | trace("special=%d\n",cr); 226 | m_ownerWin->KeyUp(129+cr-4);// UP/DOWN/LEFT/RIGHT 227 | } 228 | } 229 | 230 | - (void)scrollWheel:(NSEvent *)theEvent 231 | { 232 | //if (! [self isEnabled]) return; 233 | if (!m_isMouseCursorIn) return; 234 | 235 | trace("%s %f %f %f\n",__FUNCTION__,[theEvent deltaX],[theEvent deltaY], [theEvent deltaZ]); 236 | 237 | // A delta of 6 represents a large change. Let's consider a delta of 6 to represent an eighth of a full rotation - that is, pi/4 radians. 238 | // Therefore, we multiply by pi/4 and divide by 6, which is equivalent to multiplying by pi/24. 239 | //const CGFloat scrollWheelToRadiansConversionFactor = M_PI/24.; 240 | CGFloat deltaX = [theEvent deltaX], deltaY = [theEvent deltaY], deltaZ = [theEvent deltaZ]; 241 | //if (deltaX != 0.) [self rotateAboutAxis:kYAxis byRadians:-deltaX * scrollWheelToRadiansConversionFactor]; 242 | //if (deltaY != 0.) [self rotateAboutAxis:kXAxis byRadians:-deltaY * scrollWheelToRadiansConversionFactor]; 243 | //if (deltaZ != 0.) [self rotateAboutAxis:kZAxis byRadians:deltaZ * scrollWheelToRadiansConversionFactor]; 244 | 245 | m_ownerWin->Wheel(deltaX, deltaY, deltaZ); 246 | /* Send the action too */ 247 | //if (deltaX || deltaY || deltaZ) { 248 | // [NSApp sendAction:[self action] to:[self target] from:self]; 249 | //} 250 | } 251 | 252 | - (void) magnifyWithEvent:(NSEvent *)event 253 | { 254 | trace("%s %f\n",__FUNCTION__,[event magnification]); 255 | m_ownerWin->Magnify([event magnification]); 256 | } 257 | 258 | - (void) swipeWithEvent:(NSEvent *)event 259 | { 260 | trace("%s %f %f %f\n",__FUNCTION__,[event deltaX],[event deltaY],[event deltaZ]); 261 | m_ownerWin->Swipe([event deltaX], [event deltaY], [event deltaZ]); 262 | } 263 | 264 | - (void) rotateWithEvent:(NSEvent *)event 265 | { 266 | trace("%s %f\n",__FUNCTION__,[event rotation]); 267 | m_ownerWin->Rotate([event rotation]); 268 | } 269 | 270 | - (void) mouseMoved:(NSEvent *)theEvent 271 | { 272 | trace("%s %d %d\n",__FUNCTION__,(int)[theEvent locationInWindow].x,(int)[theEvent locationInWindow].y); 273 | m_ownerWin->MouseMove((int)[theEvent locationInWindow].x, m_height - (int)[theEvent locationInWindow].y); 274 | } 275 | 276 | - (void) mouseDragged:(NSEvent *)theEvent 277 | { 278 | trace("%s %d %d\n",__FUNCTION__,(int)[theEvent locationInWindow].x,(int)[theEvent locationInWindow].y); 279 | m_ownerWin->MouseMove((int)[theEvent locationInWindow].x, m_height - (int)[theEvent locationInWindow].y); 280 | } 281 | 282 | - (void) mouseDown:(NSEvent *)theEvent 283 | { 284 | trace("%s %d %d\n",__FUNCTION__,(int)[theEvent locationInWindow].x,(int)[theEvent locationInWindow].y); 285 | m_ownerWin->MouseLeftDown((int)[theEvent locationInWindow].x,m_height - (int)[theEvent locationInWindow].y); 286 | } 287 | 288 | - (void) mouseUp:(NSEvent *)theEvent 289 | { 290 | trace("%s %d %d\n",__FUNCTION__,(int)[theEvent locationInWindow].x,(int)[theEvent locationInWindow].y); 291 | m_ownerWin->MouseLeftUp((int)[theEvent locationInWindow].x,m_height - (int)[theEvent locationInWindow].y); 292 | } 293 | 294 | - (void) rightMouseDown:(NSEvent *)theEvent 295 | { 296 | trace("%s %d %d\n",__FUNCTION__,(int)[theEvent locationInWindow].x,(int)[theEvent locationInWindow].y); 297 | m_ownerWin->MouseRightDown((int)[theEvent locationInWindow].x,m_height - (int)[theEvent locationInWindow].y); 298 | } 299 | 300 | - (void) rightMouseUp:(NSEvent *)theEvent 301 | { 302 | trace("%s %d %d\n",__FUNCTION__,(int)[theEvent locationInWindow].x,(int)[theEvent locationInWindow].y); 303 | m_ownerWin->MouseRightUp((int)[theEvent locationInWindow].x,m_height - (int)[theEvent locationInWindow].y); 304 | } 305 | 306 | - (void) rightMouseDragged:(NSEvent *)theEvent 307 | { 308 | trace("%s %d %d\n",__FUNCTION__,(int)[theEvent locationInWindow].x,(int)[theEvent locationInWindow].y); 309 | m_ownerWin->MouseMove((int)[theEvent locationInWindow].x, m_height - (int)[theEvent locationInWindow].y); 310 | } 311 | 312 | - (void) otherMouseDown:(NSEvent *)theEvent 313 | { 314 | trace("%s %d %d\n",__FUNCTION__,(int)[theEvent locationInWindow].x,(int)[theEvent locationInWindow].y); 315 | m_ownerWin->MouseMiddleDown((int)[theEvent locationInWindow].x,m_height - (int)[theEvent locationInWindow].y); 316 | } 317 | 318 | - (void) otherMouseUp:(NSEvent *)theEvent 319 | { 320 | trace("%s %d %d\n",__FUNCTION__,(int)[theEvent locationInWindow].x,(int)[theEvent locationInWindow].y); 321 | m_ownerWin->MouseMiddleUp((int)[theEvent locationInWindow].x,m_height - (int)[theEvent locationInWindow].y); 322 | } 323 | 324 | - (void) otherMouseDragged:(NSEvent *)theEvent 325 | { 326 | trace("%s %d %d\n",__FUNCTION__,(int)[theEvent locationInWindow].x,(int)[theEvent locationInWindow].y); 327 | m_ownerWin->MouseMove((int)[theEvent locationInWindow].x, m_height - (int)[theEvent locationInWindow].y); 328 | } 329 | 330 | 331 | @end 332 | 333 | namespace { 334 | std::vector split(std::string str, const std::string& delim) 335 | { 336 | std::vector result; 337 | size_t cutAt; 338 | while( (cutAt = str.find_first_of(delim)) != str.npos ) { 339 | if(cutAt > 0) { 340 | result.push_back(str.substr(0, cutAt)); 341 | } 342 | str = str.substr(cutAt + 1); 343 | } 344 | if (str.length() > 0) { 345 | result.push_back(str); 346 | } 347 | return result; 348 | } 349 | 350 | void skAddMenu(void) 351 | { 352 | NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init]; 353 | 354 | NSMenu *mainMenu; 355 | 356 | mainMenu=[NSMenu alloc]; 357 | [mainMenu initWithTitle:@"Minimum"]; 358 | 359 | NSMenuItem *fileMenu; 360 | fileMenu=[[NSMenuItem alloc] initWithTitle:@"File" action:NULL keyEquivalent:[NSString string]]; 361 | [mainMenu addItem:fileMenu]; 362 | 363 | NSMenu *fileSubMenu; 364 | fileSubMenu=[[NSMenu alloc] initWithTitle:@"File"]; 365 | [fileMenu setSubmenu:fileSubMenu]; 366 | 367 | NSMenuItem *fileMenu_Quit; 368 | fileMenu_Quit=[[NSMenuItem alloc] initWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"]; 369 | [fileMenu_Quit setTarget:NSApp]; 370 | [fileSubMenu addItem:fileMenu_Quit]; 371 | 372 | [NSApp setMainMenu:mainMenu]; 373 | 374 | [pool release]; 375 | } 376 | 377 | void skTestApplicationPath(void) 378 | { 379 | NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init]; 380 | 381 | char cwd[256]; 382 | getcwd(cwd,255); 383 | trace("CWD(Initial): %s\n",cwd); 384 | 385 | NSString *path; 386 | path=[[NSBundle mainBundle] bundlePath]; 387 | trace("BundlePath:%s\n",[path UTF8String]); 388 | 389 | [[NSFileManager defaultManager] changeCurrentDirectoryPath:path]; 390 | 391 | getcwd(cwd,255); 392 | trace("CWD(Changed): %s\n",cwd); 393 | 394 | [pool release]; 395 | } 396 | 397 | 398 | void skPollDeviceC(void) 399 | { 400 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 401 | 402 | while(1) 403 | { 404 | [pool release]; 405 | pool=[[NSAutoreleasePool alloc] init]; 406 | 407 | NSEvent *event; 408 | event = [NSApp 409 | nextEventMatchingMask:NSAnyEventMask 410 | untilDate: [NSDate distantPast] 411 | inMode: NSDefaultRunLoopMode 412 | dequeue:YES]; 413 | if([event type] == NSRightMouseDown) 414 | { 415 | trace("R mouse down event\n"); 416 | } 417 | if(event!=nil) 418 | { 419 | [NSApp sendEvent:event]; 420 | [NSApp updateWindows]; 421 | } 422 | else 423 | { 424 | break; 425 | } 426 | } 427 | 428 | [pool release]; 429 | } 430 | 431 | } // namespace 432 | 433 | 434 | void CoreWindow::DoEvents() 435 | { 436 | skPollDeviceC(); 437 | } 438 | 439 | void CoreWindow::MainLoop() 440 | { 441 | while (1) 442 | { 443 | skPollDeviceC(); 444 | 445 | if (g_mainWin) 446 | g_mainWin->Idle(); 447 | } 448 | } 449 | 450 | CoreWindow::CoreWindow(int x, int y, int width ,int height, const char* title, bool fullscreenMode) 451 | { 452 | if (g_mainWin == 0) 453 | g_mainWin = this; 454 | NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init]; 455 | 456 | [NSApplication sharedApplication]; 457 | 458 | // Set Front process (need for keyboard and mouse events at console mode) 459 | ProcessSerialNumber psn = { 0, kCurrentProcess }; 460 | TransformProcessType(&psn, kProcessTransformToForegroundApplication); 461 | SetFrontProcess(&psn); 462 | 463 | [NSApp finishLaunching]; 464 | 465 | 466 | NSRect contRect; 467 | contRect = NSMakeRect(x, y, width, height); 468 | 469 | unsigned int winStyle = 470 | NSTitledWindowMask 471 | //NSBorderlessWindowMask 472 | | NSClosableWindowMask 473 | | NSMiniaturizableWindowMask 474 | | NSResizableWindowMask 475 | | NSWindowFullScreenButton; 476 | 477 | m_win = [skOpenGLWindow alloc]; 478 | [m_win 479 | initWithContentRect:contRect 480 | styleMask:winStyle 481 | backing:NSBackingStoreBuffered 482 | defer:NO]; 483 | [m_win setTitle:[NSString stringWithUTF8String:title]]; 484 | 485 | // for CloseButton 486 | skMacDelegate *delegate; 487 | delegate = [skMacDelegate alloc]; 488 | [delegate init]; 489 | //[NSApp setDelegate: delegate]; 490 | NSNotificationCenter *c = [NSNotificationCenter defaultCenter]; 491 | [c addObserver:NSApp selector: @selector(terminate:) name: @"NSWindowWillCloseNotification" object:m_win]; 492 | 493 | 494 | NSOpenGLPixelFormat *format; 495 | NSOpenGLPixelFormatAttribute formatAttrib[] = 496 | { 497 | NSOpenGLPFAWindow, 498 | NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)32, 499 | NSOpenGLPFAStencilSize, 1, 500 | NSOpenGLPFADoubleBuffer, 501 | 0 502 | }; 503 | 504 | format=[NSOpenGLPixelFormat alloc]; 505 | [format initWithAttributes: formatAttrib]; 506 | 507 | m_view = [skOpenGLView alloc]; 508 | [m_view setOwnerWindow:this]; 509 | contRect = NSMakeRect( 0, 0, width, height); 510 | [m_view 511 | initWithFrame:contRect 512 | pixelFormat:format]; 513 | 514 | [m_win setContentView:m_view]; 515 | [m_win makeFirstResponder:m_view]; 516 | 517 | [m_win makeKeyAndOrderFront:nil]; 518 | [m_win makeMainWindow]; 519 | 520 | if (fullscreenMode) 521 | [m_view enterFullScreenMode:[NSScreen mainScreen] withOptions:nil]; 522 | 523 | NSRect rc = [m_view bounds]; 524 | m_w = rc.size.width; 525 | m_h = rc.size.height; 526 | [NSApp activateIgnoringOtherApps:YES]; 527 | 528 | skAddMenu(); 529 | 530 | [pool release]; 531 | 532 | } 533 | 534 | CoreWindow::~CoreWindow() 535 | { 536 | 537 | } 538 | 539 | void CoreWindow::Active() 540 | { 541 | [[m_view openGLContext] makeCurrentContext]; 542 | } 543 | 544 | void CoreWindow::SwapBuffer() 545 | { 546 | glSwapAPPLE(); 547 | } 548 | 549 | void CoreWindow::Toplevel(bool top) 550 | { 551 | if (top) 552 | [m_win setLevel:NSPopUpMenuWindowLevel]; 553 | else 554 | [m_win setLevel:NSNormalWindowLevel]; 555 | } 556 | 557 | void CoreWindow::GoFullscreen(bool fullscreen,bool cursor) 558 | { 559 | if (!cursor) 560 | [NSCursor hide]; 561 | else 562 | [NSCursor unhide]; 563 | 564 | if (fullscreen) 565 | [m_view enterFullScreenMode:[NSScreen mainScreen] withOptions:nil]; 566 | else 567 | [m_view exitFullScreenModeWithOptions:nil]; 568 | } 569 | 570 | const char* CoreWindow::GetExePath() const 571 | { 572 | static char exepath[2048]; 573 | NSString *curDir = [[NSBundle mainBundle] bundlePath]; 574 | strcpy(exepath, [curDir UTF8String]); 575 | return exepath; 576 | } 577 | 578 | const char* CoreWindow::FileOpenDialog(const char* ext) const 579 | { 580 | NSOpenGLContext *cctx = [NSOpenGLContext currentContext]; 581 | static char strbuf[1024] = {}; 582 | std::vector exts = split(std::string(ext), "|"); 583 | NSMutableArray *allowedFileTypes = [NSMutableArray array]; 584 | for (size_t i = 0; i < exts.size(); ++i){ 585 | NSString* nsext = [NSString stringWithUTF8String:exts[i].c_str()]; 586 | [allowedFileTypes addObject:nsext]; 587 | } 588 | NSOpenPanel *openPanel = [NSOpenPanel openPanel]; 589 | [openPanel setAllowedFileTypes:allowedFileTypes]; 590 | NSInteger pressedButton = [openPanel runModal]; 591 | 592 | if( pressedButton == NSOKButton ){ 593 | NSURL * filePath = [openPanel URL]; 594 | NSString* nss = [filePath path]; 595 | strncpy(strbuf, [nss UTF8String], 1024); 596 | [cctx makeCurrentContext]; 597 | return strbuf; 598 | } 599 | [cctx makeCurrentContext]; 600 | return 0; 601 | } 602 | const char* CoreWindow::FileSaveDialog(const char* ext) const 603 | { 604 | NSOpenGLContext *cctx = [NSOpenGLContext currentContext]; 605 | static char strbuf[1024] = {}; 606 | std::vector exts = split(std::string(ext), "|"); 607 | NSMutableArray *allowedFileTypes = [NSMutableArray array]; 608 | for (size_t i = 0; i < exts.size(); ++i){ 609 | NSString* nsext = [NSString stringWithUTF8String:exts[i].c_str()]; 610 | [allowedFileTypes addObject:nsext]; 611 | } 612 | NSSavePanel *savePanel = [NSSavePanel savePanel]; 613 | [savePanel setAllowedFileTypes:allowedFileTypes]; 614 | NSInteger pressedButton = [savePanel runModal]; 615 | 616 | if( pressedButton == NSOKButton ){ 617 | NSURL * filePath = [savePanel URL]; 618 | NSString* nss = [filePath path]; 619 | strncpy(strbuf, [nss UTF8String], 1024); 620 | [cctx makeCurrentContext]; 621 | return strbuf; 622 | } 623 | [cctx makeCurrentContext]; 624 | return 0; 625 | } 626 | -------------------------------------------------------------------------------- /Core/CoreWindow_wgl.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kioku-systemk/SimpleUI/ef04d2269ff9590a050185d84c60ea7c851b7de5/Core/CoreWindow_wgl.cpp -------------------------------------------------------------------------------- /Core/CoreWindow_wgl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CoreWindow_wgl.h 3 | * 4 | * Created by kioku on 11/02/01. 5 | * Copyright 2011 System K. All rights reserved. 6 | * 7 | */ 8 | 9 | #ifndef COREWINDOW_WGL_HEADER 10 | #define COREWINDOW_WGL_HEADER 11 | 12 | #include "CoreWindow.h" 13 | #include 14 | 15 | class CoreWindow : public CoreWindowPlatform 16 | { 17 | protected: 18 | bool createWindow(int x, int y, int width, int height, const TCHAR* title, bool fullscreenmode = false); 19 | 20 | LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 21 | static LRESULT CALLBACK BaseWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); 22 | bool initGL(HWND hWnd); 23 | void KillGLWindow(); 24 | void resize(int width, int height); 25 | 26 | HWND m_hWnd; 27 | HGLRC m_hRC; 28 | HDC m_hDC; 29 | int m_w,m_h; 30 | bool m_inited; 31 | int m_restore_width,m_restore_height; 32 | 33 | public: 34 | CoreWindow(int x, int y, int width, int height, const TCHAR* title, bool fullscreenmode = false); 35 | ~CoreWindow(); 36 | 37 | virtual void MouseLeftDown (int x, int y){} 38 | virtual void MouseLeftUp (int x, int y){} 39 | virtual void MouseRightDown (int x, int y){} 40 | virtual void MouseRightUp (int x, int y){} 41 | virtual void MouseMiddleDown(int x, int y){} 42 | virtual void MouseMiddleUp (int x, int y){} 43 | virtual void MouseMove (int x, int y){} 44 | virtual void Wheel (float dx, float dy, float dz){} 45 | virtual void Magnify (float z) {} 46 | virtual void Swipe (float dx, float dy, float dz){} 47 | virtual void Rotate (float r) {} 48 | virtual void KeyDown (int key) {} 49 | virtual void KeyUp (int key) {} 50 | virtual void Resize (int w, int h){} 51 | virtual void Close (void) {} 52 | virtual void Idle (void) {} 53 | virtual void Draw (void) {} 54 | virtual void Toplevel (bool top); 55 | void Active(void); 56 | void SwapBuffer(); 57 | static void DoEvents(); 58 | static void MainLoop(); 59 | 60 | HDC GetHDC(); 61 | int GetWidth() const { return m_w; } 62 | int GetHeight() const { return m_h; } 63 | 64 | void GoFullscreen(bool fullscreen,bool cursor=true); 65 | 66 | const char* GetExePath() const; 67 | const char* FileOpenDialog(const char* ext) const; 68 | const char* FileSaveDialog(const char* ext) const; 69 | }; 70 | 71 | 72 | 73 | #endif // COREWINDOW_WGL_HEADER 74 | 75 | -------------------------------------------------------------------------------- /Core/CoreWindow_x11.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CoreWindow_x11.cpp 3 | * 4 | * Created by kioku on 13/01/11. 5 | * Copyright 2013 System K. All rights reserved. 6 | * 7 | */ 8 | 9 | #include "CoreWindow_x11.h" 10 | 11 | #ifdef EMSCRIPTEN 12 | #include 13 | #include 14 | #else 15 | #include 16 | #include 17 | #endif 18 | 19 | #include 20 | #include 21 | //-------------------------- 22 | 23 | #ifdef USE_GTK 24 | #include 25 | #include 26 | #endif 27 | 28 | namespace { 29 | const int MAXFILEPATH = 1024; 30 | static char filename[MAXFILEPATH]; 31 | int btnmode = 0; 32 | 33 | const char* gtkFileDialog (const char* ext, bool save) 34 | { 35 | #ifdef USE_GTK 36 | GtkWidget *filew; 37 | 38 | int argc = 1; 39 | char** argv; 40 | char name[] = "Dialog"; 41 | char* argv_i[] = {name,0}; 42 | argv = reinterpret_cast(&argv_i); 43 | gtk_init (&argc, &argv); 44 | const char* title = (save ? "Save" : "Open"); 45 | GtkWidget* dialog = gtk_file_chooser_dialog_new(title, 46 | 0,save ? GTK_FILE_CHOOSER_ACTION_SAVE : GTK_FILE_CHOOSER_ACTION_OPEN, 47 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 48 | (save ? GTK_STOCK_SAVE : GTK_STOCK_OPEN), GTK_RESPONSE_ACCEPT, NULL); 49 | gtk_widget_show_all(dialog); 50 | gint res = gtk_dialog_run(GTK_DIALOG(dialog)); 51 | if (res == GTK_RESPONSE_ACCEPT) { 52 | gchar* fname = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); 53 | strncpy(filename, fname, MAXFILEPATH); 54 | //g_free(fname); 55 | gtk_widget_hide(dialog); 56 | gtk_widget_destroy(dialog); 57 | while (gtk_events_pending()) 58 | gtk_main_iteration(); 59 | return filename; 60 | } 61 | gtk_widget_hide(dialog); 62 | gtk_widget_destroy(dialog); 63 | while (gtk_events_pending()) 64 | gtk_main_iteration(); 65 | #endif 66 | return 0; 67 | } 68 | const char* gtkFileSaveDialog (const char* ext) 69 | { 70 | return gtkFileDialog(ext, true); 71 | } 72 | const char* gtkFileOpenDialog (const char* ext) 73 | { 74 | return gtkFileDialog(ext, false); 75 | } 76 | 77 | 78 | } // namespace 79 | 80 | //-------------------------- 81 | 82 | class CoreWindow::Impl 83 | { 84 | public: 85 | Impl(){} 86 | ~Impl(){} 87 | 88 | int m_w, m_h; 89 | Window m_win; 90 | GLXContext m_ctx; 91 | }; 92 | 93 | Display* m_display; 94 | CoreWindow* g_win = 0; 95 | 96 | bool make_window( Display *dpy, const char *name, int colorbit, int depthbit, 97 | int width, int height, Window *winRet, GLXContext *ctxRet) 98 | { 99 | int attrib[] = { 100 | GLX_RGBA, GLX_DOUBLEBUFFER, 101 | GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, 102 | GLX_DEPTH_SIZE, depthbit, 103 | None 104 | }; 105 | int scrnum; 106 | XSetWindowAttributes attr; 107 | unsigned long mask; 108 | Window root; 109 | Window win; 110 | GLXContext ctx; 111 | XVisualInfo *visinfo; 112 | 113 | scrnum = DefaultScreen(dpy); 114 | //scrnum = 0; 115 | root = RootWindow(dpy, scrnum); 116 | 117 | visinfo = glXChooseVisual( dpy, scrnum, attrib ); 118 | if (!visinfo) { 119 | printf("Error: couldn't get an RGB, Double-buffered visual\n"); 120 | return false; 121 | } 122 | 123 | /* window attributes */ 124 | attr.background_pixel = 0; 125 | attr.border_pixel = 0; 126 | attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone); 127 | attr.event_mask = StructureNotifyMask | ExposureMask 128 | | KeyPressMask | KeyReleaseMask 129 | | PointerMotionMask 130 | | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask; 131 | mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; 132 | 133 | win = XCreateWindow( dpy, root, 0, 0, width, height, 134 | 0, visinfo->depth, InputOutput, 135 | visinfo->visual, mask, &attr ); 136 | if (!win) 137 | { 138 | printf("Error: couldn't create window."); 139 | return false; 140 | } 141 | 142 | /* set hints and properties */ 143 | XSizeHints sizehints; 144 | sizehints.x = 0; 145 | sizehints.y = 0; 146 | sizehints.width = width; 147 | sizehints.height = height; 148 | sizehints.flags = USSize | USPosition; 149 | XSetNormalHints(dpy, win, &sizehints); 150 | XSetStandardProperties(dpy, win, name, name, None, (char **)NULL, 0, &sizehints); 151 | 152 | ctx = glXCreateContext( dpy, visinfo, NULL, True ); 153 | if (!ctx) { 154 | printf("Error: glXCreateContext failed\n"); 155 | return false; 156 | } 157 | 158 | XFree(visinfo); 159 | *winRet = win; 160 | *ctxRet = ctx; 161 | return true; 162 | } 163 | 164 | CoreWindow::CoreWindow(int x, int y, int width, int height, const char* title, bool fullscreenMode) 165 | { 166 | m_imp = new Impl(); 167 | m_display = XOpenDisplay(0); 168 | 169 | m_imp->m_w = width; 170 | m_imp->m_h = height; 171 | bool r = make_window(m_display, title, 32, 24, width, height, &m_imp->m_win, &m_imp->m_ctx); 172 | XMapWindow(m_display, m_imp->m_win); 173 | glXMakeCurrent(m_display, m_imp->m_win, m_imp->m_ctx); 174 | g_win = this; 175 | glViewport(0,0,width,height); 176 | } 177 | CoreWindow::~CoreWindow() 178 | { 179 | // GL Context 180 | if (m_imp->m_ctx) 181 | { 182 | glXDestroyContext(m_display, m_imp->m_ctx); 183 | m_imp->m_ctx = 0; 184 | } 185 | if (m_imp->m_win){ 186 | XDestroyWindow(m_display, m_imp->m_win); 187 | m_imp->m_win = 0; 188 | } 189 | 190 | // XWindow 191 | if (m_display) 192 | { 193 | XCloseDisplay(m_display); 194 | m_display = 0; 195 | } 196 | delete m_imp; 197 | } 198 | void CoreWindow::Active() 199 | { 200 | glXMakeCurrent(m_display, m_imp->m_win, m_imp->m_ctx); 201 | } 202 | void CoreWindow::Toplevel(bool top) 203 | { 204 | 205 | } 206 | void CoreWindow::SwapBuffer() 207 | { 208 | glXSwapBuffers(m_display, g_win->m_imp->m_win); 209 | } 210 | void CoreWindow::DoEvents(void) 211 | { 212 | XEvent evt; 213 | KeySym key; 214 | char text[255]; 215 | int mx,my; 216 | 217 | if (!XPending(m_display)) 218 | return; 219 | 220 | XNextEvent(m_display, &evt ); 221 | //printf("EVENT=%d\n",evt.type); 222 | switch ( evt.type ) { 223 | case Expose: 224 | if ( evt.xexpose.count == 0 ) { 225 | g_win->Draw(); 226 | } 227 | return; 228 | 229 | case ButtonPress: 230 | mx = evt.xbutton.x; 231 | my = evt.xbutton.y; 232 | if( evt.xbutton.button == 1 ){ 233 | g_win->MouseLeftDown(mx,my); 234 | } else if( evt.xbutton.button == 2 ){ 235 | g_win->MouseMiddleDown(mx,my); 236 | } else if( evt.xbutton.button == 3 ){ 237 | g_win->MouseRightDown(mx,my); 238 | } else if( evt.xbutton.button == 4 ){ 239 | g_win->Wheel(0.0f, 1.0f, 0.0f); 240 | } else if( evt.xbutton.button == 5 ){ 241 | g_win->Wheel(0.0f,-1.0f, 0.0f); 242 | } 243 | return; 244 | case ButtonRelease: 245 | mx = evt.xbutton.x; 246 | my = evt.xbutton.y; 247 | if( evt.xbutton.button == 1 ){ 248 | g_win->MouseLeftUp(mx,my); 249 | } else if( evt.xbutton.button == 2 ){ 250 | g_win->MouseMiddleUp(mx,my); 251 | } else if( evt.xbutton.button == 3 ){ 252 | g_win->MouseRightUp(mx,my); 253 | } 254 | return; 255 | case MotionNotify: 256 | // get last motion event(for overflow motion event) 257 | while (XPending(m_display)) { 258 | XPeekEvent(m_display, &evt ); 259 | if (evt.type != MotionNotify) 260 | break; 261 | XNextEvent(m_display, &evt); 262 | } 263 | if (evt.xmotion.x != mx 264 | || evt.xmotion.y != my){ 265 | mx = evt.xmotion.x; 266 | my = evt.xmotion.y; 267 | g_win->MouseMove(mx, my); 268 | return; 269 | } 270 | case KeyPress: 271 | if (XLookupString(&evt.xkey,text,255,&key,0) == 1) { 272 | g_win->KeyDown(text[0]); 273 | } 274 | return; 275 | case KeyRelease: 276 | if (XLookupString(&evt.xkey,text,255,&key,0) == 1) { 277 | g_win->KeyUp(text[0]); 278 | } 279 | return ; 280 | 281 | case ConfigureNotify: 282 | if (g_win->m_imp->m_w != evt.xconfigure.width 283 | || g_win->m_imp->m_h != evt.xconfigure.height) { 284 | g_win->m_imp->m_w = evt.xconfigure.width; 285 | g_win->m_imp->m_h = evt.xconfigure.height; 286 | g_win->Resize(evt.xconfigure.width, evt.xconfigure.height); 287 | } 288 | return; 289 | } 290 | } 291 | void CoreWindow::MainLoop(void) 292 | { 293 | while( 1 ) { 294 | g_win->Idle(); 295 | DoEvents(); 296 | } 297 | } 298 | 299 | void CoreWindow::GoFullscreen(bool fullscreen, bool cursor) 300 | { 301 | // TODO 302 | } 303 | 304 | const char* CoreWindow::GetExePath() const 305 | { 306 | return 0; // TODO: 307 | } 308 | 309 | int CoreWindow::GetWidth() const 310 | { 311 | return m_imp->m_w; 312 | } 313 | 314 | int CoreWindow::GetHeight() const 315 | { 316 | return m_imp->m_h; 317 | } 318 | 319 | const char* CoreWindow::FileOpenDialog(const char* ext) const 320 | { 321 | return gtkFileOpenDialog(ext); 322 | } 323 | const char* CoreWindow::FileSaveDialog(const char* ext) const 324 | { 325 | return gtkFileSaveDialog(ext); 326 | } 327 | -------------------------------------------------------------------------------- /Core/CoreWindow_x11.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CoreWindow_x11.h 3 | * 4 | * Created by kioku on 13/01/11. 5 | * Copyright 2013 System K. All rights reserved. 6 | * 7 | */ 8 | 9 | #ifndef COREWINDOW_X11_HEADER 10 | #define COREWINDOW_X11_HEADER 11 | 12 | #include "CoreWindow.h" 13 | 14 | class CoreWindow : public CoreWindowPlatform 15 | { 16 | protected: 17 | CoreWindow(int x, int y, int width, int height, const char* title, bool fullscreenMode = false); 18 | ~CoreWindow(); 19 | public: 20 | 21 | virtual void MouseLeftDown (int x, int y){} 22 | virtual void MouseLeftUp (int x, int y){} 23 | virtual void MouseRightDown (int x, int y){} 24 | virtual void MouseRightUp (int x, int y){} 25 | virtual void MouseMiddleDown(int x, int y){} 26 | virtual void MouseMiddleUp (int x, int y){} 27 | virtual void MouseMove (int x, int y){} 28 | virtual void Wheel (float dx, float dy, float dz){} 29 | virtual void Magnify (float z) {} 30 | virtual void Swipe (float dx, float dy, float dz){} 31 | virtual void Rotate (float r) {} 32 | virtual void KeyDown (int key) {} 33 | virtual void KeyUp (int key) {} 34 | virtual void Resize (int w, int h){} 35 | virtual void Close (void) {} 36 | virtual void Idle (void) {} 37 | virtual void Draw (void) {} 38 | 39 | void Active(); 40 | void Toplevel(bool top); 41 | void SwapBuffer(); 42 | static void DoEvents(void); 43 | static void MainLoop(void); 44 | 45 | void GoFullscreen(bool fullscreen, bool cursor=true); 46 | 47 | int GetWidth() const; 48 | int GetHeight() const; 49 | 50 | const char* GetExePath() const; 51 | const char* FileOpenDialog(const char* ext) const; 52 | const char* FileSaveDialog(const char* ext) const; 53 | 54 | protected: 55 | class Impl; 56 | Impl* m_imp; 57 | }; 58 | 59 | void CoreWindow_DoEvents(); 60 | 61 | 62 | #endif // COREWINDOW_X11_HEADER 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | INCS= 2 | LIBS=-lGL 3 | 4 | DEFINES = -g 5 | 6 | CXX=g++ 7 | 8 | all: 9 | $(CXX) $(INCS) $(DEFINES) test.cpp Core/CoreWindow_x11.cpp $(LIBS) -o Test 10 | -------------------------------------------------------------------------------- /Makefile.emscripten: -------------------------------------------------------------------------------- 1 | 2 | DEFINES =-O2 -D__EMSCRIPTEN__ 3 | CXX=emcc 4 | SRC=test.cpp 5 | COREWIN=Core/CoreWindow_egl.cpp 6 | 7 | 8 | all: 9 | $(CXX) $(DEFINES) $(SRC) $(COREWIN) $(LIBS) -o Test.html 10 | -------------------------------------------------------------------------------- /Makefile.macosx: -------------------------------------------------------------------------------- 1 | INCS= 2 | LIBS=-framework OpenGL -framework Cocoa 3 | 4 | DEFINES = -g 5 | CXX=g++ 6 | 7 | all: 8 | mkdir -p Test.app/Contents/MacOS; 9 | $(CXX) $(INCS) $(DEFINES) test.cpp Core/CoreWindow_mac.mm $(LIBS) -o Test.app/Contents/MacOS/Test 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SimpleUI 2 | ======== 3 | 4 | UI implementation by OpenGL 5 | (Headers only implementation) 6 | 7 | OpenGL描画によるシンプルなUI実装 8 | ヘッダのインクルードのみで利用可能 9 | 10 | # Platform 11 | - Windows(Win32) 12 | - MacOSX(Cocoa) 13 | - Linux(X11) 14 | - WebGL(emscripten) 15 | 16 | # License 17 | - MIT License 18 | 19 | # Screenshots 20 | SimpleUI WebGL Sample 21 | 22 | ![screenshot_win](screenshots/screenshot_win.png) 23 | ![screenshot_mac](screenshots/screenshot_mac.png) 24 | ![screenshot_linux](screenshots/screenshot_linux.png) -------------------------------------------------------------------------------- /UI/SimpleGUI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SimpleGUI.h 3 | * SimpleGUI 4 | * 5 | * Created by kioku on 2012/09/14. 6 | * 7 | */ 8 | 9 | #ifndef INCLUDE_SIMGPLE_GUI_H 10 | #define INCLUDE_SIMGPLE_GUI_H 11 | 12 | #include "skBaseGUI.h" 13 | #include "SimpleGraphics.h" 14 | #include "SimpleShader.h" 15 | #include "SimpleTex.h" 16 | #include "SimpleVB.h" 17 | 18 | #include "icons.h" 19 | #define STRINGIFY(A) #A 20 | 21 | // Font data(TrueType font) 22 | #include "mplus1cmedium.h" 23 | 24 | // We use STB Truetype font lib 25 | #define STB_TRUETYPE_IMPLEMENTATION 26 | #include "stb_truetype.h" 27 | 28 | namespace SimpleGUI 29 | { 30 | const float UITextSize = 16; 31 | 32 | bool TGALoader(const unsigned char* buffer, int& w, int& h, const unsigned char** buf) 33 | { 34 | #ifdef __GNUC__ 35 | #pragma pack(push, 1) 36 | #define ALIGNMENT __attribute__((packed)) 37 | #else 38 | #pragma pack(1) 39 | #define ALIGNMENT 40 | #endif // __GNUC__ 41 | typedef struct 42 | { 43 | unsigned char identsize; 44 | unsigned char colourmaptype; 45 | unsigned char imagetype; 46 | short colourmapstart; 47 | short colourmaplength; 48 | unsigned char colourmapbits; 49 | short xstart; 50 | short ystart; 51 | short width; 52 | short height; 53 | unsigned char bits; 54 | unsigned char descriptor; 55 | } TGA_HEADER; 56 | #ifdef __GNUC__ 57 | #pragma pack(pop) 58 | #else 59 | #pragma pack() 60 | #endif // __GNUC__ 61 | 62 | const TGA_HEADER* header = reinterpret_cast(buffer); 63 | w = header->width; 64 | h = header->height; 65 | if (header->bits != 32 || header->colourmaptype != 0 || header->imagetype != 2) 66 | return false; 67 | *buf = buffer; 68 | *buf += 18; 69 | return true; 70 | } 71 | 72 | #define GLPRECISION "#ifdef GL_ES\nprecision highp float;\n#endif\n" 73 | 74 | class GUIManager : public skGUI::GUIManager 75 | { 76 | public: 77 | GUIManager() : skGUI::GUIManager() 78 | { 79 | static const char* vshader = GLPRECISION STRINGIFY( 80 | uniform mat4 proj; 81 | attribute vec3 pos; 82 | attribute vec4 col; 83 | attribute vec2 uv; 84 | varying vec4 color; 85 | varying vec2 tex; 86 | void main(void) { 87 | color = col; 88 | tex = uv; 89 | gl_Position = proj * vec4(pos,1); 90 | } 91 | ); 92 | static const char* fshader = GLPRECISION STRINGIFY( 93 | uniform sampler2D texture; 94 | uniform float mono; 95 | varying vec4 color; 96 | varying vec2 tex; 97 | void main(void) { 98 | vec4 t = texture2D(texture, tex); 99 | gl_FragColor = color * ((t.rrrr - t.rgba) * mono + t.rgba); 100 | } 101 | ); 102 | 103 | g = new skGUI::SimpleGraphics(); 104 | m_defshader = new skGUI::SimpleShader(g, vshader, fshader); 105 | m_defvb = new skGUI::SimpleVB(g, m_defshader); 106 | 107 | m_deftex = 0; 108 | int tw, th; 109 | const unsigned char* buf; 110 | if (TGALoader(icons, tw, th, &buf)) { 111 | m_deftex = new skGUI::SimpleTex(g, tw, th); 112 | unsigned char* data = m_deftex->Map(); 113 | // upsidedown 114 | for (int y = 0; y < th; ++y){ 115 | for (int x = 0; x < tw*4; x += 4){ 116 | data[tw * (th - y - 1) * 4 + x ] = buf[tw * y * 4 + x + 2]; 117 | data[tw * (th - y - 1) * 4 + x + 1] = buf[tw * y * 4 + x + 1]; 118 | data[tw * (th - y - 1) * 4 + x + 2] = buf[tw * y * 4 + x ]; 119 | data[tw * (th - y - 1) * 4 + x + 3] = buf[tw * y * 4 + x + 3]; 120 | } 121 | } 122 | m_deftex->Unmap(); 123 | } 124 | } 125 | ~GUIManager() 126 | { 127 | delete m_deftex; 128 | delete m_defvb; 129 | delete m_defshader; 130 | delete g; 131 | } 132 | 133 | skGUI::SimpleGraphics* GetGraphics() const 134 | { 135 | return g; 136 | } 137 | 138 | skGUI::SimpleVB* GetDefaultVB() const 139 | { 140 | return m_defvb; 141 | } 142 | 143 | skGUI::SimpleShader* GetDefaultShader() const 144 | { 145 | return m_defshader; 146 | } 147 | 148 | const skGUI::SimpleTex* GetTex() const 149 | { 150 | return m_deftex; 151 | } 152 | 153 | protected: 154 | void Ortho(float l, float r, float t, float b, float nearval, float farval, float mat[16]) 155 | { 156 | const float x = 2.0f / (r - l); 157 | const float y = 2.0f / (t - b); 158 | const float z = -2.0f / (farval - nearval); 159 | const float tx = - (r + l) / (r - l); 160 | const float ty = - (t + b) / (t - b); 161 | const float tz = - (farval + nearval) / (farval - nearval); 162 | for (int i = 0; i < 16; ++i) 163 | mat[i] = 0; 164 | mat[ 0] = x; 165 | mat[ 5] = y; 166 | mat[10] = z; 167 | mat[12] = tx; 168 | mat[13] = ty; 169 | mat[14] = tz; 170 | mat[15] = 1.0f; 171 | } 172 | 173 | void beginUI() 174 | { 175 | g->Clear(SG_DEPTH_BUFFER_BIT); 176 | m_defvb->Clear(); 177 | g->BlendFunc(SG_SRC_ALPHA, SG_ONE_MINUS_SRC_ALPHA); 178 | g->Enable(SG_BLEND); 179 | float proj[16]; 180 | Ortho(0.0f, static_cast(m_width), 0.0f, static_cast(m_height), -100.0f, 100.0f, proj); 181 | m_defshader->Bind(); 182 | m_defshader->SetUniformMatrix4x4("proj", 1, false, proj); 183 | m_defshader->SetUniform("texture", 0); 184 | m_defshader->SetUniform("mono",0.0f); 185 | m_defshader->Unbind(); 186 | g->BindTexture(SG_TEXTURE_2D, m_deftex->GetID()); 187 | } 188 | void endUI() 189 | { 190 | m_defvb->Update(); 191 | m_defvb->Draw(); 192 | 193 | g->BlendFunc(SG_ONE, SG_ONE);//_MINUS_SRC_ALPHA); 194 | m_defshader->Bind(); 195 | m_defshader->SetUniform("mono",1.0f); 196 | m_defshader->Unbind(); 197 | const int n = static_cast(m_drawsets.size()); 198 | for (int i = 0; i < n; ++i) { 199 | g->BindTexture(SG_TEXTURE_2D, m_drawsets[i].tex->GetID()); 200 | m_drawsets[i].vb->Draw(); 201 | } 202 | 203 | g->Disable(SG_BLEND); 204 | } 205 | 206 | friend class Caption; 207 | void addDrawSet(skGUI::SimpleVB* vb, skGUI::SimpleTex* tex) 208 | { 209 | m_drawsets.push_back(DrawSet(vb, tex)); 210 | } 211 | void removeDrawSet(skGUI::SimpleVB* vb, skGUI::SimpleTex* tex) 212 | { 213 | size_t n = m_drawsets.size(); 214 | for (size_t i = 0; i < n; ++i){ 215 | if( m_drawsets[i].vb == vb && m_drawsets[i].tex == tex) { 216 | m_drawsets.erase(m_drawsets.begin() + i); 217 | return; 218 | } 219 | } 220 | } 221 | 222 | private: 223 | skGUI::SimpleGraphics* g; 224 | skGUI::SimpleShader* m_defshader; 225 | skGUI::SimpleVB* m_defvb; 226 | skGUI::SimpleTex* m_deftex; 227 | class DrawSet{ 228 | public: 229 | DrawSet(skGUI::SimpleVB* vb_, skGUI::SimpleTex* tex_):vb(vb_),tex(tex_){} 230 | skGUI::SimpleVB* vb; 231 | skGUI::SimpleTex* tex; 232 | }; 233 | std::vector m_drawsets; 234 | 235 | }; 236 | 237 | enum UITYPE{ 238 | UITYPE_FRAME, 239 | UITYPE_DIALOG, 240 | UITYPE_GRAPHIC, 241 | UITYPE_BUTTON, 242 | UITYPE_SLIDER, 243 | UITYPE_CAPTION, 244 | UITYPE_CHECK 245 | }; 246 | 247 | class Frame : public skGUI::BaseWindow 248 | { 249 | public: 250 | Frame(GUIManager* mgr, int x, int y, int w, int h, const float color[4], int z = 0) : skGUI::BaseWindow(UITYPE_FRAME) 251 | { 252 | m_defvb = mgr->GetDefaultVB(); 253 | m_x = x; m_y = y; m_width = w; m_height = h; 254 | m_color[0] = color[0]; 255 | m_color[1] = color[1]; 256 | m_color[2] = color[2]; 257 | m_color[3] = color[3]; 258 | m_z = z; 259 | } 260 | ~Frame() 261 | { 262 | } 263 | void SetColor(const float color[4]) 264 | { 265 | m_color[0] = color[0]; 266 | m_color[1] = color[1]; 267 | m_color[2] = color[2]; 268 | m_color[3] = color[3]; 269 | } 270 | protected: 271 | skGUI::BaseWindow* ownHit(int x, int y){ 272 | if (x >= 0 && x < m_width 273 | && y >= 0 && y < m_height) return this; 274 | else return 0; 275 | } 276 | void ownDraw (int parent_x, int parent_y) 277 | { 278 | const int sx = parent_x + m_x; 279 | const int sy = parent_y + m_y; 280 | m_defvb->Color4f(m_color[0], m_color[1], m_color[2], m_color[3]); 281 | m_defvb->Texcoord2f(1.0f, 1.0f); 282 | m_defvb->Rect2f(static_cast(sx), static_cast(sy), 283 | static_cast(sx + m_width), static_cast(sy + m_height), static_cast(m_z)); 284 | } 285 | bool ownMouseDown (int button, int x, int y){ return ownHit(x,y) > 0; } 286 | bool ownMouseUp (int button, int x, int y){ return ownHit(x,y) > 0; } 287 | void ownMouseMove (int x, int y){} 288 | private: 289 | skGUI::SimpleVB* m_defvb; 290 | float m_color[4]; 291 | int m_z; 292 | }; 293 | 294 | class Dialog : public skGUI::BaseWindow 295 | { 296 | public: 297 | Dialog(GUIManager* mgr, int x, int y, int w, int h, int z = 0) 298 | : skGUI::BaseWindow(UITYPE_DIALOG) 299 | { 300 | m_defvb = mgr->GetDefaultVB(); 301 | m_tex_w = static_cast(mgr->GetTex()->GetWidth()); 302 | m_tex_h = static_cast(mgr->GetTex()->GetHeight()); 303 | m_x = x; m_y = y; 304 | m_tx = 0; m_ty = 0; 305 | m_width = w; m_height = h; 306 | m_z = z; 307 | m_press = false; 308 | m_alpha = 1.0f; 309 | } 310 | ~Dialog() 311 | { 312 | } 313 | 314 | void SetAlpha(float alpha) 315 | { 316 | m_alpha = alpha; 317 | } 318 | protected: 319 | BaseWindow* ownHit(int x, int y){ 320 | if (x >= 0 && x < m_width 321 | && y >= 0 && y < m_height) 322 | return this; 323 | else 324 | return 0; 325 | } 326 | void ownDraw (int parent_x, int parent_y) 327 | { 328 | const int sx = parent_x + m_x; 329 | const int sy = parent_y + m_y; 330 | const int ex = parent_x + m_x + m_width; 331 | const int ey = parent_y + m_y + m_height; 332 | const int dxy = 4; 333 | const float su = m_tx / m_tex_w; 334 | const float sv = 1.0f - m_ty / m_tex_h; 335 | const float eu = (m_tx + 12) / m_tex_w; 336 | const float ev = 1.0f - (m_ty + 12) / m_tex_h; 337 | const float du = 4.0f / m_tex_w; 338 | const float dv = -4.0f / m_tex_h; 339 | 340 | m_defvb->Color4f(1.0f,1.0f,1.0f,m_alpha); 341 | m_defvb->RectUV9Grid(static_cast(sx), static_cast(sy), 342 | static_cast(ex), static_cast(ey), static_cast(m_z), static_cast(dxy), 343 | su, sv, eu, ev, du,dv); 344 | 345 | } 346 | bool ownMouseDown (int button, int x, int y) 347 | { 348 | if (ownHit(x,y)) 349 | { 350 | m_press = true; 351 | m_mousex = x; 352 | m_mousey = y; 353 | return true; 354 | } 355 | return false; 356 | } 357 | bool ownMouseUp (int button, int x, int y) 358 | { 359 | bool r = false; 360 | if (m_press) 361 | r = true; 362 | m_press = false; 363 | return r; 364 | } 365 | void ownMouseMove (int x, int y) 366 | { 367 | if (m_press && m_active) 368 | { 369 | int dx = x - m_mousex; 370 | int dy = y - m_mousey; 371 | this->m_x += dx; 372 | this->m_y += dy; 373 | } 374 | } 375 | 376 | skGUI::SimpleVB* m_defvb; 377 | int m_tx, m_ty; 378 | int m_z; 379 | float m_tex_w,m_tex_h; 380 | bool m_press; 381 | int m_mousex,m_mousey; 382 | float m_alpha; 383 | }; 384 | 385 | class textRasterizer 386 | { 387 | private: 388 | textRasterizer() 389 | { 390 | const unsigned char* fontdata = mplus1cmedium; 391 | stbtt_InitFont(&font, fontdata, 0); 392 | } 393 | ~textRasterizer() 394 | { 395 | } 396 | public: 397 | static textRasterizer& GetInstance() 398 | { 399 | static textRasterizer singleton; 400 | return singleton; 401 | } 402 | 403 | void GetTextSize(const char* text, float fontsize, int& w, int& h, int& rw) const 404 | { 405 | int ascent,baseline,ch=0; 406 | float scale, xpos=0; 407 | scale = stbtt_ScaleForPixelHeight(&font, fontsize); 408 | stbtt_GetFontVMetrics(&font, &ascent,0,0); 409 | baseline = (int) (ascent * scale); 410 | 411 | while (text[ch]) { 412 | int chcode = static_cast(*reinterpret_cast(&text[ch])); 413 | int advance,lsb,x0,y0,x1,y1; 414 | float x_shift = xpos - (float) floor(xpos); 415 | stbtt_GetCodepointHMetrics(&font,chcode, &advance, &lsb); 416 | stbtt_GetCodepointBitmapBoxSubpixel(&font, chcode, scale,scale,x_shift,0, &x0,&y0,&x1,&y1); 417 | xpos += (advance * scale); 418 | if (chcode) 419 | xpos += scale * stbtt_GetCodepointKernAdvance(&font, chcode,chcode); 420 | ch++; 421 | } 422 | int ixpos = static_cast(xpos); 423 | rw = ixpos; 424 | w = (((ixpos+3)>>2)<<2); // 4byte align 425 | h = static_cast(fontsize); 426 | w = (w < 4 ? 4 : w); 427 | h = (h < 4 ? 4 : h); 428 | w += 4; // not just size? 429 | } 430 | 431 | void DrawText(const char* text, float fontsize, unsigned char* buf, int buf_w) const 432 | { 433 | int ascent,baseline,ch=0; 434 | float scale, xpos=0; 435 | scale = stbtt_ScaleForPixelHeight(&font, fontsize); 436 | stbtt_GetFontVMetrics(&font, &ascent,0,0); 437 | baseline = (int) (ascent * scale); 438 | 439 | while (text[ch]) { 440 | int chcode = static_cast(*reinterpret_cast(&text[ch])); 441 | int advance,lsb,x0,y0,x1,y1; 442 | float x_shift = xpos - (float) floor(xpos); 443 | stbtt_GetCodepointHMetrics(&font,chcode, &advance, &lsb); 444 | stbtt_GetCodepointBitmapBoxSubpixel(&font, chcode, scale,scale,x_shift,0, &x0,&y0,&x1,&y1); 445 | const float nextstep = scale*stbtt_GetCodepointKernAdvance(&font, chcode,chcode) + (advance * scale); 446 | if (xpos + nextstep > buf_w) 447 | break; 448 | unsigned char* bit = &buf[((baseline + y0) * buf_w + (int)xpos + x0)]; 449 | stbtt_MakeCodepointBitmapSubpixel(&font, bit, x1-x0,y1-y0, buf_w, scale,scale,x_shift,0, chcode); 450 | xpos += nextstep; 451 | ch++; 452 | } 453 | } 454 | 455 | private: 456 | stbtt_fontinfo font; 457 | }; 458 | 459 | class Caption : public skGUI::BaseWindow 460 | { 461 | public: 462 | Caption(GUIManager* mgr, int x, int y, const char* text, float size, int z = 0, int maxwsize = 0) : BaseWindow(UITYPE_CAPTION) 463 | { 464 | const float col[] = {1.0f,1.0f,1.0f,1.0f}; 465 | m_mgr = mgr; 466 | m_vb = new skGUI::SimpleVB(mgr->GetGraphics(), mgr->GetDefaultShader()); 467 | m_x = x; m_y = y; 468 | m_z = z; 469 | m_size = size; 470 | m_color[0] = col[0]; 471 | m_color[1] = col[1]; 472 | m_color[2] = col[2]; 473 | m_color[3] = col[3]; 474 | 475 | textRasterizer& txt = textRasterizer::GetInstance(); 476 | int w,h,rw; 477 | txt.GetTextSize(text, size, w, h, rw); 478 | m_realwidth = rw; 479 | m_width = w; 480 | m_maxwsize = maxwsize = (((maxwsize + 3) >> 2) << 2); 481 | if (maxwsize != 0) 482 | m_width = (maxwsize < m_width ? maxwsize : m_width); 483 | m_height = h; 484 | m_tex = new skGUI::SimpleTex(mgr->GetGraphics(), m_width, m_height, skGUI::SimpleTex::COLOR_R8); 485 | unsigned char* ptr = m_tex->Map(); 486 | memset(ptr, 0x00, w*h); 487 | txt.DrawText(text,size,ptr,m_width); 488 | m_tex->Unmap(); 489 | m_mgr->addDrawSet(m_vb, m_tex); 490 | //ownDraw(0,0); 491 | } 492 | ~Caption() 493 | { 494 | m_mgr->removeDrawSet(m_vb,m_tex); 495 | delete m_tex; 496 | delete m_vb; 497 | } 498 | void SetText(const char* text) 499 | { 500 | textRasterizer& txt = textRasterizer::GetInstance(); 501 | int w,h,rw; 502 | txt.GetTextSize(text, static_cast(m_size), w, h,rw); 503 | m_width = w; 504 | if (m_maxwsize != 0) 505 | m_width = (m_maxwsize < m_width ? m_maxwsize : m_width); 506 | m_height = h; 507 | m_realwidth = rw; 508 | m_tex->Resize(m_width,m_height); 509 | unsigned char* ptr = m_tex->Map(); 510 | memset(ptr, 0x00, w*h); 511 | txt.DrawText(text,static_cast(m_size),ptr,m_width); 512 | m_tex->Unmap(); 513 | } 514 | 515 | int GetRealWidth() const 516 | { 517 | return m_realwidth; 518 | } 519 | protected: 520 | BaseWindow* ownHit(int x, int y){ 521 | if (x >= 0 && x < m_width && y >= 0 && y < m_height) return this; 522 | else return 0; 523 | } 524 | void ownDraw (int parent_x, int parent_y) 525 | { 526 | const int sx = parent_x + m_x; 527 | const int sy = parent_y + m_y; 528 | if (m_cache_x != sx || m_cache_y != sy || m_cache_w != m_width || m_cache_h != m_height) { 529 | m_vb->Clear(); 530 | m_vb->Color4f(m_color[0],m_color[1],m_color[2],m_color[3]); 531 | m_vb->RectUV2f(static_cast(sx), static_cast(sy), 532 | static_cast(sx + m_width), static_cast(sy + m_height), static_cast(m_z), 0.0f, 0.0f, 1.0f, 1.0f); 533 | m_vb->Update(); 534 | } 535 | m_cache_x = sx; 536 | m_cache_y = sy; 537 | m_cache_w = m_width; 538 | m_cache_h = m_height; 539 | } 540 | bool ownMouseDown (int button, int x, int y) { return false; } 541 | bool ownMouseUp (int button, int x, int y) { return false; } 542 | void ownMouseMove (int x, int y) {} 543 | private: 544 | GUIManager* m_mgr; 545 | skGUI::SimpleGraphics* g; 546 | skGUI::SimpleVB* m_vb; 547 | skGUI::SimpleTex* m_tex; 548 | float m_color[4]; 549 | int m_cache_x, m_cache_y, m_cache_w, m_cache_h; 550 | float m_size; 551 | int m_maxwsize; 552 | int m_z; 553 | int m_realwidth; 554 | }; 555 | 556 | 557 | class Button : public skGUI::BaseWindow 558 | { 559 | public: 560 | Button(GUIManager* mgr, const char* caption, int x, int y, int w, int h, int z = 0) 561 | : skGUI::BaseWindow(UITYPE_BUTTON) 562 | { 563 | m_defvb = mgr->GetDefaultVB(); 564 | m_tex_w = static_cast(mgr->GetTex()->GetWidth()); 565 | m_tex_h = static_cast(mgr->GetTex()->GetHeight()); 566 | m_x = x; m_y = y; 567 | m_tx = 14; m_ty = 0; 568 | m_width = w; m_height = h; 569 | m_z = z; 570 | m_over = false; 571 | m_press = false; 572 | m_func = 0; 573 | m_thisptr = 0; 574 | Caption* txt = new Caption(mgr, 0,0,caption, UITextSize, z+1); 575 | int txt_x = (w - txt->GetRealWidth()) / 2; 576 | int txt_y = (h - txt->GetHeight()) / 2; 577 | txt->SetPos(txt_x, txt_y); 578 | AddChild(txt); 579 | } 580 | ~Button() 581 | { 582 | } 583 | void SetClickedFunc(void (*func)(void*), void* thisptr) 584 | { 585 | m_func = func; 586 | m_thisptr = thisptr; 587 | } 588 | protected: 589 | BaseWindow* ownHit(int x, int y){ 590 | if (x >= 0 && x < m_width 591 | && y >= 0 && y < m_height) 592 | return this; 593 | else 594 | return 0; 595 | } 596 | void ownDraw (int parent_x, int parent_y) 597 | { 598 | const int sx = parent_x + m_x; 599 | const int sy = parent_y + m_y; 600 | const int ex = parent_x + m_x + m_width; 601 | const int ey = parent_y + m_y + m_height; 602 | const int dxy = 4; 603 | const float su = m_tx / m_tex_w; 604 | const float sv = 1.0f - m_ty / m_tex_h; 605 | const float eu = (m_tx + 12) / m_tex_w; 606 | const float ev = 1.0f - (m_ty + 12) / m_tex_h; 607 | const float du = 4.0f / m_tex_w; 608 | const float dv = -4.0f / m_tex_h; 609 | 610 | if (m_press) 611 | m_defvb->Color4f(1.0f,0.5f,0.4f,1.0f); 612 | else if (m_over) 613 | m_defvb->Color4f(1.0f,0.8f,0.7f,1.0f); 614 | else 615 | m_defvb->Color4f(1.0f,1.0f,1.0f,1.0f); 616 | 617 | m_defvb->RectUV9Grid(static_cast(sx), static_cast(sy), 618 | static_cast(ex), static_cast(ey), static_cast(m_z), static_cast(dxy), 619 | su, sv, eu, ev, du,dv); 620 | 621 | } 622 | bool ownMouseDown (int button, int x, int y) 623 | { 624 | if (ownHit(x,y)) { 625 | m_press = true; 626 | return true; 627 | } 628 | return false; 629 | } 630 | bool ownMouseUp (int button, int x, int y) 631 | { 632 | bool r = false; 633 | if (m_press && ownHit(x,y) && m_func) { 634 | (*m_func)(m_thisptr); 635 | r = true; 636 | } 637 | m_press = false; 638 | return r; 639 | } 640 | void ownMouseMove (int x, int y) 641 | { 642 | if (ownHit(x,y)) 643 | m_over = true; 644 | else 645 | m_over = false; 646 | 647 | } 648 | 649 | skGUI::SimpleVB* m_defvb; 650 | int m_tx, m_ty; 651 | int m_z; 652 | float m_tex_w,m_tex_h; 653 | bool m_over, m_press; 654 | void (*m_func)(void*); 655 | void* m_thisptr; 656 | }; 657 | 658 | class Slider : public skGUI::BaseWindow 659 | { 660 | public: 661 | Slider(GUIManager* mgr, int x, int y, int w, int h, int z = 0) 662 | : skGUI::BaseWindow(UITYPE_SLIDER) 663 | { 664 | m_defvb = mgr->GetDefaultVB(); 665 | m_tex_w = static_cast(mgr->GetTex()->GetWidth()); 666 | m_tex_h = static_cast(mgr->GetTex()->GetHeight()); 667 | m_x = x; m_y = y; 668 | m_tx = 14; m_ty = 0; 669 | m_width = w; m_height = h; 670 | m_z = z; 671 | m_over = false; 672 | m_press = false; 673 | m_val = 0.0f; 674 | m_func = 0; 675 | m_thisptr = 0; 676 | } 677 | ~Slider() 678 | { 679 | } 680 | 681 | float GetValue() const 682 | { 683 | return m_val; 684 | } 685 | void SetValue(float val) 686 | { 687 | changeVal(val); 688 | } 689 | void SetChangedFunc(void (*func)(float, void*), void* thisptr) 690 | { 691 | m_func = func; 692 | m_thisptr = thisptr; 693 | } 694 | protected: 695 | BaseWindow* ownHit(int x, int y){ 696 | if (x >= 0 && x < m_width 697 | && y >= 0 && y < 10) 698 | return this; 699 | else 700 | return 0; 701 | } 702 | void ownDraw (int parent_x, int parent_y) 703 | { 704 | const int sx = parent_x + m_x; 705 | const int sy = parent_y + m_y; 706 | const int ex = parent_x + m_x + m_width; 707 | //const int ey = parent_y + m_y + m_height; 708 | 709 | m_defvb->Texcoord2f(1.0f,1.0f); 710 | if (m_over) 711 | m_defvb->Color4f(0.59f,0.33f,0.23f,1.0f); 712 | else 713 | m_defvb->Color4f(0.0f,0.0f,0.0f,1.0f); 714 | m_defvb->Rect2f(static_cast(sx), static_cast(sy), 715 | static_cast(ex), static_cast(sy+10), 716 | static_cast(m_z)); 717 | 718 | m_defvb->Color4f(0.91f,0.31f,0.10f,1.0f); 719 | m_defvb->Rect2f(static_cast(sx+1), static_cast(sy+1), 720 | static_cast(sx+1)+m_val*(ex-sx-1), static_cast(sy+9), 721 | static_cast(m_z)); 722 | 723 | m_defvb->Color4f(0.21f,0.21f,0.21f,1.0f); 724 | m_defvb->Rect2f(static_cast(sx+1)+m_val*(ex-sx-1), static_cast(sy+1), 725 | static_cast(ex-1), static_cast(sy+9), 726 | static_cast(m_z)); 727 | 728 | 729 | } 730 | 731 | void changeVal(float v) 732 | { 733 | m_val = v; 734 | m_val = m_val < 0.0f ? 0.0f : m_val; 735 | m_val = m_val > 1.0f ? 1.0f : m_val; 736 | if (m_func) 737 | (*m_func)(m_val, m_thisptr); 738 | } 739 | bool ownMouseDown (int button, int x, int y) 740 | { 741 | if (ownHit(x,y)) { 742 | m_press = true; 743 | changeVal(x / static_cast(m_width)); 744 | return true; 745 | } 746 | return false; 747 | } 748 | bool ownMouseUp (int button, int x, int y) 749 | { 750 | bool r = false; 751 | if (m_press) 752 | r = true; 753 | m_press = false; 754 | return r; 755 | } 756 | void ownMouseMove (int x, int y) 757 | { 758 | bool r = (ownHit(x,y) != 0); 759 | m_over = r; 760 | 761 | if (!m_press) 762 | return; 763 | 764 | if (m_active) 765 | { 766 | changeVal(x / static_cast(m_width)); 767 | } 768 | } 769 | 770 | skGUI::SimpleVB* m_defvb; 771 | int m_tx, m_ty; 772 | int m_z; 773 | float m_tex_w,m_tex_h; 774 | 775 | bool m_over; 776 | bool m_press; 777 | float m_val; 778 | 779 | void (*m_func)(float, void*); 780 | void* m_thisptr; 781 | }; 782 | 783 | class Check : public skGUI::BaseWindow 784 | { 785 | public: 786 | Check(GUIManager* mgr, const char* caption, int x, int y, int z = 0) 787 | : skGUI::BaseWindow(UITYPE_CHECK) 788 | { 789 | m_defvb = mgr->GetDefaultVB(); 790 | m_tex_w = static_cast(mgr->GetTex()->GetWidth()); 791 | m_tex_h = static_cast(mgr->GetTex()->GetHeight()); 792 | m_x = x; m_y = y; 793 | m_z = z; 794 | m_over = false; 795 | m_press = false; 796 | m_state = false; 797 | m_func = 0; 798 | m_thisptr = 0; 799 | Caption* txt = new Caption(mgr, 0,0,caption, UITextSize, z+1); 800 | m_width = 16 + txt->GetRealWidth(); 801 | m_height = static_cast(UITextSize); 802 | int txt_x = 16; 803 | int txt_y = (16 - txt->GetHeight()) / 2; 804 | txt->SetPos(txt_x, txt_y); 805 | AddChild(txt); 806 | } 807 | ~Check() 808 | { 809 | } 810 | void SetChangedFunc(void (*func)(bool, void*), void* thisptr) 811 | { 812 | m_func = func; 813 | m_thisptr = thisptr; 814 | } 815 | protected: 816 | BaseWindow* ownHit(int x, int y){ 817 | if (x >= 0 && x < m_width 818 | && y >= 0 && y < m_height) 819 | return this; 820 | else 821 | return 0; 822 | } 823 | void ownDraw (int parent_x, int parent_y) 824 | { 825 | const int sx = parent_x + m_x + 3; 826 | const int sy = parent_y + m_y + 3; 827 | const int ex = parent_x + m_x + 15; 828 | const int ey = parent_y + m_y + 15; 829 | const int tx = 28; 830 | int ty = 0; 831 | if (m_state) 832 | ty = 12; 833 | const float su = tx / m_tex_w; 834 | const float sv = 1.0f - ty / m_tex_h; 835 | const float eu = (tx + 12) / m_tex_w; 836 | const float ev = 1.0f - (ty + 12) / m_tex_h; 837 | 838 | if (m_over) 839 | m_defvb->Color4f(1.0f,0.8f,0.7f,1.0f); 840 | else 841 | m_defvb->Color4f(1.0f,1.0f,1.0f,1.0f); 842 | 843 | m_defvb->RectUV2f(static_cast(sx), static_cast(sy), 844 | static_cast(ex), static_cast(ey), static_cast(m_z), 845 | su, sv, eu, ev); 846 | 847 | } 848 | bool ownMouseDown (int button, int x, int y) 849 | { 850 | if (ownHit(x,y)) { 851 | m_press = true; 852 | return true; 853 | } 854 | return false; 855 | } 856 | bool ownMouseUp (int button, int x, int y) 857 | { 858 | bool r = false; 859 | if (m_press && ownHit(x,y)){ 860 | m_state = !m_state; 861 | if (m_func) 862 | (*m_func)(m_state,m_thisptr); 863 | r = true; 864 | } 865 | m_press = false; 866 | return r; 867 | } 868 | void ownMouseMove (int x, int y) 869 | { 870 | if (ownHit(x,y)) 871 | m_over = true; 872 | else 873 | m_over = false; 874 | 875 | } 876 | 877 | void SetState(bool state) 878 | { 879 | m_state = state; 880 | if (m_func) 881 | (*m_func)(state,m_thisptr); 882 | } 883 | 884 | bool GetState() const 885 | { 886 | return m_state; 887 | } 888 | 889 | skGUI::SimpleVB* m_defvb; 890 | int m_z; 891 | float m_tex_w,m_tex_h; 892 | bool m_over, m_press, m_state; 893 | void (*m_func)(bool,void*); 894 | void* m_thisptr; 895 | }; 896 | 897 | }// SimpleGUI 898 | 899 | #endif // INCLUDE_SIMGPLE_GUI_H 900 | 901 | -------------------------------------------------------------------------------- /UI/SimpleGraphics.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SimpleGraphics.h 3 | * 4 | * coded by kioku / System K 5 | * 6 | */ 7 | 8 | #ifndef INCLUDE_SIMPLEGRAPHICS_H 9 | #define INCLUDE_SIMPLEGRAPHICS_H 10 | 11 | namespace skGUI { 12 | 13 | typedef unsigned int SGenum; 14 | 15 | class SimpleGraphics 16 | { 17 | public: 18 | SimpleGraphics(); 19 | ~SimpleGraphics(); 20 | 21 | public: 22 | void AttachShader (unsigned int program, unsigned int shader); 23 | void BindAttribLocation (unsigned int program, unsigned int index, const char* name); 24 | void BindBuffer (SGenum target, unsigned int buffer); 25 | void BindTexture (SGenum target, unsigned int texture); 26 | void BlendFunc (SGenum sfactor, SGenum dfactor); 27 | void BufferData (SGenum target, int size, const void* data, SGenum usage); 28 | void BufferSubData (SGenum target, int offset, int size, const void* data); 29 | void Clear (unsigned int mask); 30 | void ClearColor (float red, float green, float blue, float alpha); 31 | void CompileShader (unsigned int shader); 32 | unsigned int CreateProgram (void); 33 | unsigned int CreateShader (SGenum type); 34 | void CullFace (SGenum mode); 35 | void DeleteBuffers (int n, const unsigned int* buffers); 36 | void DeleteProgram (unsigned int program); 37 | void DeleteShader (unsigned int shader); 38 | void DeleteTextures (int n, const unsigned int* textures); 39 | void Disable (SGenum cap); 40 | void DisableVertexAttribArray (unsigned int index); 41 | void DrawArrays (SGenum mode, int first, int count); 42 | void DrawElements (SGenum mode, int count, SGenum type, const void* indices); 43 | void Enable (SGenum cap); 44 | void EnableVertexAttribArray (unsigned int index); 45 | void GenBuffers (int n, unsigned int* buffers); 46 | void GenTextures (int n, unsigned int* textures); 47 | int GetAttribLocation (unsigned int program, const char* name); 48 | SGenum GetError (void); 49 | void GetFloatv (SGenum pname, float* params); 50 | void GetIntegerv (SGenum pname, int* params); 51 | void GetProgramiv (unsigned int program, SGenum pname, int* params); 52 | void GetProgramInfoLog (unsigned int program, int bufsize, int* length, char* infolog); 53 | void GetShaderiv (unsigned int shader, SGenum pname, int* params); 54 | void GetShaderInfoLog (unsigned int shader, int bufsize, int* length, char* infolog); 55 | int GetUniformLocation (unsigned int program, const char* name); 56 | void LinkProgram (unsigned int program); 57 | void ShaderSource (unsigned int shader, int count, const char** string, const int* length); 58 | void TexImage2D (SGenum target, int level, int internalformat, int width, int height, int border, SGenum format, SGenum type, const void* pixels); 59 | void TexParameterf (SGenum target, SGenum pname, float param); 60 | void TexParameterfv (SGenum target, SGenum pname, const float* params); 61 | void TexParameteri (SGenum target, SGenum pname, int param); 62 | void TexParameteriv (SGenum target, SGenum pname, const int* params); 63 | void TexSubImage2D (SGenum target, int level, int xoffset, int yoffset, int width, int height, SGenum format, SGenum type, const void* pixels); 64 | void Uniform1f (int location, float x); 65 | void Uniform1fv (int location, int count, const float* v); 66 | void Uniform1i (int location, int x); 67 | void Uniform1iv (int location, int count, const int* v); 68 | void Uniform2f (int location, float x, float y); 69 | void Uniform2fv (int location, int count, const float* v); 70 | void Uniform2i (int location, int x, int y); 71 | void Uniform2iv (int location, int count, const int* v); 72 | void Uniform3f (int location, float x, float y, float z); 73 | void Uniform3fv (int location, int count, const float* v); 74 | void Uniform3i (int location, int x, int y, int z); 75 | void Uniform3iv (int location, int count, const int* v); 76 | void Uniform4f (int location, float x, float y, float z, float w); 77 | void Uniform4fv (int location, int count, const float* v); 78 | void Uniform4i (int location, int x, int y, int z, int w); 79 | void Uniform4iv (int location, int count, const int* v); 80 | void UniformMatrix2fv (int location, int count, unsigned char transpose, const float* value); 81 | void UniformMatrix3fv (int location, int count, unsigned char transpose, const float* value); 82 | void UniformMatrix4fv (int location, int count, unsigned char transpose, const float* value); 83 | void UseProgram (unsigned int program); 84 | void ValidateProgram (unsigned int program); 85 | void VertexAttribPointer (unsigned int indx, int size, SGenum type, unsigned char normalized, int stride, const void* ptr); 86 | void Viewport (int x, int y, int width, int height); 87 | 88 | }; 89 | 90 | } // namespace SG 91 | 92 | /* ClearBufferMask */ 93 | #define SG_DEPTH_BUFFER_BIT 0x00000100 94 | #define SG_STENCIL_BUFFER_BIT 0x00000400 95 | #define SG_COLOR_BUFFER_BIT 0x00004000 96 | 97 | /* Boolean */ 98 | #define SG_FALSE 0 99 | #define SG_TRUE 1 100 | 101 | /* BeginMode */ 102 | #define SG_POINTS 0x0000 103 | #define SG_LINES 0x0001 104 | #define SG_LINE_LOOP 0x0002 105 | #define SG_LINE_STRIP 0x0003 106 | #define SG_TRIANGLES 0x0004 107 | #define SG_TRIANGLE_STRIP 0x0005 108 | #define SG_TRIANGLE_FAN 0x0006 109 | 110 | /* AlphaFunction (not supported in ES20) */ 111 | /* SG_NEVER */ 112 | /* SG_LESS */ 113 | /* SG_EQUAL */ 114 | /* SG_LEQUAL */ 115 | /* SG_GREATER */ 116 | /* SG_NOTEQUAL */ 117 | /* SG_GEQUAL */ 118 | /* SG_ALWAYS */ 119 | 120 | /* BlendingFactorDest */ 121 | #define SG_ZERO 0 122 | #define SG_ONE 1 123 | #define SG_SRC_COLOR 0x0300 124 | #define SG_ONE_MINUS_SRC_COLOR 0x0301 125 | #define SG_SRC_ALPHA 0x0302 126 | #define SG_ONE_MINUS_SRC_ALPHA 0x0303 127 | #define SG_DST_ALPHA 0x0304 128 | #define SG_ONE_MINUS_DST_ALPHA 0x0305 129 | 130 | /* BlendingFactorSrc */ 131 | /* SG_ZERO */ 132 | /* SG_ONE */ 133 | #define SG_DST_COLOR 0x0306 134 | #define SG_ONE_MINUS_DST_COLOR 0x0307 135 | #define SG_SRC_ALPHA_SATURATE 0x0308 136 | /* SG_SRC_ALPHA */ 137 | /* SG_ONE_MINUS_SRC_ALPHA */ 138 | /* SG_DST_ALPHA */ 139 | /* SG_ONE_MINUS_DST_ALPHA */ 140 | 141 | /* BlendEquationSeparate */ 142 | #define SG_FUNC_ADD 0x8006 143 | #define SG_BLEND_EQUATION 0x8009 144 | #define SG_BLEND_EQUATION_RGB 0x8009 /* same as BLEND_EQUATION */ 145 | #define SG_BLEND_EQUATION_ALPHA 0x883D 146 | 147 | /* BlendSubtract */ 148 | #define SG_FUNC_SUBTRACT 0x800A 149 | #define SG_FUNC_REVERSE_SUBTRACT 0x800B 150 | 151 | /* Separate Blend Functions */ 152 | #define SG_BLEND_DST_RGB 0x80C8 153 | #define SG_BLEND_SRC_RGB 0x80C9 154 | #define SG_BLEND_DST_ALPHA 0x80CA 155 | #define SG_BLEND_SRC_ALPHA 0x80CB 156 | #define SG_CONSTANT_COLOR 0x8001 157 | #define SG_ONE_MINUS_CONSTANT_COLOR 0x8002 158 | #define SG_CONSTANT_ALPHA 0x8003 159 | #define SG_ONE_MINUS_CONSTANT_ALPHA 0x8004 160 | #define SG_BLEND_COLOR 0x8005 161 | 162 | /* Buffer Objects */ 163 | #define SG_ARRAY_BUFFER 0x8892 164 | #define SG_ELEMENT_ARRAY_BUFFER 0x8893 165 | #define SG_ARRAY_BUFFER_BINDING 0x8894 166 | #define SG_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 167 | 168 | #define SG_STREAM_DRAW 0x88E0 169 | #define SG_STATIC_DRAW 0x88E4 170 | #define SG_DYNAMIC_DRAW 0x88E8 171 | 172 | #define SG_BUFFER_SIZE 0x8764 173 | #define SG_BUFFER_USAGE 0x8765 174 | 175 | #define SG_CURRENT_VERTEX_ATTRIB 0x8626 176 | 177 | /* CullFaceMode */ 178 | #define SG_FRONT 0x0404 179 | #define SG_BACK 0x0405 180 | #define SG_FRONT_AND_BACK 0x0408 181 | 182 | /* PolygonMode */ 183 | #define SG_POINT 0x1B00 184 | #define SG_LINE 0x1B01 185 | #define SG_FILL 0x1B02 186 | 187 | /* DepthFunction */ 188 | /* SG_NEVER */ 189 | /* SG_LESS */ 190 | /* SG_EQUAL */ 191 | /* SG_LEQUAL */ 192 | /* SG_GREATER */ 193 | /* SG_NOTEQUAL */ 194 | /* SG_GEQUAL */ 195 | /* SG_ALWAYS */ 196 | 197 | /* EnableCap */ 198 | #define SG_TEXTURE_2D 0x0DE1 199 | #define SG_CULL_FACE 0x0B44 200 | #define SG_BLEND 0x0BE2 201 | #define SG_DITHER 0x0BD0 202 | #define SG_STENCIL_TEST 0x0B90 203 | #define SG_DEPTH_TEST 0x0B71 204 | #define SG_SCISSOR_TEST 0x0C11 205 | #define SG_POLYGON_OFFSET_FILL 0x8037 206 | #define SG_SAMPLE_ALPHA_TO_COVERAGE 0x809E 207 | #define SG_SAMPLE_COVERAGE 0x80A0 208 | 209 | /* ErrorCode */ 210 | #define SG_NO_ERROR 0 211 | #define SG_INVALID_ENUM 0x0500 212 | #define SG_INVALID_VALUE 0x0501 213 | #define SG_INVALID_OPERATION 0x0502 214 | #define SG_OUT_OF_MEMORY 0x0505 215 | 216 | /* FrontFaceDirection */ 217 | #define SG_CW 0x0900 218 | #define SG_CCW 0x0901 219 | 220 | /* GetPName */ 221 | #define SG_LINE_WIDTH 0x0B21 222 | #define SG_ALIASED_POINT_SIZE_RANGE 0x846D 223 | #define SG_ALIASED_LINE_WIDTH_RANGE 0x846E 224 | #define SG_CULL_FACE_MODE 0x0B45 225 | #define SG_FRONT_FACE 0x0B46 226 | #define SG_DEPTH_RANGE 0x0B70 227 | #define SG_DEPTH_WRITEMASK 0x0B72 228 | #define SG_DEPTH_CLEAR_VALUE 0x0B73 229 | #define SG_DEPTH_FUNC 0x0B74 230 | #define SG_STENCIL_CLEAR_VALUE 0x0B91 231 | #define SG_STENCIL_FUNC 0x0B92 232 | #define SG_STENCIL_FAIL 0x0B94 233 | #define SG_STENCIL_PASS_DEPTH_FAIL 0x0B95 234 | #define SG_STENCIL_PASS_DEPTH_PASS 0x0B96 235 | #define SG_STENCIL_REF 0x0B97 236 | #define SG_STENCIL_VALUE_MASK 0x0B93 237 | #define SG_STENCIL_WRITEMASK 0x0B98 238 | #define SG_STENCIL_BACK_FUNC 0x8800 239 | #define SG_STENCIL_BACK_FAIL 0x8801 240 | #define SG_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 241 | #define SG_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 242 | #define SG_STENCIL_BACK_REF 0x8CA3 243 | #define SG_STENCIL_BACK_VALUE_MASK 0x8CA4 244 | #define SG_STENCIL_BACK_WRITEMASK 0x8CA5 245 | #define SG_VIEWPORT 0x0BA2 246 | #define SG_SCISSOR_BOX 0x0C10 247 | /* SG_SCISSOR_TEST */ 248 | #define SG_COLOR_CLEAR_VALUE 0x0C22 249 | #define SG_COLOR_WRITEMASK 0x0C23 250 | #define SG_UNPACK_ALIGNMENT 0x0CF5 251 | #define SG_PACK_ALIGNMENT 0x0D05 252 | #define SG_MAX_TEXTURE_SIZE 0x0D33 253 | #define SG_MAX_VIEWPORT_DIMS 0x0D3A 254 | #define SG_SUBPIXEL_BITS 0x0D50 255 | #define SG_RED_BITS 0x0D52 256 | #define SG_GREEN_BITS 0x0D53 257 | #define SG_BLUE_BITS 0x0D54 258 | #define SG_ALPHA_BITS 0x0D55 259 | #define SG_DEPTH_BITS 0x0D56 260 | #define SG_STENCIL_BITS 0x0D57 261 | #define SG_POLYGON_OFFSET_UNITS 0x2A00 262 | /* SG_POLYGON_OFFSET_FILL */ 263 | #define SG_POLYGON_OFFSET_FACTOR 0x8038 264 | #define SG_TEXTURE_BINDING_2D 0x8069 265 | #define SG_SAMPLE_BUFFERS 0x80A8 266 | #define SG_SAMPLES 0x80A9 267 | #define SG_SAMPLE_COVERAGE_VALUE 0x80AA 268 | #define SG_SAMPLE_COVERAGE_INVERT 0x80AB 269 | 270 | /* GetTextureParameter */ 271 | /* SG_TEXTURE_MAG_FILTER */ 272 | /* SG_TEXTURE_MIN_FILTER */ 273 | /* SG_TEXTURE_WRAP_S */ 274 | /* SG_TEXTURE_WRAP_T */ 275 | 276 | #define SG_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 277 | #define SG_COMPRESSED_TEXTURE_FORMATS 0x86A3 278 | 279 | /* HintMode */ 280 | #define SG_DONT_CARE 0x1100 281 | #define SG_FASTEST 0x1101 282 | #define SG_NICEST 0x1102 283 | 284 | /* HintTarget */ 285 | #define SG_GENERATE_MIPMAP_HINT 0x8192 286 | 287 | /* DataType */ 288 | #define SG_BYTE 0x1400 289 | #define SG_UNSIGNED_BYTE 0x1401 290 | #define SG_SHORT 0x1402 291 | #define SG_UNSIGNED_SHORT 0x1403 292 | #define SG_INT 0x1404 293 | #define SG_UNSIGNED_INT 0x1405 294 | #define SG_FLOAT 0x1406 295 | #define SG_FIXED 0x140C 296 | 297 | /* PixelFormat */ 298 | #define SG_DEPTH_COMPONENT 0x1902 299 | #define SG_ALPHA 0x1906 300 | #define SG_RGB 0x1907 301 | #define SG_BGRA 0x80E1 // will support extension! 302 | #define SG_RGBA 0x1908 303 | #define SG_LUMINANCE 0x1909 304 | #define SG_LUMINANCE_ALPHA 0x190A 305 | 306 | /* PixelType */ 307 | /* SG_UNSIGNED_BYTE */ 308 | #define SG_UNSIGNED_SHORT_4_4_4_4 0x8033 309 | #define SG_UNSIGNED_SHORT_5_5_5_1 0x8034 310 | #define SG_UNSIGNED_SHORT_5_6_5 0x8363 311 | 312 | /* Shaders */ 313 | #define SG_FRAGMENT_SHADER 0x8B30 314 | #define SG_VERTEX_SHADER 0x8B31 315 | #define SG_MAX_VERTEX_ATTRIBS 0x8869 316 | #define SG_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB 317 | #define SG_MAX_VARYING_VECTORS 0x8DFC 318 | #define SG_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D 319 | #define SG_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C 320 | #define SG_MAX_TEXTURE_IMAGE_UNITS 0x8872 321 | #define SG_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD 322 | #define SG_SHADER_TYPE 0x8B4F 323 | #define SG_DELETE_STATUS 0x8B80 324 | #define SG_LINK_STATUS 0x8B82 325 | #define SG_VALIDATE_STATUS 0x8B83 326 | #define SG_ATTACHED_SHADERS 0x8B85 327 | #define SG_ACTIVE_UNIFORMS 0x8B86 328 | #define SG_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 329 | #define SG_ACTIVE_ATTRIBUTES 0x8B89 330 | #define SG_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A 331 | #define SG_SHADING_LANGUAGE_VERSION 0x8B8C 332 | #define SG_CURRENT_PROGRAM 0x8B8D 333 | 334 | /* StencilFunction */ 335 | #define SG_NEVER 0x0200 336 | #define SG_LESS 0x0201 337 | #define SG_EQUAL 0x0202 338 | #define SG_LEQUAL 0x0203 339 | #define SG_GREATER 0x0204 340 | #define SG_NOTEQUAL 0x0205 341 | #define SG_GEQUAL 0x0206 342 | #define SG_ALWAYS 0x0207 343 | 344 | /* StencilOp */ 345 | /* SG_ZERO */ 346 | #define SG_KEEP 0x1E00 347 | #define SG_REPLACE 0x1E01 348 | #define SG_INCR 0x1E02 349 | #define SG_DECR 0x1E03 350 | #define SG_INVERT 0x150A 351 | #define SG_INCR_WRAP 0x8507 352 | #define SG_DECR_WRAP 0x8508 353 | 354 | /* StringName */ 355 | #define SG_VENDOR 0x1F00 356 | #define SG_RENDERER 0x1F01 357 | #define SG_VERSION 0x1F02 358 | #define SG_EXTENSIONS 0x1F03 359 | 360 | /* TextureMagFilter */ 361 | #define SG_NEAREST 0x2600 362 | #define SG_LINEAR 0x2601 363 | 364 | /* TextureMinFilter */ 365 | /* SG_NEAREST */ 366 | /* SG_LINEAR */ 367 | #define SG_NEAREST_MIPMAP_NEAREST 0x2700 368 | #define SG_LINEAR_MIPMAP_NEAREST 0x2701 369 | #define SG_NEAREST_MIPMAP_LINEAR 0x2702 370 | #define SG_LINEAR_MIPMAP_LINEAR 0x2703 371 | 372 | /* TextureParameterName */ 373 | #define SG_TEXTURE_MAG_FILTER 0x2800 374 | #define SG_TEXTURE_MIN_FILTER 0x2801 375 | #define SG_TEXTURE_WRAP_S 0x2802 376 | #define SG_TEXTURE_WRAP_T 0x2803 377 | 378 | /* TextureTarget */ 379 | /* SG_TEXTURE_2D */ 380 | #define SG_TEXTURE 0x1702 381 | 382 | #define SG_TEXTURE_CUBE_MAP 0x8513 383 | #define SG_TEXTURE_BINDING_CUBE_MAP 0x8514 384 | #define SG_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 385 | #define SG_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 386 | #define SG_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 387 | #define SG_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 388 | #define SG_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 389 | #define SG_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A 390 | #define SG_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C 391 | 392 | /* TextureUnit */ 393 | #define SG_TEXTURE0 0x84C0 394 | #define SG_TEXTURE1 0x84C1 395 | #define SG_TEXTURE2 0x84C2 396 | #define SG_TEXTURE3 0x84C3 397 | #define SG_TEXTURE4 0x84C4 398 | #define SG_TEXTURE5 0x84C5 399 | #define SG_TEXTURE6 0x84C6 400 | #define SG_TEXTURE7 0x84C7 401 | #define SG_TEXTURE8 0x84C8 402 | #define SG_TEXTURE9 0x84C9 403 | #define SG_TEXTURE10 0x84CA 404 | #define SG_TEXTURE11 0x84CB 405 | #define SG_TEXTURE12 0x84CC 406 | #define SG_TEXTURE13 0x84CD 407 | #define SG_TEXTURE14 0x84CE 408 | #define SG_TEXTURE15 0x84CF 409 | #define SG_TEXTURE16 0x84D0 410 | #define SG_TEXTURE17 0x84D1 411 | #define SG_TEXTURE18 0x84D2 412 | #define SG_TEXTURE19 0x84D3 413 | #define SG_TEXTURE20 0x84D4 414 | #define SG_TEXTURE21 0x84D5 415 | #define SG_TEXTURE22 0x84D6 416 | #define SG_TEXTURE23 0x84D7 417 | #define SG_TEXTURE24 0x84D8 418 | #define SG_TEXTURE25 0x84D9 419 | #define SG_TEXTURE26 0x84DA 420 | #define SG_TEXTURE27 0x84DB 421 | #define SG_TEXTURE28 0x84DC 422 | #define SG_TEXTURE29 0x84DD 423 | #define SG_TEXTURE30 0x84DE 424 | #define SG_TEXTURE31 0x84DF 425 | #define SG_ACTIVE_TEXTURE 0x84E0 426 | 427 | /* TextureWrapMode */ 428 | #define SG_REPEAT 0x2901 429 | #define SG_CLAMP_TO_EDGE 0x812F 430 | #define SG_MIRRORED_REPEAT 0x8370 431 | 432 | /* Uniform Types */ 433 | #define SG_FLOAT_VEC2 0x8B50 434 | #define SG_FLOAT_VEC3 0x8B51 435 | #define SG_FLOAT_VEC4 0x8B52 436 | #define SG_INT_VEC2 0x8B53 437 | #define SG_INT_VEC3 0x8B54 438 | #define SG_INT_VEC4 0x8B55 439 | #define SG_BOOL 0x8B56 440 | #define SG_BOOL_VEC2 0x8B57 441 | #define SG_BOOL_VEC3 0x8B58 442 | #define SG_BOOL_VEC4 0x8B59 443 | #define SG_FLOAT_MAT2 0x8B5A 444 | #define SG_FLOAT_MAT3 0x8B5B 445 | #define SG_FLOAT_MAT4 0x8B5C 446 | #define SG_SAMPLER_2D 0x8B5E 447 | #define SG_SAMPLER_CUBE 0x8B60 448 | 449 | /* Vertex Arrays */ 450 | #define SG_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 451 | #define SG_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 452 | #define SG_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 453 | #define SG_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 454 | #define SG_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A 455 | #define SG_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 456 | #define SG_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F 457 | 458 | /* Read Format */ 459 | #define SG_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A 460 | #define SG_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B 461 | 462 | /* Shader Source */ 463 | #define SG_COMPILE_STATUS 0x8B81 464 | #define SG_INFO_LOG_LENGTH 0x8B84 465 | #define SG_SHADER_SOURCE_LENGTH 0x8B88 466 | #define SG_SHADER_COMPILER 0x8DFA 467 | 468 | /* Shader Binary */ 469 | #define SG_SHADER_BINARY_FORMATS 0x8DF8 470 | #define SG_NUM_SHADER_BINARY_FORMATS 0x8DF9 471 | 472 | /* Shader Precision-Specified Types */ 473 | #define SG_LOW_FLOAT 0x8DF0 474 | #define SG_MEDIUM_FLOAT 0x8DF1 475 | #define SG_HIGH_FLOAT 0x8DF2 476 | #define SG_LOW_INT 0x8DF3 477 | #define SG_MEDIUM_INT 0x8DF4 478 | #define SG_HIGH_INT 0x8DF5 479 | 480 | /* Framebuffer Object. */ 481 | #define SG_FRAMEBUFFER 0x8D40 482 | #define SG_RENDERBUFFER 0x8D41 483 | 484 | #define SG_RGBA4 0x8056 485 | #define SG_RGB5_A1 0x8057 486 | #define SG_RGB565 0x8D62 487 | #define SG_DEPTH_COMPONENT16 0x81A5 488 | #define SG_STENCIL_INDEX 0x1901 489 | #define SG_STENCIL_INDEX8 0x8D48 490 | 491 | #define SG_RENDERBUFFER_WIDTH 0x8D42 492 | #define SG_RENDERBUFFER_HEIGHT 0x8D43 493 | #define SG_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 494 | #define SG_RENDERBUFFER_RED_SIZE 0x8D50 495 | #define SG_RENDERBUFFER_GREEN_SIZE 0x8D51 496 | #define SG_RENDERBUFFER_BLUE_SIZE 0x8D52 497 | #define SG_RENDERBUFFER_ALPHA_SIZE 0x8D53 498 | #define SG_RENDERBUFFER_DEPTH_SIZE 0x8D54 499 | #define SG_RENDERBUFFER_STENCIL_SIZE 0x8D55 500 | 501 | #define SG_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 502 | #define SG_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 503 | #define SG_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 504 | #define SG_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 505 | 506 | #define SG_COLOR_ATTACHMENT0 0x8CE0 507 | #define SG_DEPTH_ATTACHMENT 0x8D00 508 | #define SG_STENCIL_ATTACHMENT 0x8D20 509 | 510 | #define SG_NONE 0 511 | 512 | #define SG_FRAMEBUFFER_COMPLETE 0x8CD5 513 | #define SG_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 514 | #define SG_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 515 | #define SG_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9 516 | #define SG_FRAMEBUFFER_UNSUPPORTED 0x8CDD 517 | 518 | #define SG_FRAMEBUFFER_BINDING 0x8CA6 519 | #define SG_RENDERBUFFER_BINDING 0x8CA7 520 | #define SG_MAX_RENDERBUFFER_SIZE 0x84E8 521 | 522 | #define SG_INVALID_FRAMEBUFFER_OPERATION 0x0506 523 | 524 | 525 | #include "SimpleGraphics_impl.h" 526 | 527 | #endif // INCLUDE_SIMPLEGRAPHICS_H 528 | -------------------------------------------------------------------------------- /UI/SimpleGraphics_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SimpleGraphics_impl.h 3 | * 4 | * Created by kioku on 11/07/06. 5 | * 6 | */ 7 | 8 | // !!! This is included by SimpleGraphics.h !!! 9 | #ifndef INCLUDE_SIMPLEGRAPHICS_H 10 | #error "You must include from SimpleGraphics.h. Do not include this file." 11 | #else 12 | 13 | #if defined(__EMSCRIPTEN__) 14 | #include 15 | #include 16 | 17 | namespace { 18 | void InitGLExtension(){} 19 | } 20 | #elif defined(_WIN32) 21 | #include 22 | #include 23 | #include "WGLExtension.h" 24 | #elif defined(__APPLE__) 25 | #include 26 | #include 27 | #include 28 | namespace { 29 | void InitGLExtension(){} 30 | } 31 | #else // Linux 32 | #define GL_GLEXT_PROTOTYPES 33 | #include 34 | #include 35 | #include 36 | namespace { 37 | void InitGLExtension(){} 38 | } 39 | #endif 40 | 41 | #include 42 | 43 | //#define GL_DEBUG 44 | 45 | #ifdef GL_DEBUG 46 | #define GLDEBUG GL_debug_func(this, __LINE__) 47 | #include 48 | #include 49 | #else 50 | 51 | #define GLDEBUG 52 | 53 | #endif 54 | 55 | namespace skGUI { 56 | #ifdef GL_DEBUG 57 | inline void GL_debug_func(SimpleGraphics* g, int line) 58 | { 59 | SGenum e = g->GetError(); 60 | if(e) { 61 | printf("GL ERROR(0x%X):Line(%d) - %s\n", e, line, gluErrorString(e)); 62 | assert(0); 63 | } 64 | } 65 | #endif 66 | 67 | inline SimpleGraphics::SimpleGraphics() 68 | { 69 | InitGLExtension(); 70 | } 71 | 72 | inline SimpleGraphics::~SimpleGraphics() 73 | { 74 | } 75 | 76 | 77 | 78 | inline void SimpleGraphics::AttachShader (unsigned int program, unsigned int shader){ glAttachShader(program, shader); GLDEBUG; } 79 | inline void SimpleGraphics::BindAttribLocation (unsigned int program, unsigned int index, const char* name){ glBindAttribLocation(program, index, name); GLDEBUG; } 80 | inline void SimpleGraphics::BindBuffer (SGenum target, unsigned int buffer){ glBindBuffer(target, buffer); GLDEBUG;} 81 | inline void SimpleGraphics::BindTexture (SGenum target, unsigned int texture){ glBindTexture(target, texture); GLDEBUG;} 82 | inline void SimpleGraphics::BlendFunc (SGenum sfactor, SGenum dfactor){ glBlendFunc(sfactor, dfactor); GLDEBUG; } 83 | inline void SimpleGraphics::BufferData (SGenum target, int size, const void* data, SGenum usage){ glBufferData(target, size, data, usage); GLDEBUG;} 84 | inline void SimpleGraphics::BufferSubData (SGenum target, int offset, int size, const void* data){ glBufferSubData(target, offset, size, data); GLDEBUG;} 85 | inline void SimpleGraphics::Clear (unsigned int mask){ glClear(mask); GLDEBUG; } 86 | inline void SimpleGraphics::ClearColor (float red, float green, float blue, float alpha){ glClearColor(red, green, blue, alpha); GLDEBUG; } 87 | inline void SimpleGraphics::CompileShader (unsigned int shader){ glCompileShader(shader); GLDEBUG; } 88 | inline unsigned int SimpleGraphics::CreateProgram (void){ return glCreateProgram(); GLDEBUG;} 89 | inline unsigned int SimpleGraphics::CreateShader (SGenum type){ return glCreateShader(type); GLDEBUG; } 90 | inline void SimpleGraphics::CullFace (SGenum mode){ glCullFace(mode); GLDEBUG; } 91 | inline void SimpleGraphics::DeleteBuffers (int n, const unsigned int* buffers){ glDeleteBuffers(n, buffers); GLDEBUG; } 92 | inline void SimpleGraphics::DeleteProgram (unsigned int program){ glDeleteProgram(program); GLDEBUG; } 93 | inline void SimpleGraphics::DeleteShader (unsigned int shader){ glDeleteShader(shader); GLDEBUG; } 94 | inline void SimpleGraphics::DeleteTextures (int n, const unsigned int* textures){ glDeleteTextures(n, textures); GLDEBUG; } 95 | //inline void SimpleGraphics::DetachShader (unsigned int program, unsigned int shader){ glDetachShader(program, shader); GLDEBUG; } 96 | inline void SimpleGraphics::Disable (SGenum cap){ glDisable(cap); GLDEBUG; } 97 | inline void SimpleGraphics::DisableVertexAttribArray (unsigned int index){ glDisableVertexAttribArray(index); GLDEBUG; } 98 | inline void SimpleGraphics::DrawArrays (SGenum mode, int first, int count){ glDrawArrays(mode, first, count); GLDEBUG; } 99 | inline void SimpleGraphics::DrawElements (SGenum mode, int count, SGenum type, const void* indices){ glDrawElements(mode, count, type, indices); GLDEBUG; } 100 | inline void SimpleGraphics::Enable (SGenum cap){ glEnable(cap); GLDEBUG; } 101 | inline void SimpleGraphics::EnableVertexAttribArray (unsigned int index){ glEnableVertexAttribArray(index); GLDEBUG; } 102 | inline void SimpleGraphics::GenBuffers (int n, unsigned int* buffers){ glGenBuffers(n, buffers); GLDEBUG; } 103 | inline void SimpleGraphics::GenTextures (int n, unsigned int* textures){ glGenTextures(n, textures); GLDEBUG; } 104 | inline int SimpleGraphics::GetAttribLocation (unsigned int program, const char* name){ return glGetAttribLocation(program, name); GLDEBUG; } 105 | inline SGenum SimpleGraphics::GetError (void){ return glGetError(); } 106 | inline void SimpleGraphics::GetFloatv (SGenum pname, float* params){ glGetFloatv(pname, params); GLDEBUG; } 107 | inline void SimpleGraphics::GetIntegerv (SGenum pname, int* params){ glGetIntegerv(pname, params); GLDEBUG; } 108 | inline void SimpleGraphics::GetProgramiv (unsigned int program, SGenum pname, int* params){ glGetProgramiv(program, pname, params); GLDEBUG; } 109 | inline void SimpleGraphics::GetProgramInfoLog (unsigned int program, int bufsize, int* length, char* infolog){ glGetProgramInfoLog(program, bufsize, length, infolog); GLDEBUG; } 110 | inline void SimpleGraphics::GetShaderiv (unsigned int shader, SGenum pname, int* params){ glGetShaderiv(shader, pname, params); GLDEBUG; } 111 | inline void SimpleGraphics::GetShaderInfoLog (unsigned int shader, int bufsize, int* length, char* infolog){ glGetShaderInfoLog(shader, bufsize, length, infolog); GLDEBUG; } 112 | inline int SimpleGraphics::GetUniformLocation (unsigned int program, const char* name){ return glGetUniformLocation(program, name); GLDEBUG; } 113 | inline void SimpleGraphics::LinkProgram (unsigned int program){ glLinkProgram(program); GLDEBUG; } 114 | inline void SimpleGraphics::ShaderSource (unsigned int shader, int count, const char** string, const int* length){ glShaderSource(shader, count, string, length); GLDEBUG; } 115 | inline void SimpleGraphics::TexImage2D (SGenum target, int level, int internalformat, int width, int height, int border, SGenum format, SGenum type, const void* pixels){ glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels); GLDEBUG; } 116 | inline void SimpleGraphics::TexParameterf (SGenum target, SGenum pname, float param){ glTexParameterf(target, pname, param); GLDEBUG; } 117 | inline void SimpleGraphics::TexParameterfv (SGenum target, SGenum pname, const float* params){ glTexParameterfv(target, pname, params); GLDEBUG; } 118 | inline void SimpleGraphics::TexParameteri (SGenum target, SGenum pname, int param){ glTexParameteri(target, pname, param); GLDEBUG; } 119 | inline void SimpleGraphics::TexParameteriv (SGenum target, SGenum pname, const int* params){ glTexParameteriv(target, pname, params); GLDEBUG; } 120 | inline void SimpleGraphics::TexSubImage2D (SGenum target, int level, int xoffset, int yoffset, int width, int height, SGenum format, SGenum type, const void* pixels){ glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); GLDEBUG; } 121 | inline void SimpleGraphics::Uniform1f (int location, float x){ glUniform1f(location, x); GLDEBUG; } 122 | inline void SimpleGraphics::Uniform1fv (int location, int count, const float* v){ glUniform1fv(location, count, v); GLDEBUG; } 123 | inline void SimpleGraphics::Uniform1i (int location, int x){ glUniform1i(location, x); GLDEBUG; } 124 | inline void SimpleGraphics::Uniform1iv (int location, int count, const int* v){ glUniform1iv(location, count, v); GLDEBUG; } 125 | inline void SimpleGraphics::Uniform2f (int location, float x, float y){ glUniform2f(location, x, y); GLDEBUG; } 126 | inline void SimpleGraphics::Uniform2fv (int location, int count, const float* v){ glUniform2fv(location, count, v); GLDEBUG; } 127 | inline void SimpleGraphics::Uniform2i (int location, int x, int y){ glUniform2i(location, x, y); GLDEBUG; } 128 | inline void SimpleGraphics::Uniform2iv (int location, int count, const int* v){ glUniform2iv(location, count, v); GLDEBUG; } 129 | inline void SimpleGraphics::Uniform3f (int location, float x, float y, float z){ glUniform3f(location, x, y, z); GLDEBUG; } 130 | inline void SimpleGraphics::Uniform3fv (int location, int count, const float* v){ glUniform3fv(location, count, v); GLDEBUG; } 131 | inline void SimpleGraphics::Uniform3i (int location, int x, int y, int z){ glUniform3i(location, x, y, z); GLDEBUG; } 132 | inline void SimpleGraphics::Uniform3iv (int location, int count, const int* v){ glUniform3iv(location, count, v); GLDEBUG; } 133 | inline void SimpleGraphics::Uniform4f (int location, float x, float y, float z, float w){ glUniform4f(location, x, y, z, w); GLDEBUG; } 134 | inline void SimpleGraphics::Uniform4fv (int location, int count, const float* v){ glUniform4fv(location, count, v); GLDEBUG; } 135 | inline void SimpleGraphics::Uniform4i (int location, int x, int y, int z, int w){ glUniform4i(location, x, y, z, w); GLDEBUG; } 136 | inline void SimpleGraphics::Uniform4iv (int location, int count, const int* v){ glUniform4iv(location, count, v); GLDEBUG; } 137 | inline void SimpleGraphics::UniformMatrix2fv (int location, int count, unsigned char transpose, const float* value){ glUniformMatrix2fv(location, count, transpose, value); GLDEBUG; } 138 | inline void SimpleGraphics::UniformMatrix3fv (int location, int count, unsigned char transpose, const float* value){ glUniformMatrix3fv(location, count, transpose, value); GLDEBUG; } 139 | inline void SimpleGraphics::UniformMatrix4fv (int location, int count, unsigned char transpose, const float* value){ glUniformMatrix4fv(location, count, transpose, value); GLDEBUG; } 140 | inline void SimpleGraphics::UseProgram (unsigned int program){ glUseProgram(program); GLDEBUG; } 141 | inline void SimpleGraphics::ValidateProgram (unsigned int program){ glValidateProgram(program); GLDEBUG; } 142 | inline void SimpleGraphics::VertexAttribPointer (unsigned int indx, int size, SGenum type, unsigned char normalized, int stride, const void* ptr){ glVertexAttribPointer(indx, size, type, normalized, stride, ptr); GLDEBUG; } 143 | inline void SimpleGraphics::Viewport (int x, int y, int width, int height){ glViewport(x, y, width, height); GLDEBUG; } 144 | 145 | } // namespace Simple 146 | #endif 147 | 148 | -------------------------------------------------------------------------------- /UI/SimpleShader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SimpleShader.h 3 | * 4 | * Created by kioku on 2012/08/20. 5 | * 6 | */ 7 | 8 | #ifndef INCLUDE_SIMPLESHADER_H 9 | #define INCLUDE_SIMPLESHADER_H 10 | 11 | #include "SimpleGraphics.h" 12 | #include 13 | #include 14 | 15 | namespace skGUI { 16 | 17 | class SimpleShader 18 | { 19 | public: 20 | SimpleShader(SimpleGraphics* sg, const char* vsshader, const char* fsshader) 21 | { 22 | g = sg; 23 | m_program = 0; 24 | m_oldProgram = 0; 25 | m_binding = false; 26 | const int vshader = createShader(vsshader, SG_VERTEX_SHADER); 27 | const int fshader = createShader(fsshader, SG_FRAGMENT_SHADER); 28 | link(vshader, fshader); 29 | g->DeleteShader(vshader); 30 | g->DeleteShader(fshader); 31 | } 32 | ~SimpleShader() 33 | { 34 | g->DeleteProgram(m_program); 35 | } 36 | 37 | void Bind() 38 | { 39 | g->GetIntegerv(SG_CURRENT_PROGRAM, reinterpret_cast(&m_oldProgram)); 40 | g->UseProgram(m_program); 41 | m_binding = true; 42 | } 43 | void Unbind() 44 | { 45 | g->UseProgram(m_oldProgram); 46 | m_binding = false; 47 | } 48 | void SetUniform(const char* name, const int i0) 49 | { 50 | if (m_program && m_binding) 51 | g->Uniform1i(g->GetUniformLocation(m_program, name), i0); 52 | } 53 | 54 | void SetUniform(const char* name, const float f0) 55 | { 56 | if (m_program && m_binding) 57 | g->Uniform1f(g->GetUniformLocation(m_program, name), f0); 58 | } 59 | void SetUniform(const char* name, const float f0, const float f1, const float f2, const float f3) 60 | { 61 | if (m_program && m_binding) 62 | g->Uniform4f(g->GetUniformLocation(m_program, name), f0, f1, f2, f3); 63 | } 64 | 65 | void SetUniformMatrix4x4(const char* name, const int count, const bool transpose, const float* val) 66 | { 67 | if (m_program && m_binding) 68 | g->UniformMatrix4fv(g->GetUniformLocation(m_program, name), count, transpose, val); 69 | } 70 | 71 | void BindAttribLocation(unsigned int index, const char* name) 72 | { 73 | if (m_program && m_binding) 74 | g->BindAttribLocation(m_program, index, name); 75 | } 76 | 77 | unsigned int GetAttribLocation(const char* name) 78 | { 79 | if (m_program && m_binding) 80 | return g->GetAttribLocation(m_program, name); 81 | else 82 | return -1; 83 | } 84 | 85 | 86 | private: 87 | void printShaderInfoLog(SimpleGraphics* g, int shader) const 88 | { 89 | int bufSize = 0; 90 | g->GetShaderiv(shader, SG_INFO_LOG_LENGTH , &bufSize); 91 | if (bufSize > 1) { 92 | char *infoLog; 93 | infoLog = new char[bufSize]; 94 | if (infoLog != NULL) { 95 | int length; 96 | g->GetShaderInfoLog(shader, bufSize, &length, infoLog); 97 | printf("InfoLog:\n%s\n",infoLog); 98 | delete [] infoLog; 99 | } else { 100 | printf("Could not allocate InfoLog buffer."); 101 | } 102 | } 103 | } 104 | 105 | void printProgramInfoLog(SimpleGraphics* g, GLuint program) const 106 | { 107 | int bufSize; 108 | g->GetProgramiv(program, SG_INFO_LOG_LENGTH , &bufSize); 109 | if (bufSize > 1) { 110 | char *infoLog; 111 | infoLog = new char[bufSize]; 112 | if (infoLog != NULL) { 113 | int length; 114 | g->GetProgramInfoLog(program, bufSize, &length, infoLog); 115 | printf("InfoLog:\n%s\n",infoLog); 116 | delete [] infoLog; 117 | } else { 118 | printf("Could not allocate InfoLog buffer."); 119 | } 120 | } 121 | } 122 | 123 | int createShader(const char* programSource, SGenum shaderType) const 124 | { 125 | const char* s = programSource; 126 | const int l = static_cast(strlen(programSource)); 127 | 128 | int shader = g->CreateShader(shaderType); 129 | g->ShaderSource( shader, 1, &s, &l ); 130 | if ( g->GetError() != SG_NO_ERROR ) { 131 | printf("cannot set shader source: %s", s); 132 | return -1; 133 | } 134 | 135 | // compile 136 | int compiled = 0; 137 | g->CompileShader(shader); 138 | g->GetShaderiv(shader, SG_COMPILE_STATUS, &compiled); 139 | printShaderInfoLog(g, shader); 140 | if (!compiled) 141 | { 142 | printf("Compile is failed"); 143 | return -1; 144 | } 145 | 146 | return shader; 147 | } 148 | 149 | bool link(const int vertexShader, const int fragmentShader) 150 | { 151 | if (!m_program) { 152 | unsigned int program = g->CreateProgram(); 153 | g->AttachShader(program, vertexShader); 154 | g->AttachShader(program, fragmentShader); 155 | m_program = program; 156 | } 157 | 158 | g->LinkProgram(m_program); 159 | GLint linked; 160 | g->GetProgramiv(m_program, SG_LINK_STATUS, &linked); 161 | printProgramInfoLog(g, m_program); 162 | if (linked == SG_FALSE) { 163 | printf("Link error."); 164 | return false; 165 | } 166 | return true; 167 | } 168 | 169 | unsigned int m_program, m_oldProgram; 170 | bool m_binding; 171 | SimpleGraphics* g; 172 | }; 173 | 174 | } // namespace skGUI 175 | 176 | #endif // INCLUDE_SIMPLESHADER_H 177 | 178 | -------------------------------------------------------------------------------- /UI/SimpleTex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SimpleTex.h 3 | * 4 | * Created by kioku on 2012/08/20. 5 | * 6 | */ 7 | 8 | #ifndef INCLUDE_SIMPLETEX_H 9 | #define INCLUDE_SIMPLETEX_H 10 | 11 | namespace skGUI { 12 | 13 | class SimpleTex 14 | { 15 | public: 16 | enum COLORTYPE { 17 | COLOR_RGBA8888, 18 | COLOR_R8 19 | }; 20 | 21 | SimpleTex(SimpleGraphics* sg, int w, int h, COLORTYPE col = COLOR_RGBA8888) 22 | { 23 | g = sg; 24 | m_tex = -1; 25 | m_width = w; 26 | m_height = h; 27 | m_color = col; 28 | const int colsize = (col == COLOR_RGBA8888 ? 4 : 1); 29 | m_buffer = new unsigned char[colsize * w * h]; 30 | } 31 | ~SimpleTex() 32 | { 33 | delete [] m_buffer; 34 | g->DeleteTextures(1, &m_tex); 35 | } 36 | int GetWidth () const { return m_width; } 37 | int GetHeight() const { return m_height; } 38 | COLORTYPE GetColorType() const { return m_color; } 39 | void Resize(int w, int h) 40 | { 41 | delete [] m_buffer; 42 | const int colsize = (m_color == COLOR_RGBA8888 ? 4 : 1); 43 | m_buffer = new unsigned char[colsize * w * h]; 44 | m_width = w; 45 | m_height = h; 46 | } 47 | unsigned char* Map() 48 | { 49 | return m_buffer; 50 | } 51 | void Unmap() 52 | { 53 | if (m_tex == -1){ 54 | g->GenTextures(1, &m_tex); 55 | g->BindTexture(SG_TEXTURE_2D, m_tex); 56 | g->TexParameteri(SG_TEXTURE_2D, SG_TEXTURE_MIN_FILTER, SG_LINEAR); 57 | g->TexParameteri(SG_TEXTURE_2D, SG_TEXTURE_MAG_FILTER, SG_LINEAR); 58 | g->TexParameteri(SG_TEXTURE_2D, SG_TEXTURE_WRAP_S, SG_CLAMP_TO_EDGE); 59 | g->TexParameteri(SG_TEXTURE_2D, SG_TEXTURE_WRAP_T, SG_CLAMP_TO_EDGE); 60 | } 61 | // Update 62 | g->BindTexture(SG_TEXTURE_2D, m_tex); 63 | if (m_color == COLOR_RGBA8888) 64 | g->TexImage2D(SG_TEXTURE_2D, 0, SG_RGBA, m_width, m_height, 0, SG_RGBA, SG_UNSIGNED_BYTE, m_buffer); 65 | else 66 | g->TexImage2D(SG_TEXTURE_2D, 0, SG_LUMINANCE, m_width, m_height, 0, SG_LUMINANCE, SG_UNSIGNED_BYTE, m_buffer); 67 | } 68 | unsigned int GetID() 69 | { 70 | return m_tex; 71 | } 72 | private: 73 | COLORTYPE m_color; 74 | 75 | SimpleGraphics* g; 76 | unsigned int m_tex; 77 | int m_width; 78 | int m_height; 79 | unsigned char* m_buffer; 80 | }; 81 | 82 | } // namespace skGUI 83 | 84 | #endif // INCLUDE_SIMPLETEX_H 85 | 86 | -------------------------------------------------------------------------------- /UI/SimpleVB.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SimpleVB.h 3 | * 4 | * Created by kioku on 2012/08/20. 5 | * 6 | */ 7 | 8 | #ifndef INCLUDE_SIMPLEVB_H 9 | #define INCLUDE_SIMPLEVB_H 10 | 11 | #include 12 | 13 | namespace skGUI { 14 | 15 | class SimpleVB 16 | { 17 | public: 18 | SimpleVB(SimpleGraphics* sg, SimpleShader* shader) 19 | { 20 | g = sg; 21 | m_color = 0xFFFFFFFF; 22 | m_uv[0] = 0.0f; 23 | m_uv[1] = 0.0f; 24 | g->GenBuffers(1, &m_vb); 25 | g->GenBuffers(1, &m_ib); 26 | shader->Bind(); 27 | m_att_pos = shader->GetAttribLocation("pos"); 28 | m_att_col = shader->GetAttribLocation("col"); 29 | m_att_uv = shader->GetAttribLocation("uv"); 30 | m_shader = shader; 31 | m_shader->Unbind(); 32 | } 33 | ~SimpleVB() 34 | { 35 | g->DeleteBuffers(1, &m_vb); 36 | g->DeleteBuffers(1, &m_ib); 37 | } 38 | 39 | class VertexFormat 40 | { 41 | public: 42 | VertexFormat(float x_, float y_, float z_, unsigned int color, float uv[2]) 43 | { 44 | x = x_; y = y_; z = z_; 45 | col = color; 46 | u = uv[0]; v = uv[1]; 47 | } 48 | float x,y,z; 49 | unsigned int col; 50 | float u,v; 51 | }; 52 | 53 | void BeginTriangle(){ 54 | 55 | } 56 | void End() 57 | { 58 | 59 | } 60 | void Vertex3f(float x, float y, float z) 61 | { 62 | m_buffer.push_back(VertexFormat(x,y,z, m_color, m_uv)); 63 | } 64 | 65 | void Color4f(float r, float g, float b, float a) 66 | { 67 | unsigned int rc = static_cast(r * 255.0); 68 | unsigned int gc = static_cast(g * 255.0); 69 | unsigned int bc = static_cast(b * 255.0); 70 | unsigned int ac = static_cast(a * 255.0); 71 | if (rc > 255) rc = 255; 72 | if (gc > 255) gc = 255; 73 | if (bc > 255) bc = 255; 74 | if (ac > 255) ac = 255; 75 | m_color = (ac << 24) | (bc << 16) | (gc << 8) | rc; 76 | } 77 | void Texcoord2f(float u, float v) 78 | { 79 | m_uv[0] = u; 80 | m_uv[1] = v; 81 | } 82 | 83 | void Rect2f(float sx, float sy, float ex, float ey, float z) 84 | { 85 | BeginTriangle(); 86 | const size_t baseIndex = m_buffer.size(); 87 | Vertex3f(sx,sy,z); 88 | Vertex3f(ex,sy,z); 89 | Vertex3f(sx,ey,z); 90 | Vertex3f(ex,ey,z); 91 | m_indexbuffer.push_back(baseIndex ); 92 | m_indexbuffer.push_back(baseIndex+1); 93 | m_indexbuffer.push_back(baseIndex+2); 94 | m_indexbuffer.push_back(baseIndex+2); 95 | m_indexbuffer.push_back(baseIndex+1); 96 | m_indexbuffer.push_back(baseIndex+3); 97 | End(); 98 | } 99 | 100 | void RectUV2f(float sx, float sy, float ex, float ey, float z, float su, float sv, float eu, float ev) 101 | { 102 | BeginTriangle(); 103 | const size_t baseIndex = m_buffer.size(); 104 | Texcoord2f(su, sv); Vertex3f(sx,sy,z); 105 | Texcoord2f(eu, sv); Vertex3f(ex,sy,z); 106 | Texcoord2f(su, ev); Vertex3f(sx,ey,z); 107 | Texcoord2f(eu, ev); Vertex3f(ex,ey,z); 108 | m_indexbuffer.push_back(baseIndex ); 109 | m_indexbuffer.push_back(baseIndex+1); 110 | m_indexbuffer.push_back(baseIndex+2); 111 | m_indexbuffer.push_back(baseIndex+2); 112 | m_indexbuffer.push_back(baseIndex+1); 113 | m_indexbuffer.push_back(baseIndex+3); 114 | End(); 115 | } 116 | 117 | void RectUV9Grid(float sx, float sy, float ex, float ey, float z, float dxy, float su, float sv, float eu, float ev, float du, float dv) 118 | { 119 | BeginTriangle(); 120 | const size_t baseIndex = m_buffer.size(); 121 | Texcoord2f(su , sv ); 122 | Vertex3f (sx , sy , z); 123 | Texcoord2f(su+du , sv ); 124 | Vertex3f (sx+dxy, sy , z); 125 | Texcoord2f(eu-du , sv ); 126 | Vertex3f (ex-dxy, sy , z); 127 | Texcoord2f(eu , sv ); 128 | Vertex3f (ex , sy , z); 129 | 130 | Texcoord2f(su , sv+dv ); 131 | Vertex3f (sx , sy+dxy, z); 132 | Texcoord2f(su+du , sv+dv ); 133 | Vertex3f (sx+dxy, sy+dxy, z); 134 | Texcoord2f(eu-du , sv+dv ); 135 | Vertex3f (ex-dxy, sy+dxy, z); 136 | Texcoord2f(eu , sv+dv ); 137 | Vertex3f (ex , sy+dxy, z); 138 | 139 | Texcoord2f(su , ev-dv ); 140 | Vertex3f (sx , ey-dxy, z); 141 | Texcoord2f(su+du , ev-dv ); 142 | Vertex3f (sx+dxy, ey-dxy, z); 143 | Texcoord2f(eu-du , ev-dv ); 144 | Vertex3f (ex-dxy, ey-dxy, z); 145 | Texcoord2f(eu , ev-dv ); 146 | Vertex3f (ex , ey-dxy, z); 147 | 148 | Texcoord2f(su , ev ); 149 | Vertex3f (sx , ey , z); 150 | Texcoord2f(su+du , ev ); 151 | Vertex3f (sx+dxy, ey , z); 152 | Texcoord2f(eu-du , ev ); 153 | Vertex3f (ex-dxy, ey , z); 154 | Texcoord2f(eu , ev ); 155 | Vertex3f (ex , ey , z); 156 | 157 | for (size_t y = 0; y < 3; ++y) { 158 | for (size_t x = 0; x < 3; ++x) { 159 | m_indexbuffer.push_back(baseIndex +x + 4*y); 160 | m_indexbuffer.push_back(baseIndex+1+x + 4*y); 161 | m_indexbuffer.push_back(baseIndex+4+x + 4*y); 162 | m_indexbuffer.push_back(baseIndex+4+x + 4*y); 163 | m_indexbuffer.push_back(baseIndex+1+x + 4*y); 164 | m_indexbuffer.push_back(baseIndex+5+x + 4*y); 165 | } 166 | } 167 | End(); 168 | 169 | } 170 | 171 | void Clear() 172 | { 173 | m_buffer.clear(); 174 | m_indexbuffer.clear(); 175 | } 176 | 177 | void Update() 178 | { 179 | g->BindBuffer(SG_ARRAY_BUFFER, m_vb); 180 | g->BufferData(SG_ARRAY_BUFFER, static_cast(m_buffer.size()) * sizeof(VertexFormat), &m_buffer[0], SG_STATIC_DRAW); 181 | g->BindBuffer(SG_ELEMENT_ARRAY_BUFFER, m_ib); 182 | g->BufferData(SG_ELEMENT_ARRAY_BUFFER, static_cast(m_indexbuffer.size()) * sizeof(unsigned short), &m_indexbuffer[0], SG_STATIC_DRAW); 183 | g->BindBuffer(SG_ARRAY_BUFFER, 0); 184 | g->BindBuffer(SG_ELEMENT_ARRAY_BUFFER, 0); 185 | } 186 | 187 | void Draw() 188 | { 189 | g->BindBuffer(SG_ARRAY_BUFFER, m_vb); 190 | g->BindBuffer(SG_ELEMENT_ARRAY_BUFFER, m_ib); 191 | m_shader->Bind(); 192 | g->EnableVertexAttribArray(m_att_pos); 193 | g->VertexAttribPointer(m_att_pos, 3, SG_FLOAT, SG_FALSE, sizeof(VertexFormat), 0); 194 | g->EnableVertexAttribArray(m_att_col); 195 | g->VertexAttribPointer(m_att_col, 4, SG_UNSIGNED_BYTE, SG_TRUE, sizeof(VertexFormat), (const void*)(sizeof(float)*3)); 196 | g->EnableVertexAttribArray(m_att_uv); 197 | g->VertexAttribPointer(m_att_uv, 2, SG_FLOAT, SG_FALSE, sizeof(VertexFormat), (const void*)(sizeof(float)*4)); 198 | //g->DrawArrays(SG_TRIANGLES, 0, static_cast(m_buffer.size())); 199 | g->DrawElements(SG_TRIANGLES, static_cast(m_indexbuffer.size()), SG_UNSIGNED_SHORT, 0); 200 | g->DisableVertexAttribArray(m_att_pos); 201 | g->DisableVertexAttribArray(m_att_col); 202 | g->DisableVertexAttribArray(m_att_uv); 203 | m_shader->Unbind(); 204 | g->BindBuffer(SG_ARRAY_BUFFER, 0); 205 | g->BindBuffer(SG_ELEMENT_ARRAY_BUFFER, 0); 206 | } 207 | private: 208 | SimpleGraphics* g; 209 | unsigned int m_color; 210 | float m_uv[2]; 211 | std::vector m_buffer; 212 | std::vector m_indexbuffer; 213 | unsigned int m_vb,m_ib; 214 | int m_att_pos, m_att_col, m_att_uv; 215 | SimpleShader* m_shader; 216 | }; 217 | 218 | } // namespace skGUI 219 | 220 | #endif // INCLUDE_SIMPLEVB_H 221 | 222 | -------------------------------------------------------------------------------- /UI/WGLExtension.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "glext.h" 4 | #include "wglext.h" 5 | 6 | extern "C" { 7 | 8 | PFNGLGENBUFFERSARBPROC glGenBuffers = 0; 9 | PFNGLBINDBUFFERARBPROC glBindBuffer = 0; 10 | PFNGLBUFFERDATAARBPROC glBufferData = 0; 11 | PFNGLBUFFERSUBDATAARBPROC glBufferSubData = 0; 12 | PFNGLDELETEBUFFERSARBPROC glDeleteBuffers = 0; 13 | PFNGLGETBUFFERPARAMETERIVARBPROC glGetBufferParameteriv = 0; 14 | PFNGLMAPBUFFERARBPROC glMapBuffer = 0; 15 | PFNGLUNMAPBUFFERARBPROC glUnmapBuffer = 0; 16 | PFNGLISBUFFERARBPROC glIsBuffer = 0; 17 | 18 | PFNGLATTACHSHADERPROC glAttachShader = 0; 19 | PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation = 0; 20 | PFNGLCOMPILESHADERPROC glCompileShader = 0; 21 | PFNGLCREATEPROGRAMPROC glCreateProgram = 0; 22 | PFNGLCREATESHADERPROC glCreateShader = 0; 23 | PFNGLDELETEPROGRAMPROC glDeleteProgram = 0; 24 | PFNGLDELETESHADERPROC glDeleteShader = 0; 25 | PFNGLDETACHSHADERPROC glDetachShader = 0; 26 | PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray = 0; 27 | PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray = 0; 28 | PFNGLGETACTIVEATTRIBPROC glGetActiveAttrib = 0; 29 | PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform = 0; 30 | PFNGLGETATTACHEDSHADERSPROC glGetAttachedShaders = 0; 31 | PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation = 0; 32 | PFNGLGETPROGRAMIVPROC glGetProgramiv = 0; 33 | PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog = 0; 34 | PFNGLGETSHADERIVPROC glGetShaderiv = 0; 35 | PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog = 0; 36 | PFNGLGETSHADERSOURCEPROC glGetShaderSource = 0; 37 | PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = 0; 38 | PFNGLGETUNIFORMFVPROC glGetUniformfv = 0; 39 | PFNGLGETUNIFORMIVPROC glGetUniformiv = 0; 40 | PFNGLGETVERTEXATTRIBDVPROC glGetVertexAttribdv = 0; 41 | PFNGLGETVERTEXATTRIBFVPROC glGetVertexAttribfv = 0; 42 | PFNGLGETVERTEXATTRIBIVPROC glGetVertexAttribiv = 0; 43 | PFNGLGETVERTEXATTRIBPOINTERVPROC glGetVertexAttribPointerv = 0; 44 | PFNGLISPROGRAMPROC glIsProgram = 0; 45 | PFNGLISSHADERPROC glIsShader = 0; 46 | PFNGLLINKPROGRAMPROC glLinkProgram = 0; 47 | PFNGLSHADERSOURCEPROC glShaderSource = 0; 48 | PFNGLUSEPROGRAMPROC glUseProgram = 0; 49 | 50 | 51 | PFNGLUNIFORM1IPROC glUniform1i = 0; 52 | PFNGLUNIFORM2IPROC glUniform2i = 0; 53 | PFNGLUNIFORM3IPROC glUniform3i = 0; 54 | PFNGLUNIFORM4IPROC glUniform4i = 0; 55 | PFNGLUNIFORM1IVPROC glUniform1iv = 0; 56 | PFNGLUNIFORM2IVPROC glUniform2iv = 0; 57 | PFNGLUNIFORM3IVPROC glUniform3iv = 0; 58 | PFNGLUNIFORM4IVPROC glUniform4iv = 0; 59 | PFNGLUNIFORM1FPROC glUniform1f = 0; 60 | PFNGLUNIFORM2FPROC glUniform2f = 0; 61 | PFNGLUNIFORM3FPROC glUniform3f = 0; 62 | PFNGLUNIFORM4FPROC glUniform4f = 0; 63 | PFNGLUNIFORM1FVPROC glUniform1fv = 0; 64 | PFNGLUNIFORM2FVPROC glUniform2fv = 0; 65 | PFNGLUNIFORM3FVPROC glUniform3fv = 0; 66 | PFNGLUNIFORM4FVPROC glUniform4fv = 0; 67 | PFNGLUNIFORMMATRIX2FVPROC glUniformMatrix2fv = 0; 68 | PFNGLUNIFORMMATRIX3FVPROC glUniformMatrix3fv = 0; 69 | PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv = 0; 70 | PFNGLPROGRAMPARAMETERIEXTPROC glProgramParameteri = 0; 71 | 72 | PFNGLVALIDATEPROGRAMPROC glValidateProgram = 0; 73 | PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer = 0; 74 | 75 | 76 | bool InitGLExtension() 77 | { 78 | glGenBuffers = (PFNGLGENBUFFERSARBPROC)wglGetProcAddress("glGenBuffersARB"); 79 | glBindBuffer = (PFNGLBINDBUFFERARBPROC)wglGetProcAddress("glBindBufferARB"); 80 | glBufferData = (PFNGLBUFFERDATAARBPROC)wglGetProcAddress("glBufferDataARB"); 81 | glBufferSubData = (PFNGLBUFFERSUBDATAARBPROC)wglGetProcAddress("glBufferSubDataARB"); 82 | glDeleteBuffers = (PFNGLDELETEBUFFERSARBPROC)wglGetProcAddress("glDeleteBuffersARB"); 83 | glGetBufferParameteriv = (PFNGLGETBUFFERPARAMETERIVARBPROC)wglGetProcAddress("glGetBufferParameterivARB"); 84 | glMapBuffer = (PFNGLMAPBUFFERARBPROC)wglGetProcAddress("glMapBufferARB"); 85 | glUnmapBuffer = (PFNGLUNMAPBUFFERARBPROC)wglGetProcAddress("glUnmapBufferARB"); 86 | glIsBuffer = (PFNGLISBUFFERARBPROC)wglGetProcAddress("glIsBufferARB"); 87 | 88 | glGetUniformfv = (PFNGLGETUNIFORMFVPROC)wglGetProcAddress("glGetUniformfv"); 89 | glGetUniformiv = (PFNGLGETUNIFORMIVPROC )wglGetProcAddress("glGetUniformiv"); 90 | glGetVertexAttribdv = (PFNGLGETVERTEXATTRIBDVPROC)wglGetProcAddress("glGetVertexAttribdv"); 91 | glGetVertexAttribfv = (PFNGLGETVERTEXATTRIBFVPROC)wglGetProcAddress("glGetVertexAttribfv"); 92 | glGetVertexAttribiv = (PFNGLGETVERTEXATTRIBIVPROC)wglGetProcAddress("glGetVertexAttribiv"); 93 | glGetVertexAttribPointerv = (PFNGLGETVERTEXATTRIBPOINTERVPROC)wglGetProcAddress("glGetVertexAttribPointerv"); 94 | glIsProgram = (PFNGLISPROGRAMPROC)wglGetProcAddress("glIsProgram"); 95 | glIsShader = (PFNGLISSHADERPROC)wglGetProcAddress("glIsShader"); 96 | 97 | 98 | glCreateShader = (PFNGLCREATESHADERPROC)wglGetProcAddress("glCreateShader"); 99 | glShaderSource = (PFNGLSHADERSOURCEPROC)wglGetProcAddress("glShaderSource"); 100 | glCompileShader = (PFNGLCOMPILESHADERPROC)wglGetProcAddress("glCompileShader"); 101 | glGetShaderiv = (PFNGLGETSHADERIVPROC)wglGetProcAddress("glGetShaderiv"); 102 | glDeleteShader = (PFNGLDELETESHADERPROC)wglGetProcAddress("glDeleteShader"); 103 | glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)wglGetProcAddress("glGetShaderInfoLog"); 104 | glCreateProgram = (PFNGLCREATEPROGRAMPROC)wglGetProcAddress("glCreateProgram"); 105 | glAttachShader = (PFNGLATTACHSHADERPROC)wglGetProcAddress("glAttachShader"); 106 | glGetAttachedShaders = (PFNGLGETATTACHEDSHADERSPROC)wglGetProcAddress("glGetAttachedShaders"); 107 | glLinkProgram = (PFNGLLINKPROGRAMPROC)wglGetProcAddress("glLinkProgram"); 108 | glGetProgramiv = (PFNGLGETPROGRAMIVPROC)wglGetProcAddress("glGetProgramiv"); 109 | glUseProgram = (PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram"); 110 | glDetachShader = (PFNGLDETACHSHADERPROC)wglGetProcAddress("glDetachShader"); 111 | glDeleteProgram = (PFNGLDELETEPROGRAMPROC)wglGetProcAddress("glDeleteProgram"); 112 | glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)wglGetProcAddress("glGetProgramInfoLog"); 113 | glGetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC)wglGetProcAddress("glGetAttribLocation"); 114 | 115 | // get vertex attribute function pointers 116 | glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)wglGetProcAddress("glEnableVertexAttribArray"); 117 | glDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC)wglGetProcAddress("glDisableVertexAttribArray"); 118 | glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)wglGetProcAddress("glVertexAttribPointer"); 119 | glGetActiveAttrib = (PFNGLGETACTIVEATTRIBPROC)wglGetProcAddress("glGetActiveAttrib"); 120 | glGetActiveUniform = (PFNGLGETACTIVEUNIFORMPROC)wglGetProcAddress("glGetActiveUniform"); 121 | glBindAttribLocation = (PFNGLBINDATTRIBLOCATIONPROC)wglGetProcAddress("glBindAttribLocation"); 122 | 123 | // uniforms 124 | glGetShaderSource = (PFNGLGETSHADERSOURCEPROC)wglGetProcAddress("glGetShaderSource"); 125 | glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation"); 126 | glUniform1i = (PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"); 127 | glUniform2i = (PFNGLUNIFORM2IPROC)wglGetProcAddress("glUniform2i"); 128 | glUniform3i = (PFNGLUNIFORM3IPROC)wglGetProcAddress("glUniform3i"); 129 | glUniform4i = (PFNGLUNIFORM4IPROC)wglGetProcAddress("glUniform4i"); 130 | glUniform1iv = (PFNGLUNIFORM1IVPROC)wglGetProcAddress("glUniform1iv"); 131 | glUniform2iv = (PFNGLUNIFORM2IVPROC)wglGetProcAddress("glUniform2iv"); 132 | glUniform3iv = (PFNGLUNIFORM3IVPROC)wglGetProcAddress("glUniform3iv"); 133 | glUniform4iv = (PFNGLUNIFORM4IVPROC)wglGetProcAddress("glUniform4iv"); 134 | glUniform1f = (PFNGLUNIFORM1FPROC)wglGetProcAddress("glUniform1f"); 135 | glUniform2f = (PFNGLUNIFORM2FPROC)wglGetProcAddress("glUniform2f"); 136 | glUniform3f = (PFNGLUNIFORM3FPROC)wglGetProcAddress("glUniform3f"); 137 | glUniform4f = (PFNGLUNIFORM4FPROC)wglGetProcAddress("glUniform4f"); 138 | glUniform1fv = (PFNGLUNIFORM1FVPROC)wglGetProcAddress("glUniform1fv"); 139 | glUniform2fv = (PFNGLUNIFORM2FVPROC)wglGetProcAddress("glUniform2fv"); 140 | glUniform3fv = (PFNGLUNIFORM3FVPROC)wglGetProcAddress("glUniform3fv"); 141 | glUniform4fv = (PFNGLUNIFORM4FVPROC)wglGetProcAddress("glUniform4fv"); 142 | glUniformMatrix2fv = (PFNGLUNIFORMMATRIX2FVPROC)wglGetProcAddress("glUniformMatrix2fv"); 143 | glUniformMatrix3fv = (PFNGLUNIFORMMATRIX3FVPROC)wglGetProcAddress("glUniformMatrix3fv"); 144 | glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC)wglGetProcAddress("glUniformMatrix4fv"); 145 | glProgramParameteri = (PFNGLPROGRAMPARAMETERIEXTPROC)wglGetProcAddress("glProgramParameteri"); 146 | 147 | glValidateProgram = (PFNGLVALIDATEPROGRAMPROC)wglGetProcAddress("glValidateProgram"); 148 | glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)wglGetProcAddress("glVertexAttribPointer"); 149 | 150 | 151 | return true; 152 | } 153 | 154 | } // extern "C" -------------------------------------------------------------------------------- /UI/WGLExtension.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kioku-systemk/SimpleUI/ef04d2269ff9590a050185d84c60ea7c851b7de5/UI/WGLExtension.h -------------------------------------------------------------------------------- /UI/skBaseGUI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * skBaseGUI.h 3 | * skBaseGUI 4 | * 5 | * Created by kioku on 2010/05/04. 6 | * Copyright 2010 System K. All rights reserved. 7 | * 8 | */ 9 | 10 | #ifndef INCLUDE_SKBASEGUI_H 11 | #define INCLUDE_SKBASEGUI_H 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace skGUI 18 | { 19 | class RefPtr 20 | { 21 | protected: 22 | RefPtr() { m_ref = 0; } 23 | virtual ~RefPtr() {}; 24 | public: 25 | int Ref() const { return ++m_ref; } 26 | int GetRef() const { return m_ref; } 27 | int Unref() const { 28 | const int ref = --m_ref; 29 | assert(ref>=0); 30 | 31 | if (!ref) 32 | delete this; 33 | return ref; 34 | } 35 | 36 | private: 37 | mutable int m_ref; 38 | }; 39 | 40 | template 41 | class SharedRefPtr 42 | { 43 | public: 44 | SharedRefPtr() { m_p = 0; } 45 | SharedRefPtr(T* s) { 46 | m_p = s; 47 | if (m_p) 48 | m_p->Ref(); 49 | } 50 | SharedRefPtr(const SharedRefPtr& p) 51 | { 52 | m_p = p; 53 | if (m_p) 54 | m_p->Ref(); 55 | } 56 | ~SharedRefPtr() 57 | { 58 | if (m_p) 59 | m_p->Unref(); 60 | } 61 | 62 | T* Get() const { return m_p; } 63 | operator T*() const { return m_p; } 64 | T& operator *() const { assert(m_p); return *m_p; } 65 | T* operator->() const { assert(m_p); return m_p; } 66 | bool operator !() const { return m_p == 0; } 67 | bool operator ==(T* p) const { return m_p == p; } 68 | bool operator !=(T* p) const { return m_p != p; } 69 | bool operator <(T* p) const { return m_p < p; } 70 | T* operator =(T* p) 71 | { 72 | if (p) 73 | p->Ref(); 74 | if (m_p) 75 | m_p->Unref(); 76 | m_p = p; 77 | return m_p; 78 | } 79 | private: 80 | T* m_p; 81 | }; 82 | 83 | 84 | class BaseWindow : public RefPtr 85 | { 86 | public: 87 | bool IsEnable() { return m_enable; } 88 | void SetEnable(bool enable){ m_enable = enable; } 89 | bool IsShow() { return m_show; } 90 | void SetShow(bool show) { m_show = show; } 91 | 92 | size_t GetNumChildren() 93 | { 94 | return m_children.size(); 95 | } 96 | BaseWindow* GetChild(size_t i) 97 | { 98 | if (i < GetNumChildren()) 99 | return m_children[i]; 100 | else 101 | return NULL; 102 | } 103 | void AddChild(BaseWindow* win) 104 | { 105 | win->setParent(this); 106 | m_children.push_back(win); 107 | } 108 | bool RemoveChild(BaseWindow* win) 109 | { 110 | std::vector< SharedRefPtr >::iterator it = std::find(m_children.begin(), m_children.end(), win); 111 | if (it != m_children.end()) 112 | { 113 | m_children.erase(it); 114 | return true; 115 | } 116 | return false; 117 | } 118 | void ClearChild() 119 | { 120 | destory(); 121 | } 122 | 123 | BaseWindow* GetParent() 124 | { 125 | return m_parent; 126 | } 127 | 128 | int GetX() { return m_x; } 129 | int GetY() { return m_y; } 130 | int GetWidth() { return m_width; } 131 | int GetHeight() { return m_height; } 132 | int GetDrawOrder(){ return m_order; } 133 | float GetScale() { return m_scale; } 134 | void SetPos(int x, int y) { m_x = x; m_y = y; } 135 | void SetSize(int w, int h) { m_width = w; m_height = h; ownResized(); } 136 | void SetScale(float s) { m_scale = s; } 137 | void SetDrawOrder(int order){ m_order = order; } 138 | int GetAbsoluteX() 139 | { 140 | int x = GetX(); 141 | if (m_parent) 142 | x += m_parent->GetAbsoluteX(); 143 | return x; 144 | } 145 | int GetAbsoluteY() 146 | { 147 | int y = GetY(); 148 | if (m_parent) 149 | y += m_parent->GetAbsoluteY(); 150 | return y; 151 | } 152 | 153 | void Draw(int parent_x = 0, int parent_y = 0) 154 | { 155 | if (m_show) 156 | { 157 | ownDraw(parent_x, parent_y); 158 | std::vector< SharedRefPtr >::iterator it, eit = m_children.end(); 159 | for (it = m_children.begin(); it != eit; ++it) 160 | { 161 | (*it)->Draw(parent_x + m_x, parent_y + m_y); 162 | } 163 | ownDrawAfter(parent_x, parent_y); 164 | } 165 | } 166 | bool MouseDown(int button, int x, int y) 167 | { 168 | if (m_show && m_enable) 169 | { 170 | transformScale(x,y); 171 | bool r = false; 172 | if (isChildEvent(x,y)) 173 | { 174 | std::vector< SharedRefPtr >::iterator it, eit = m_children.end(); 175 | for (it = m_children.begin(); it != eit; ++it) 176 | { 177 | r |= (*it)->MouseDown(button, x - (*it)->GetX(), y - (*it)->GetY()); 178 | } 179 | } 180 | r |= ownMouseDown(button, x, y); 181 | return r; 182 | } 183 | return false; 184 | } 185 | bool MouseUp(int button, int x, int y) 186 | { 187 | if (m_show && m_enable) 188 | { 189 | transformScale(x,y); 190 | bool r = false; 191 | if (isChildEvent(x,y)) 192 | { 193 | std::vector< SharedRefPtr >::iterator it, eit = m_children.end(); 194 | for (it = m_children.begin(); it != eit; ++it) 195 | { 196 | r |= (*it)->MouseUp(button, x - (*it)->GetX(), y - (*it)->GetY()); 197 | } 198 | } 199 | r |= ownMouseUp(button, x, y); 200 | return r; 201 | } 202 | return false; 203 | } 204 | void MouseMove(int x, int y) 205 | { 206 | if (m_show && m_enable) 207 | { 208 | transformScale(x,y); 209 | ownMouseMove(x, y); 210 | if (isChildEvent(x,y)) 211 | { 212 | std::vector< SharedRefPtr >::iterator it, eit = m_children.end(); 213 | for (it = m_children.begin(); it != eit; ++it) 214 | { 215 | (*it)->MouseMove(x - (*it)->GetX(), y - (*it)->GetY()); 216 | } 217 | } 218 | } 219 | } 220 | void MouseDropped(BaseWindow* w) 221 | { 222 | ownMouseDropped(w); 223 | }; 224 | 225 | void KeyInput (int key) 226 | { 227 | if (m_show && m_enable) 228 | { 229 | ownKeyInput(key); 230 | if (isChildEvent(0,0)) 231 | { 232 | std::vector< SharedRefPtr >::iterator it, eit = m_children.end(); 233 | for (it = m_children.begin(); it != eit; ++it) 234 | { 235 | (*it)->KeyInput(key); 236 | } 237 | } 238 | } 239 | } 240 | 241 | void KeyDown (int key) 242 | { 243 | if (m_show && m_enable) 244 | { 245 | ownKeyDown(key); 246 | if (isChildEvent(0,0)) 247 | { 248 | std::vector< SharedRefPtr >::iterator it, eit = m_children.end(); 249 | for (it = m_children.begin(); it != eit; ++it) 250 | { 251 | (*it)->KeyDown(key); 252 | } 253 | } 254 | } 255 | } 256 | 257 | void KeyUp (int key) 258 | { 259 | if (m_show && m_enable) 260 | { 261 | ownKeyUp(key); 262 | if (isChildEvent(0,0)) 263 | { 264 | std::vector< SharedRefPtr >::iterator it, eit = m_children.end(); 265 | for (it = m_children.begin(); it != eit; ++it) 266 | { 267 | (*it)->KeyUp(key); 268 | } 269 | } 270 | } 271 | } 272 | 273 | 274 | BaseWindow* Hit(int x, int y) 275 | { 276 | BaseWindow* w = NULL; 277 | if (m_show) 278 | { 279 | transformScale(x, y); 280 | if (isChildEvent(x,y)) 281 | { 282 | std::vector< SharedRefPtr >::iterator it, eit = m_children.end(); 283 | for (it = m_children.begin(); it != eit; ++it) 284 | { 285 | BaseWindow* t = (*it)->Hit(x - (*it)->GetX(), y - (*it)->GetY()); 286 | if (w == NULL 287 | || (t != NULL && w->GetDrawOrder() <= t->GetDrawOrder())) 288 | w = t; 289 | } 290 | } 291 | if (!w) 292 | w = ownHit(x, y); 293 | } 294 | return w; 295 | } 296 | void SetActive(bool active) 297 | { 298 | m_active = active; 299 | } 300 | 301 | virtual ~BaseWindow() 302 | { 303 | destory(); 304 | } 305 | 306 | int GetType() 307 | { 308 | return m_uiType; 309 | } 310 | void SetUserData(void* data) 311 | { 312 | m_userData = data; 313 | } 314 | void* GetUserData() 315 | { 316 | return m_userData; 317 | } 318 | protected: 319 | BaseWindow(int uiType) 320 | { 321 | m_uiType = uiType; 322 | m_enable = true; 323 | m_show = true; 324 | m_active = false; 325 | m_userData = NULL; 326 | 327 | m_order = 0; 328 | m_x = m_y = m_z = 0; 329 | m_width = m_height = 100; 330 | m_scale = 1.0f; 331 | 332 | m_parent = NULL; 333 | } 334 | 335 | void destory() 336 | { 337 | m_children.clear(); 338 | } 339 | 340 | void transformScale(int& x, int& y) 341 | { 342 | if (m_scale != 1.0f) 343 | { 344 | x += static_cast(m_x - m_width * 0.5f); 345 | y += static_cast(m_y - m_height * 0.5f); 346 | x = static_cast(x / m_scale); 347 | y = static_cast(y / m_scale); 348 | x -= static_cast(m_x - m_width * 0.5f); 349 | y -= static_cast(m_y - m_height * 0.5f); 350 | } 351 | } 352 | 353 | void setParent(BaseWindow* parent){ m_parent = parent; } 354 | 355 | virtual BaseWindow* ownHit(int x, int y) = 0; 356 | virtual void ownDraw (int parent_x, int parent_y) = 0; 357 | virtual void ownDrawAfter (int parent_x, int parent_y) {}; 358 | virtual void ownResized () {}; 359 | virtual bool ownMouseDown (int button, int x, int y) = 0; 360 | virtual bool ownMouseUp (int button, int x, int y) = 0; 361 | virtual void ownMouseMove (int x, int y) = 0; 362 | virtual void ownKeyInput (int key){}; 363 | virtual void ownKeyDown (int key){}; 364 | virtual void ownKeyUp (int key){}; 365 | 366 | virtual void ownMouseDropped(BaseWindow* w){}; 367 | virtual bool isChildEvent (int x, int y) { return true; }; 368 | 369 | bool m_enable; 370 | bool m_show; 371 | bool m_active; 372 | int m_uiType; 373 | void* m_userData; 374 | 375 | int m_order;// high order is over 376 | int m_x, m_y, m_z; 377 | int m_width, m_height; 378 | float m_scale; 379 | 380 | BaseWindow* m_parent; 381 | std::vector< SharedRefPtr > m_children; 382 | }; 383 | 384 | class BlankWindow : public BaseWindow 385 | { 386 | public: 387 | BlankWindow() : BaseWindow(-1) 388 | { 389 | } 390 | ~BlankWindow() 391 | { 392 | } 393 | BaseWindow* ownHit(int x, int y){ return NULL; } 394 | void ownDraw(int parent_x, int parent_y){}; 395 | bool ownMouseDown(int button, int x, int y){ return false; }; 396 | bool ownMouseUp (int button, int x, int y){ return false; }; 397 | void ownMouseMove(int x, int y){}; 398 | }; 399 | 400 | class GUIManager 401 | { 402 | protected: 403 | GUIManager() 404 | { 405 | m_root = static_cast(new BlankWindow()); 406 | m_activeWindow = NULL; 407 | } 408 | ~GUIManager() 409 | { 410 | } 411 | 412 | public: 413 | void Draw() 414 | { 415 | beginUI(); 416 | if (m_root) 417 | { 418 | m_root->Draw(); 419 | } 420 | endUI(); 421 | } 422 | BaseWindow* Hit(int x, int y) 423 | { 424 | if (m_root) 425 | { 426 | return m_root->Hit(x, y); 427 | } 428 | return NULL; 429 | } 430 | 431 | BaseWindow* GetRoot() 432 | { 433 | return m_root; 434 | } 435 | 436 | void Deactive() 437 | { 438 | m_activeWindow = NULL; 439 | } 440 | BaseWindow* GetActiveWindow() 441 | { 442 | return m_activeWindow; 443 | } 444 | 445 | bool MouseDown(int button, int x, int y) 446 | { 447 | if (m_activeWindow) 448 | m_activeWindow->SetActive(false); 449 | m_activeWindow = Hit(x, y); 450 | if (m_activeWindow) 451 | m_activeWindow->SetActive(true); 452 | 453 | if (m_root) 454 | return m_root->MouseDown(button, x, y); 455 | 456 | return false; 457 | } 458 | bool MouseUp(int button, int x, int y) 459 | { 460 | if (m_root) 461 | { 462 | bool r = m_root->MouseUp(button, x, y); 463 | BaseWindow* w = Hit(x, y); 464 | if (w && m_activeWindow != w) 465 | { 466 | w->MouseDropped(m_activeWindow); 467 | } 468 | return r; 469 | } 470 | return false; 471 | } 472 | void MouseMove(int x, int y) 473 | { 474 | if (m_root) 475 | { 476 | m_root->MouseMove(x, y); 477 | } 478 | } 479 | void KeyInput(int key) 480 | { 481 | if (m_root) 482 | m_root->KeyInput(key); 483 | } 484 | void KeyDown(int key) 485 | { 486 | if (m_root) 487 | m_root->KeyDown(key); 488 | } 489 | void KeyUp(int key) 490 | { 491 | if (m_root) 492 | m_root->KeyUp(key); 493 | } 494 | 495 | 496 | int GetWidth() { return m_width; } 497 | int GetHeight(){ return m_height; } 498 | 499 | void Resize(int w, int h){ m_width = w; m_height = h; } 500 | protected: 501 | virtual void beginUI() = 0; 502 | virtual void endUI() = 0; 503 | 504 | SharedRefPtr m_root; 505 | SharedRefPtr m_activeWindow; 506 | int m_width, m_height; 507 | 508 | }; 509 | 510 | 511 | }// skGUI 512 | 513 | #endif // INCLUDE_SKBASEGUI_H 514 | 515 | -------------------------------------------------------------------------------- /UI/wglext.h: -------------------------------------------------------------------------------- 1 | #ifndef __wglext_h_ 2 | #define __wglext_h_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* 9 | ** Copyright (c) 2007-2012 The Khronos Group Inc. 10 | ** 11 | ** Permission is hereby granted, free of charge, to any person obtaining a 12 | ** copy of this software and/or associated documentation files (the 13 | ** "Materials"), to deal in the Materials without restriction, including 14 | ** without limitation the rights to use, copy, modify, merge, publish, 15 | ** distribute, sublicense, and/or sell copies of the Materials, and to 16 | ** permit persons to whom the Materials are furnished to do so, subject to 17 | ** the following conditions: 18 | ** 19 | ** The above copyright notice and this permission notice shall be included 20 | ** in all copies or substantial portions of the Materials. 21 | ** 22 | ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 29 | */ 30 | 31 | /* Function declaration macros - to move into glplatform.h */ 32 | 33 | #if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) 34 | #define WIN32_LEAN_AND_MEAN 1 35 | #include 36 | #endif 37 | 38 | #ifndef APIENTRY 39 | #define APIENTRY 40 | #endif 41 | #ifndef APIENTRYP 42 | #define APIENTRYP APIENTRY * 43 | #endif 44 | #ifndef GLAPI 45 | #define GLAPI extern 46 | #endif 47 | 48 | /*************************************************************/ 49 | 50 | /* Header file version number */ 51 | /* wglext.h last updated 2012/01/04 */ 52 | /* Current version at http://www.opengl.org/registry/ */ 53 | #define WGL_WGLEXT_VERSION 24 54 | 55 | #ifndef WGL_ARB_buffer_region 56 | #define WGL_FRONT_COLOR_BUFFER_BIT_ARB 0x00000001 57 | #define WGL_BACK_COLOR_BUFFER_BIT_ARB 0x00000002 58 | #define WGL_DEPTH_BUFFER_BIT_ARB 0x00000004 59 | #define WGL_STENCIL_BUFFER_BIT_ARB 0x00000008 60 | #endif 61 | 62 | #ifndef WGL_ARB_multisample 63 | #define WGL_SAMPLE_BUFFERS_ARB 0x2041 64 | #define WGL_SAMPLES_ARB 0x2042 65 | #endif 66 | 67 | #ifndef WGL_ARB_extensions_string 68 | #endif 69 | 70 | #ifndef WGL_ARB_pixel_format 71 | #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 72 | #define WGL_DRAW_TO_WINDOW_ARB 0x2001 73 | #define WGL_DRAW_TO_BITMAP_ARB 0x2002 74 | #define WGL_ACCELERATION_ARB 0x2003 75 | #define WGL_NEED_PALETTE_ARB 0x2004 76 | #define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005 77 | #define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006 78 | #define WGL_SWAP_METHOD_ARB 0x2007 79 | #define WGL_NUMBER_OVERLAYS_ARB 0x2008 80 | #define WGL_NUMBER_UNDERLAYS_ARB 0x2009 81 | #define WGL_TRANSPARENT_ARB 0x200A 82 | #define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037 83 | #define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038 84 | #define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039 85 | #define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A 86 | #define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B 87 | #define WGL_SHARE_DEPTH_ARB 0x200C 88 | #define WGL_SHARE_STENCIL_ARB 0x200D 89 | #define WGL_SHARE_ACCUM_ARB 0x200E 90 | #define WGL_SUPPORT_GDI_ARB 0x200F 91 | #define WGL_SUPPORT_OPENGL_ARB 0x2010 92 | #define WGL_DOUBLE_BUFFER_ARB 0x2011 93 | #define WGL_STEREO_ARB 0x2012 94 | #define WGL_PIXEL_TYPE_ARB 0x2013 95 | #define WGL_COLOR_BITS_ARB 0x2014 96 | #define WGL_RED_BITS_ARB 0x2015 97 | #define WGL_RED_SHIFT_ARB 0x2016 98 | #define WGL_GREEN_BITS_ARB 0x2017 99 | #define WGL_GREEN_SHIFT_ARB 0x2018 100 | #define WGL_BLUE_BITS_ARB 0x2019 101 | #define WGL_BLUE_SHIFT_ARB 0x201A 102 | #define WGL_ALPHA_BITS_ARB 0x201B 103 | #define WGL_ALPHA_SHIFT_ARB 0x201C 104 | #define WGL_ACCUM_BITS_ARB 0x201D 105 | #define WGL_ACCUM_RED_BITS_ARB 0x201E 106 | #define WGL_ACCUM_GREEN_BITS_ARB 0x201F 107 | #define WGL_ACCUM_BLUE_BITS_ARB 0x2020 108 | #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 109 | #define WGL_DEPTH_BITS_ARB 0x2022 110 | #define WGL_STENCIL_BITS_ARB 0x2023 111 | #define WGL_AUX_BUFFERS_ARB 0x2024 112 | #define WGL_NO_ACCELERATION_ARB 0x2025 113 | #define WGL_GENERIC_ACCELERATION_ARB 0x2026 114 | #define WGL_FULL_ACCELERATION_ARB 0x2027 115 | #define WGL_SWAP_EXCHANGE_ARB 0x2028 116 | #define WGL_SWAP_COPY_ARB 0x2029 117 | #define WGL_SWAP_UNDEFINED_ARB 0x202A 118 | #define WGL_TYPE_RGBA_ARB 0x202B 119 | #define WGL_TYPE_COLORINDEX_ARB 0x202C 120 | #endif 121 | 122 | #ifndef WGL_ARB_make_current_read 123 | #define ERROR_INVALID_PIXEL_TYPE_ARB 0x2043 124 | #define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB 0x2054 125 | #endif 126 | 127 | #ifndef WGL_ARB_pbuffer 128 | #define WGL_DRAW_TO_PBUFFER_ARB 0x202D 129 | #define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E 130 | #define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F 131 | #define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030 132 | #define WGL_PBUFFER_LARGEST_ARB 0x2033 133 | #define WGL_PBUFFER_WIDTH_ARB 0x2034 134 | #define WGL_PBUFFER_HEIGHT_ARB 0x2035 135 | #define WGL_PBUFFER_LOST_ARB 0x2036 136 | #endif 137 | 138 | #ifndef WGL_ARB_render_texture 139 | #define WGL_BIND_TO_TEXTURE_RGB_ARB 0x2070 140 | #define WGL_BIND_TO_TEXTURE_RGBA_ARB 0x2071 141 | #define WGL_TEXTURE_FORMAT_ARB 0x2072 142 | #define WGL_TEXTURE_TARGET_ARB 0x2073 143 | #define WGL_MIPMAP_TEXTURE_ARB 0x2074 144 | #define WGL_TEXTURE_RGB_ARB 0x2075 145 | #define WGL_TEXTURE_RGBA_ARB 0x2076 146 | #define WGL_NO_TEXTURE_ARB 0x2077 147 | #define WGL_TEXTURE_CUBE_MAP_ARB 0x2078 148 | #define WGL_TEXTURE_1D_ARB 0x2079 149 | #define WGL_TEXTURE_2D_ARB 0x207A 150 | #define WGL_MIPMAP_LEVEL_ARB 0x207B 151 | #define WGL_CUBE_MAP_FACE_ARB 0x207C 152 | #define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x207D 153 | #define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x207E 154 | #define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x207F 155 | #define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x2080 156 | #define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x2081 157 | #define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x2082 158 | #define WGL_FRONT_LEFT_ARB 0x2083 159 | #define WGL_FRONT_RIGHT_ARB 0x2084 160 | #define WGL_BACK_LEFT_ARB 0x2085 161 | #define WGL_BACK_RIGHT_ARB 0x2086 162 | #define WGL_AUX0_ARB 0x2087 163 | #define WGL_AUX1_ARB 0x2088 164 | #define WGL_AUX2_ARB 0x2089 165 | #define WGL_AUX3_ARB 0x208A 166 | #define WGL_AUX4_ARB 0x208B 167 | #define WGL_AUX5_ARB 0x208C 168 | #define WGL_AUX6_ARB 0x208D 169 | #define WGL_AUX7_ARB 0x208E 170 | #define WGL_AUX8_ARB 0x208F 171 | #define WGL_AUX9_ARB 0x2090 172 | #endif 173 | 174 | #ifndef WGL_ARB_pixel_format_float 175 | #define WGL_TYPE_RGBA_FLOAT_ARB 0x21A0 176 | #endif 177 | 178 | #ifndef WGL_ARB_framebuffer_sRGB 179 | #define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9 180 | #endif 181 | 182 | #ifndef WGL_ARB_create_context 183 | #define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001 184 | #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 185 | #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 186 | #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 187 | #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093 188 | #define WGL_CONTEXT_FLAGS_ARB 0x2094 189 | #define ERROR_INVALID_VERSION_ARB 0x2095 190 | #endif 191 | 192 | #ifndef WGL_ARB_create_context_profile 193 | #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 194 | #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 195 | #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 196 | #define ERROR_INVALID_PROFILE_ARB 0x2096 197 | #endif 198 | 199 | #ifndef WGL_ARB_create_context_robustness 200 | #define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 201 | #define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 202 | #define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 203 | #define WGL_NO_RESET_NOTIFICATION_ARB 0x8261 204 | #endif 205 | 206 | #ifndef WGL_EXT_make_current_read 207 | #define ERROR_INVALID_PIXEL_TYPE_EXT 0x2043 208 | #endif 209 | 210 | #ifndef WGL_EXT_pixel_format 211 | #define WGL_NUMBER_PIXEL_FORMATS_EXT 0x2000 212 | #define WGL_DRAW_TO_WINDOW_EXT 0x2001 213 | #define WGL_DRAW_TO_BITMAP_EXT 0x2002 214 | #define WGL_ACCELERATION_EXT 0x2003 215 | #define WGL_NEED_PALETTE_EXT 0x2004 216 | #define WGL_NEED_SYSTEM_PALETTE_EXT 0x2005 217 | #define WGL_SWAP_LAYER_BUFFERS_EXT 0x2006 218 | #define WGL_SWAP_METHOD_EXT 0x2007 219 | #define WGL_NUMBER_OVERLAYS_EXT 0x2008 220 | #define WGL_NUMBER_UNDERLAYS_EXT 0x2009 221 | #define WGL_TRANSPARENT_EXT 0x200A 222 | #define WGL_TRANSPARENT_VALUE_EXT 0x200B 223 | #define WGL_SHARE_DEPTH_EXT 0x200C 224 | #define WGL_SHARE_STENCIL_EXT 0x200D 225 | #define WGL_SHARE_ACCUM_EXT 0x200E 226 | #define WGL_SUPPORT_GDI_EXT 0x200F 227 | #define WGL_SUPPORT_OPENGL_EXT 0x2010 228 | #define WGL_DOUBLE_BUFFER_EXT 0x2011 229 | #define WGL_STEREO_EXT 0x2012 230 | #define WGL_PIXEL_TYPE_EXT 0x2013 231 | #define WGL_COLOR_BITS_EXT 0x2014 232 | #define WGL_RED_BITS_EXT 0x2015 233 | #define WGL_RED_SHIFT_EXT 0x2016 234 | #define WGL_GREEN_BITS_EXT 0x2017 235 | #define WGL_GREEN_SHIFT_EXT 0x2018 236 | #define WGL_BLUE_BITS_EXT 0x2019 237 | #define WGL_BLUE_SHIFT_EXT 0x201A 238 | #define WGL_ALPHA_BITS_EXT 0x201B 239 | #define WGL_ALPHA_SHIFT_EXT 0x201C 240 | #define WGL_ACCUM_BITS_EXT 0x201D 241 | #define WGL_ACCUM_RED_BITS_EXT 0x201E 242 | #define WGL_ACCUM_GREEN_BITS_EXT 0x201F 243 | #define WGL_ACCUM_BLUE_BITS_EXT 0x2020 244 | #define WGL_ACCUM_ALPHA_BITS_EXT 0x2021 245 | #define WGL_DEPTH_BITS_EXT 0x2022 246 | #define WGL_STENCIL_BITS_EXT 0x2023 247 | #define WGL_AUX_BUFFERS_EXT 0x2024 248 | #define WGL_NO_ACCELERATION_EXT 0x2025 249 | #define WGL_GENERIC_ACCELERATION_EXT 0x2026 250 | #define WGL_FULL_ACCELERATION_EXT 0x2027 251 | #define WGL_SWAP_EXCHANGE_EXT 0x2028 252 | #define WGL_SWAP_COPY_EXT 0x2029 253 | #define WGL_SWAP_UNDEFINED_EXT 0x202A 254 | #define WGL_TYPE_RGBA_EXT 0x202B 255 | #define WGL_TYPE_COLORINDEX_EXT 0x202C 256 | #endif 257 | 258 | #ifndef WGL_EXT_pbuffer 259 | #define WGL_DRAW_TO_PBUFFER_EXT 0x202D 260 | #define WGL_MAX_PBUFFER_PIXELS_EXT 0x202E 261 | #define WGL_MAX_PBUFFER_WIDTH_EXT 0x202F 262 | #define WGL_MAX_PBUFFER_HEIGHT_EXT 0x2030 263 | #define WGL_OPTIMAL_PBUFFER_WIDTH_EXT 0x2031 264 | #define WGL_OPTIMAL_PBUFFER_HEIGHT_EXT 0x2032 265 | #define WGL_PBUFFER_LARGEST_EXT 0x2033 266 | #define WGL_PBUFFER_WIDTH_EXT 0x2034 267 | #define WGL_PBUFFER_HEIGHT_EXT 0x2035 268 | #endif 269 | 270 | #ifndef WGL_EXT_depth_float 271 | #define WGL_DEPTH_FLOAT_EXT 0x2040 272 | #endif 273 | 274 | #ifndef WGL_3DFX_multisample 275 | #define WGL_SAMPLE_BUFFERS_3DFX 0x2060 276 | #define WGL_SAMPLES_3DFX 0x2061 277 | #endif 278 | 279 | #ifndef WGL_EXT_multisample 280 | #define WGL_SAMPLE_BUFFERS_EXT 0x2041 281 | #define WGL_SAMPLES_EXT 0x2042 282 | #endif 283 | 284 | #ifndef WGL_I3D_digital_video_control 285 | #define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D 0x2050 286 | #define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D 0x2051 287 | #define WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D 0x2052 288 | #define WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D 0x2053 289 | #endif 290 | 291 | #ifndef WGL_I3D_gamma 292 | #define WGL_GAMMA_TABLE_SIZE_I3D 0x204E 293 | #define WGL_GAMMA_EXCLUDE_DESKTOP_I3D 0x204F 294 | #endif 295 | 296 | #ifndef WGL_I3D_genlock 297 | #define WGL_GENLOCK_SOURCE_MULTIVIEW_I3D 0x2044 298 | #define WGL_GENLOCK_SOURCE_EXTENAL_SYNC_I3D 0x2045 299 | #define WGL_GENLOCK_SOURCE_EXTENAL_FIELD_I3D 0x2046 300 | #define WGL_GENLOCK_SOURCE_EXTENAL_TTL_I3D 0x2047 301 | #define WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D 0x2048 302 | #define WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D 0x2049 303 | #define WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D 0x204A 304 | #define WGL_GENLOCK_SOURCE_EDGE_RISING_I3D 0x204B 305 | #define WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D 0x204C 306 | #endif 307 | 308 | #ifndef WGL_I3D_image_buffer 309 | #define WGL_IMAGE_BUFFER_MIN_ACCESS_I3D 0x00000001 310 | #define WGL_IMAGE_BUFFER_LOCK_I3D 0x00000002 311 | #endif 312 | 313 | #ifndef WGL_I3D_swap_frame_lock 314 | #endif 315 | 316 | #ifndef WGL_NV_render_depth_texture 317 | #define WGL_BIND_TO_TEXTURE_DEPTH_NV 0x20A3 318 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV 0x20A4 319 | #define WGL_DEPTH_TEXTURE_FORMAT_NV 0x20A5 320 | #define WGL_TEXTURE_DEPTH_COMPONENT_NV 0x20A6 321 | #define WGL_DEPTH_COMPONENT_NV 0x20A7 322 | #endif 323 | 324 | #ifndef WGL_NV_render_texture_rectangle 325 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV 0x20A0 326 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV 0x20A1 327 | #define WGL_TEXTURE_RECTANGLE_NV 0x20A2 328 | #endif 329 | 330 | #ifndef WGL_ATI_pixel_format_float 331 | #define WGL_TYPE_RGBA_FLOAT_ATI 0x21A0 332 | #endif 333 | 334 | #ifndef WGL_NV_float_buffer 335 | #define WGL_FLOAT_COMPONENTS_NV 0x20B0 336 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV 0x20B1 337 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV 0x20B2 338 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV 0x20B3 339 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV 0x20B4 340 | #define WGL_TEXTURE_FLOAT_R_NV 0x20B5 341 | #define WGL_TEXTURE_FLOAT_RG_NV 0x20B6 342 | #define WGL_TEXTURE_FLOAT_RGB_NV 0x20B7 343 | #define WGL_TEXTURE_FLOAT_RGBA_NV 0x20B8 344 | #endif 345 | 346 | #ifndef WGL_3DL_stereo_control 347 | #define WGL_STEREO_EMITTER_ENABLE_3DL 0x2055 348 | #define WGL_STEREO_EMITTER_DISABLE_3DL 0x2056 349 | #define WGL_STEREO_POLARITY_NORMAL_3DL 0x2057 350 | #define WGL_STEREO_POLARITY_INVERT_3DL 0x2058 351 | #endif 352 | 353 | #ifndef WGL_EXT_pixel_format_packed_float 354 | #define WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT 0x20A8 355 | #endif 356 | 357 | #ifndef WGL_EXT_framebuffer_sRGB 358 | #define WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20A9 359 | #endif 360 | 361 | #ifndef WGL_NV_present_video 362 | #define WGL_NUM_VIDEO_SLOTS_NV 0x20F0 363 | #endif 364 | 365 | #ifndef WGL_NV_video_out 366 | #define WGL_BIND_TO_VIDEO_RGB_NV 0x20C0 367 | #define WGL_BIND_TO_VIDEO_RGBA_NV 0x20C1 368 | #define WGL_BIND_TO_VIDEO_RGB_AND_DEPTH_NV 0x20C2 369 | #define WGL_VIDEO_OUT_COLOR_NV 0x20C3 370 | #define WGL_VIDEO_OUT_ALPHA_NV 0x20C4 371 | #define WGL_VIDEO_OUT_DEPTH_NV 0x20C5 372 | #define WGL_VIDEO_OUT_COLOR_AND_ALPHA_NV 0x20C6 373 | #define WGL_VIDEO_OUT_COLOR_AND_DEPTH_NV 0x20C7 374 | #define WGL_VIDEO_OUT_FRAME 0x20C8 375 | #define WGL_VIDEO_OUT_FIELD_1 0x20C9 376 | #define WGL_VIDEO_OUT_FIELD_2 0x20CA 377 | #define WGL_VIDEO_OUT_STACKED_FIELDS_1_2 0x20CB 378 | #define WGL_VIDEO_OUT_STACKED_FIELDS_2_1 0x20CC 379 | #endif 380 | 381 | #ifndef WGL_NV_swap_group 382 | #endif 383 | 384 | #ifndef WGL_NV_gpu_affinity 385 | #define WGL_ERROR_INCOMPATIBLE_AFFINITY_MASKS_NV 0x20D0 386 | #define WGL_ERROR_MISSING_AFFINITY_MASK_NV 0x20D1 387 | #endif 388 | 389 | #ifndef WGL_AMD_gpu_association 390 | #define WGL_GPU_VENDOR_AMD 0x1F00 391 | #define WGL_GPU_RENDERER_STRING_AMD 0x1F01 392 | #define WGL_GPU_OPENGL_VERSION_STRING_AMD 0x1F02 393 | #define WGL_GPU_FASTEST_TARGET_GPUS_AMD 0x21A2 394 | #define WGL_GPU_RAM_AMD 0x21A3 395 | #define WGL_GPU_CLOCK_AMD 0x21A4 396 | #define WGL_GPU_NUM_PIPES_AMD 0x21A5 397 | #define WGL_GPU_NUM_SIMD_AMD 0x21A6 398 | #define WGL_GPU_NUM_RB_AMD 0x21A7 399 | #define WGL_GPU_NUM_SPI_AMD 0x21A8 400 | #endif 401 | 402 | #ifndef WGL_NV_video_capture 403 | #define WGL_UNIQUE_ID_NV 0x20CE 404 | #define WGL_NUM_VIDEO_CAPTURE_SLOTS_NV 0x20CF 405 | #endif 406 | 407 | #ifndef WGL_NV_copy_image 408 | #endif 409 | 410 | #ifndef WGL_NV_multisample_coverage 411 | #define WGL_COVERAGE_SAMPLES_NV 0x2042 412 | #define WGL_COLOR_SAMPLES_NV 0x20B9 413 | #endif 414 | 415 | #ifndef WGL_EXT_create_context_es2_profile 416 | #define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 417 | #endif 418 | 419 | #ifndef WGL_NV_DX_interop 420 | #define WGL_ACCESS_READ_ONLY_NV 0x00000000 421 | #define WGL_ACCESS_READ_WRITE_NV 0x00000001 422 | #define WGL_ACCESS_WRITE_DISCARD_NV 0x00000002 423 | #endif 424 | 425 | #ifndef WGL_NV_DX_interop2 426 | #endif 427 | 428 | #ifndef WGL_EXT_swap_control_tear 429 | #endif 430 | 431 | 432 | /*************************************************************/ 433 | 434 | #ifndef WGL_ARB_pbuffer 435 | DECLARE_HANDLE(HPBUFFERARB); 436 | #endif 437 | #ifndef WGL_EXT_pbuffer 438 | DECLARE_HANDLE(HPBUFFEREXT); 439 | #endif 440 | #ifndef WGL_NV_present_video 441 | DECLARE_HANDLE(HVIDEOOUTPUTDEVICENV); 442 | #endif 443 | #ifndef WGL_NV_video_output 444 | DECLARE_HANDLE(HPVIDEODEV); 445 | #endif 446 | #ifndef WGL_NV_gpu_affinity 447 | DECLARE_HANDLE(HPGPUNV); 448 | DECLARE_HANDLE(HGPUNV); 449 | 450 | typedef struct _GPU_DEVICE { 451 | DWORD cb; 452 | CHAR DeviceName[32]; 453 | CHAR DeviceString[128]; 454 | DWORD Flags; 455 | RECT rcVirtualScreen; 456 | } GPU_DEVICE, *PGPU_DEVICE; 457 | #endif 458 | #ifndef WGL_NV_video_capture 459 | DECLARE_HANDLE(HVIDEOINPUTDEVICENV); 460 | #endif 461 | 462 | #ifndef WGL_ARB_buffer_region 463 | #define WGL_ARB_buffer_region 1 464 | #ifdef WGL_WGLEXT_PROTOTYPES 465 | extern HANDLE WINAPI wglCreateBufferRegionARB (HDC hDC, int iLayerPlane, UINT uType); 466 | extern VOID WINAPI wglDeleteBufferRegionARB (HANDLE hRegion); 467 | extern BOOL WINAPI wglSaveBufferRegionARB (HANDLE hRegion, int x, int y, int width, int height); 468 | extern BOOL WINAPI wglRestoreBufferRegionARB (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc); 469 | #endif /* WGL_WGLEXT_PROTOTYPES */ 470 | typedef HANDLE (WINAPI * PFNWGLCREATEBUFFERREGIONARBPROC) (HDC hDC, int iLayerPlane, UINT uType); 471 | typedef VOID (WINAPI * PFNWGLDELETEBUFFERREGIONARBPROC) (HANDLE hRegion); 472 | typedef BOOL (WINAPI * PFNWGLSAVEBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height); 473 | typedef BOOL (WINAPI * PFNWGLRESTOREBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc); 474 | #endif 475 | 476 | #ifndef WGL_ARB_multisample 477 | #define WGL_ARB_multisample 1 478 | #endif 479 | 480 | #ifndef WGL_ARB_extensions_string 481 | #define WGL_ARB_extensions_string 1 482 | #ifdef WGL_WGLEXT_PROTOTYPES 483 | extern const char * WINAPI wglGetExtensionsStringARB (HDC hdc); 484 | #endif /* WGL_WGLEXT_PROTOTYPES */ 485 | typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc); 486 | #endif 487 | 488 | #ifndef WGL_ARB_pixel_format 489 | #define WGL_ARB_pixel_format 1 490 | #ifdef WGL_WGLEXT_PROTOTYPES 491 | extern BOOL WINAPI wglGetPixelFormatAttribivARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues); 492 | extern BOOL WINAPI wglGetPixelFormatAttribfvARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues); 493 | extern BOOL WINAPI wglChoosePixelFormatARB (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); 494 | #endif /* WGL_WGLEXT_PROTOTYPES */ 495 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues); 496 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues); 497 | typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); 498 | #endif 499 | 500 | #ifndef WGL_ARB_make_current_read 501 | #define WGL_ARB_make_current_read 1 502 | #ifdef WGL_WGLEXT_PROTOTYPES 503 | extern BOOL WINAPI wglMakeContextCurrentARB (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); 504 | extern HDC WINAPI wglGetCurrentReadDCARB (void); 505 | #endif /* WGL_WGLEXT_PROTOTYPES */ 506 | typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTARBPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); 507 | typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCARBPROC) (void); 508 | #endif 509 | 510 | #ifndef WGL_ARB_pbuffer 511 | #define WGL_ARB_pbuffer 1 512 | #ifdef WGL_WGLEXT_PROTOTYPES 513 | extern HPBUFFERARB WINAPI wglCreatePbufferARB (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); 514 | extern HDC WINAPI wglGetPbufferDCARB (HPBUFFERARB hPbuffer); 515 | extern int WINAPI wglReleasePbufferDCARB (HPBUFFERARB hPbuffer, HDC hDC); 516 | extern BOOL WINAPI wglDestroyPbufferARB (HPBUFFERARB hPbuffer); 517 | extern BOOL WINAPI wglQueryPbufferARB (HPBUFFERARB hPbuffer, int iAttribute, int *piValue); 518 | #endif /* WGL_WGLEXT_PROTOTYPES */ 519 | typedef HPBUFFERARB (WINAPI * PFNWGLCREATEPBUFFERARBPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); 520 | typedef HDC (WINAPI * PFNWGLGETPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer); 521 | typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer, HDC hDC); 522 | typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFERARBPROC) (HPBUFFERARB hPbuffer); 523 | typedef BOOL (WINAPI * PFNWGLQUERYPBUFFERARBPROC) (HPBUFFERARB hPbuffer, int iAttribute, int *piValue); 524 | #endif 525 | 526 | #ifndef WGL_ARB_render_texture 527 | #define WGL_ARB_render_texture 1 528 | #ifdef WGL_WGLEXT_PROTOTYPES 529 | extern BOOL WINAPI wglBindTexImageARB (HPBUFFERARB hPbuffer, int iBuffer); 530 | extern BOOL WINAPI wglReleaseTexImageARB (HPBUFFERARB hPbuffer, int iBuffer); 531 | extern BOOL WINAPI wglSetPbufferAttribARB (HPBUFFERARB hPbuffer, const int *piAttribList); 532 | #endif /* WGL_WGLEXT_PROTOTYPES */ 533 | typedef BOOL (WINAPI * PFNWGLBINDTEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer); 534 | typedef BOOL (WINAPI * PFNWGLRELEASETEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer); 535 | typedef BOOL (WINAPI * PFNWGLSETPBUFFERATTRIBARBPROC) (HPBUFFERARB hPbuffer, const int *piAttribList); 536 | #endif 537 | 538 | #ifndef WGL_ARB_pixel_format_float 539 | #define WGL_ARB_pixel_format_float 1 540 | #endif 541 | 542 | #ifndef WGL_ARB_framebuffer_sRGB 543 | #define WGL_ARB_framebuffer_sRGB 1 544 | #endif 545 | 546 | #ifndef WGL_ARB_create_context 547 | #define WGL_ARB_create_context 1 548 | #ifdef WGL_WGLEXT_PROTOTYPES 549 | extern HGLRC WINAPI wglCreateContextAttribsARB (HDC hDC, HGLRC hShareContext, const int *attribList); 550 | #endif /* WGL_WGLEXT_PROTOTYPES */ 551 | typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList); 552 | #endif 553 | 554 | #ifndef WGL_ARB_create_context_profile 555 | #define WGL_ARB_create_context_profile 1 556 | #endif 557 | 558 | #ifndef WGL_ARB_create_context_robustness 559 | #define WGL_ARB_create_context_robustness 1 560 | #endif 561 | 562 | #ifndef WGL_EXT_display_color_table 563 | #define WGL_EXT_display_color_table 1 564 | #ifdef WGL_WGLEXT_PROTOTYPES 565 | extern GLboolean WINAPI wglCreateDisplayColorTableEXT (GLushort id); 566 | extern GLboolean WINAPI wglLoadDisplayColorTableEXT (const GLushort *table, GLuint length); 567 | extern GLboolean WINAPI wglBindDisplayColorTableEXT (GLushort id); 568 | extern VOID WINAPI wglDestroyDisplayColorTableEXT (GLushort id); 569 | #endif /* WGL_WGLEXT_PROTOTYPES */ 570 | typedef GLboolean (WINAPI * PFNWGLCREATEDISPLAYCOLORTABLEEXTPROC) (GLushort id); 571 | typedef GLboolean (WINAPI * PFNWGLLOADDISPLAYCOLORTABLEEXTPROC) (const GLushort *table, GLuint length); 572 | typedef GLboolean (WINAPI * PFNWGLBINDDISPLAYCOLORTABLEEXTPROC) (GLushort id); 573 | typedef VOID (WINAPI * PFNWGLDESTROYDISPLAYCOLORTABLEEXTPROC) (GLushort id); 574 | #endif 575 | 576 | #ifndef WGL_EXT_extensions_string 577 | #define WGL_EXT_extensions_string 1 578 | #ifdef WGL_WGLEXT_PROTOTYPES 579 | extern const char * WINAPI wglGetExtensionsStringEXT (void); 580 | #endif /* WGL_WGLEXT_PROTOTYPES */ 581 | typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC) (void); 582 | #endif 583 | 584 | #ifndef WGL_EXT_make_current_read 585 | #define WGL_EXT_make_current_read 1 586 | #ifdef WGL_WGLEXT_PROTOTYPES 587 | extern BOOL WINAPI wglMakeContextCurrentEXT (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); 588 | extern HDC WINAPI wglGetCurrentReadDCEXT (void); 589 | #endif /* WGL_WGLEXT_PROTOTYPES */ 590 | typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTEXTPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); 591 | typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCEXTPROC) (void); 592 | #endif 593 | 594 | #ifndef WGL_EXT_pbuffer 595 | #define WGL_EXT_pbuffer 1 596 | #ifdef WGL_WGLEXT_PROTOTYPES 597 | extern HPBUFFEREXT WINAPI wglCreatePbufferEXT (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); 598 | extern HDC WINAPI wglGetPbufferDCEXT (HPBUFFEREXT hPbuffer); 599 | extern int WINAPI wglReleasePbufferDCEXT (HPBUFFEREXT hPbuffer, HDC hDC); 600 | extern BOOL WINAPI wglDestroyPbufferEXT (HPBUFFEREXT hPbuffer); 601 | extern BOOL WINAPI wglQueryPbufferEXT (HPBUFFEREXT hPbuffer, int iAttribute, int *piValue); 602 | #endif /* WGL_WGLEXT_PROTOTYPES */ 603 | typedef HPBUFFEREXT (WINAPI * PFNWGLCREATEPBUFFEREXTPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); 604 | typedef HDC (WINAPI * PFNWGLGETPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer); 605 | typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer, HDC hDC); 606 | typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer); 607 | typedef BOOL (WINAPI * PFNWGLQUERYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer, int iAttribute, int *piValue); 608 | #endif 609 | 610 | #ifndef WGL_EXT_pixel_format 611 | #define WGL_EXT_pixel_format 1 612 | #ifdef WGL_WGLEXT_PROTOTYPES 613 | extern BOOL WINAPI wglGetPixelFormatAttribivEXT (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues); 614 | extern BOOL WINAPI wglGetPixelFormatAttribfvEXT (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, FLOAT *pfValues); 615 | extern BOOL WINAPI wglChoosePixelFormatEXT (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); 616 | #endif /* WGL_WGLEXT_PROTOTYPES */ 617 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues); 618 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, FLOAT *pfValues); 619 | typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATEXTPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); 620 | #endif 621 | 622 | #ifndef WGL_EXT_swap_control 623 | #define WGL_EXT_swap_control 1 624 | #ifdef WGL_WGLEXT_PROTOTYPES 625 | extern BOOL WINAPI wglSwapIntervalEXT (int interval); 626 | extern int WINAPI wglGetSwapIntervalEXT (void); 627 | #endif /* WGL_WGLEXT_PROTOTYPES */ 628 | typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval); 629 | typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void); 630 | #endif 631 | 632 | #ifndef WGL_EXT_depth_float 633 | #define WGL_EXT_depth_float 1 634 | #endif 635 | 636 | #ifndef WGL_NV_vertex_array_range 637 | #define WGL_NV_vertex_array_range 1 638 | #ifdef WGL_WGLEXT_PROTOTYPES 639 | extern void* WINAPI wglAllocateMemoryNV (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority); 640 | extern void WINAPI wglFreeMemoryNV (void *pointer); 641 | #endif /* WGL_WGLEXT_PROTOTYPES */ 642 | typedef void* (WINAPI * PFNWGLALLOCATEMEMORYNVPROC) (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority); 643 | typedef void (WINAPI * PFNWGLFREEMEMORYNVPROC) (void *pointer); 644 | #endif 645 | 646 | #ifndef WGL_3DFX_multisample 647 | #define WGL_3DFX_multisample 1 648 | #endif 649 | 650 | #ifndef WGL_EXT_multisample 651 | #define WGL_EXT_multisample 1 652 | #endif 653 | 654 | #ifndef WGL_OML_sync_control 655 | #define WGL_OML_sync_control 1 656 | #ifdef WGL_WGLEXT_PROTOTYPES 657 | extern BOOL WINAPI wglGetSyncValuesOML (HDC hdc, INT64 *ust, INT64 *msc, INT64 *sbc); 658 | extern BOOL WINAPI wglGetMscRateOML (HDC hdc, INT32 *numerator, INT32 *denominator); 659 | extern INT64 WINAPI wglSwapBuffersMscOML (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder); 660 | extern INT64 WINAPI wglSwapLayerBuffersMscOML (HDC hdc, int fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder); 661 | extern BOOL WINAPI wglWaitForMscOML (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64 *ust, INT64 *msc, INT64 *sbc); 662 | extern BOOL WINAPI wglWaitForSbcOML (HDC hdc, INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc); 663 | #endif /* WGL_WGLEXT_PROTOTYPES */ 664 | typedef BOOL (WINAPI * PFNWGLGETSYNCVALUESOMLPROC) (HDC hdc, INT64 *ust, INT64 *msc, INT64 *sbc); 665 | typedef BOOL (WINAPI * PFNWGLGETMSCRATEOMLPROC) (HDC hdc, INT32 *numerator, INT32 *denominator); 666 | typedef INT64 (WINAPI * PFNWGLSWAPBUFFERSMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder); 667 | typedef INT64 (WINAPI * PFNWGLSWAPLAYERBUFFERSMSCOMLPROC) (HDC hdc, int fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder); 668 | typedef BOOL (WINAPI * PFNWGLWAITFORMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64 *ust, INT64 *msc, INT64 *sbc); 669 | typedef BOOL (WINAPI * PFNWGLWAITFORSBCOMLPROC) (HDC hdc, INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc); 670 | #endif 671 | 672 | #ifndef WGL_I3D_digital_video_control 673 | #define WGL_I3D_digital_video_control 1 674 | #ifdef WGL_WGLEXT_PROTOTYPES 675 | extern BOOL WINAPI wglGetDigitalVideoParametersI3D (HDC hDC, int iAttribute, int *piValue); 676 | extern BOOL WINAPI wglSetDigitalVideoParametersI3D (HDC hDC, int iAttribute, const int *piValue); 677 | #endif /* WGL_WGLEXT_PROTOTYPES */ 678 | typedef BOOL (WINAPI * PFNWGLGETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int *piValue); 679 | typedef BOOL (WINAPI * PFNWGLSETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int *piValue); 680 | #endif 681 | 682 | #ifndef WGL_I3D_gamma 683 | #define WGL_I3D_gamma 1 684 | #ifdef WGL_WGLEXT_PROTOTYPES 685 | extern BOOL WINAPI wglGetGammaTableParametersI3D (HDC hDC, int iAttribute, int *piValue); 686 | extern BOOL WINAPI wglSetGammaTableParametersI3D (HDC hDC, int iAttribute, const int *piValue); 687 | extern BOOL WINAPI wglGetGammaTableI3D (HDC hDC, int iEntries, USHORT *puRed, USHORT *puGreen, USHORT *puBlue); 688 | extern BOOL WINAPI wglSetGammaTableI3D (HDC hDC, int iEntries, const USHORT *puRed, const USHORT *puGreen, const USHORT *puBlue); 689 | #endif /* WGL_WGLEXT_PROTOTYPES */ 690 | typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int *piValue); 691 | typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int *piValue); 692 | typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, USHORT *puRed, USHORT *puGreen, USHORT *puBlue); 693 | typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, const USHORT *puRed, const USHORT *puGreen, const USHORT *puBlue); 694 | #endif 695 | 696 | #ifndef WGL_I3D_genlock 697 | #define WGL_I3D_genlock 1 698 | #ifdef WGL_WGLEXT_PROTOTYPES 699 | extern BOOL WINAPI wglEnableGenlockI3D (HDC hDC); 700 | extern BOOL WINAPI wglDisableGenlockI3D (HDC hDC); 701 | extern BOOL WINAPI wglIsEnabledGenlockI3D (HDC hDC, BOOL *pFlag); 702 | extern BOOL WINAPI wglGenlockSourceI3D (HDC hDC, UINT uSource); 703 | extern BOOL WINAPI wglGetGenlockSourceI3D (HDC hDC, UINT *uSource); 704 | extern BOOL WINAPI wglGenlockSourceEdgeI3D (HDC hDC, UINT uEdge); 705 | extern BOOL WINAPI wglGetGenlockSourceEdgeI3D (HDC hDC, UINT *uEdge); 706 | extern BOOL WINAPI wglGenlockSampleRateI3D (HDC hDC, UINT uRate); 707 | extern BOOL WINAPI wglGetGenlockSampleRateI3D (HDC hDC, UINT *uRate); 708 | extern BOOL WINAPI wglGenlockSourceDelayI3D (HDC hDC, UINT uDelay); 709 | extern BOOL WINAPI wglGetGenlockSourceDelayI3D (HDC hDC, UINT *uDelay); 710 | extern BOOL WINAPI wglQueryGenlockMaxSourceDelayI3D (HDC hDC, UINT *uMaxLineDelay, UINT *uMaxPixelDelay); 711 | #endif /* WGL_WGLEXT_PROTOTYPES */ 712 | typedef BOOL (WINAPI * PFNWGLENABLEGENLOCKI3DPROC) (HDC hDC); 713 | typedef BOOL (WINAPI * PFNWGLDISABLEGENLOCKI3DPROC) (HDC hDC); 714 | typedef BOOL (WINAPI * PFNWGLISENABLEDGENLOCKI3DPROC) (HDC hDC, BOOL *pFlag); 715 | typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEI3DPROC) (HDC hDC, UINT uSource); 716 | typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEI3DPROC) (HDC hDC, UINT *uSource); 717 | typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT uEdge); 718 | typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT *uEdge); 719 | typedef BOOL (WINAPI * PFNWGLGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT uRate); 720 | typedef BOOL (WINAPI * PFNWGLGETGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT *uRate); 721 | typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT uDelay); 722 | typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT *uDelay); 723 | typedef BOOL (WINAPI * PFNWGLQUERYGENLOCKMAXSOURCEDELAYI3DPROC) (HDC hDC, UINT *uMaxLineDelay, UINT *uMaxPixelDelay); 724 | #endif 725 | 726 | #ifndef WGL_I3D_image_buffer 727 | #define WGL_I3D_image_buffer 1 728 | #ifdef WGL_WGLEXT_PROTOTYPES 729 | extern LPVOID WINAPI wglCreateImageBufferI3D (HDC hDC, DWORD dwSize, UINT uFlags); 730 | extern BOOL WINAPI wglDestroyImageBufferI3D (HDC hDC, LPVOID pAddress); 731 | extern BOOL WINAPI wglAssociateImageBufferEventsI3D (HDC hDC, const HANDLE *pEvent, const LPVOID *pAddress, const DWORD *pSize, UINT count); 732 | extern BOOL WINAPI wglReleaseImageBufferEventsI3D (HDC hDC, const LPVOID *pAddress, UINT count); 733 | #endif /* WGL_WGLEXT_PROTOTYPES */ 734 | typedef LPVOID (WINAPI * PFNWGLCREATEIMAGEBUFFERI3DPROC) (HDC hDC, DWORD dwSize, UINT uFlags); 735 | typedef BOOL (WINAPI * PFNWGLDESTROYIMAGEBUFFERI3DPROC) (HDC hDC, LPVOID pAddress); 736 | typedef BOOL (WINAPI * PFNWGLASSOCIATEIMAGEBUFFEREVENTSI3DPROC) (HDC hDC, const HANDLE *pEvent, const LPVOID *pAddress, const DWORD *pSize, UINT count); 737 | typedef BOOL (WINAPI * PFNWGLRELEASEIMAGEBUFFEREVENTSI3DPROC) (HDC hDC, const LPVOID *pAddress, UINT count); 738 | #endif 739 | 740 | #ifndef WGL_I3D_swap_frame_lock 741 | #define WGL_I3D_swap_frame_lock 1 742 | #ifdef WGL_WGLEXT_PROTOTYPES 743 | extern BOOL WINAPI wglEnableFrameLockI3D (void); 744 | extern BOOL WINAPI wglDisableFrameLockI3D (void); 745 | extern BOOL WINAPI wglIsEnabledFrameLockI3D (BOOL *pFlag); 746 | extern BOOL WINAPI wglQueryFrameLockMasterI3D (BOOL *pFlag); 747 | #endif /* WGL_WGLEXT_PROTOTYPES */ 748 | typedef BOOL (WINAPI * PFNWGLENABLEFRAMELOCKI3DPROC) (void); 749 | typedef BOOL (WINAPI * PFNWGLDISABLEFRAMELOCKI3DPROC) (void); 750 | typedef BOOL (WINAPI * PFNWGLISENABLEDFRAMELOCKI3DPROC) (BOOL *pFlag); 751 | typedef BOOL (WINAPI * PFNWGLQUERYFRAMELOCKMASTERI3DPROC) (BOOL *pFlag); 752 | #endif 753 | 754 | #ifndef WGL_I3D_swap_frame_usage 755 | #define WGL_I3D_swap_frame_usage 1 756 | #ifdef WGL_WGLEXT_PROTOTYPES 757 | extern BOOL WINAPI wglGetFrameUsageI3D (float *pUsage); 758 | extern BOOL WINAPI wglBeginFrameTrackingI3D (void); 759 | extern BOOL WINAPI wglEndFrameTrackingI3D (void); 760 | extern BOOL WINAPI wglQueryFrameTrackingI3D (DWORD *pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage); 761 | #endif /* WGL_WGLEXT_PROTOTYPES */ 762 | typedef BOOL (WINAPI * PFNWGLGETFRAMEUSAGEI3DPROC) (float *pUsage); 763 | typedef BOOL (WINAPI * PFNWGLBEGINFRAMETRACKINGI3DPROC) (void); 764 | typedef BOOL (WINAPI * PFNWGLENDFRAMETRACKINGI3DPROC) (void); 765 | typedef BOOL (WINAPI * PFNWGLQUERYFRAMETRACKINGI3DPROC) (DWORD *pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage); 766 | #endif 767 | 768 | #ifndef WGL_ATI_pixel_format_float 769 | #define WGL_ATI_pixel_format_float 1 770 | #endif 771 | 772 | #ifndef WGL_NV_float_buffer 773 | #define WGL_NV_float_buffer 1 774 | #endif 775 | 776 | #ifndef WGL_3DL_stereo_control 777 | #define WGL_3DL_stereo_control 1 778 | #ifdef WGL_WGLEXT_PROTOTYPES 779 | extern BOOL WINAPI wglSetStereoEmitterState3DL (HDC hDC, UINT uState); 780 | #endif /* WGL_WGLEXT_PROTOTYPES */ 781 | typedef BOOL (WINAPI * PFNWGLSETSTEREOEMITTERSTATE3DLPROC) (HDC hDC, UINT uState); 782 | #endif 783 | 784 | #ifndef WGL_EXT_pixel_format_packed_float 785 | #define WGL_EXT_pixel_format_packed_float 1 786 | #endif 787 | 788 | #ifndef WGL_EXT_framebuffer_sRGB 789 | #define WGL_EXT_framebuffer_sRGB 1 790 | #endif 791 | 792 | #ifndef WGL_NV_present_video 793 | #define WGL_NV_present_video 1 794 | #ifdef WGL_WGLEXT_PROTOTYPES 795 | extern int WINAPI wglEnumerateVideoDevicesNV (HDC hDC, HVIDEOOUTPUTDEVICENV *phDeviceList); 796 | extern BOOL WINAPI wglBindVideoDeviceNV (HDC hDC, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int *piAttribList); 797 | extern BOOL WINAPI wglQueryCurrentContextNV (int iAttribute, int *piValue); 798 | #endif /* WGL_WGLEXT_PROTOTYPES */ 799 | typedef int (WINAPI * PFNWGLENUMERATEVIDEODEVICESNVPROC) (HDC hDC, HVIDEOOUTPUTDEVICENV *phDeviceList); 800 | typedef BOOL (WINAPI * PFNWGLBINDVIDEODEVICENVPROC) (HDC hDC, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int *piAttribList); 801 | typedef BOOL (WINAPI * PFNWGLQUERYCURRENTCONTEXTNVPROC) (int iAttribute, int *piValue); 802 | #endif 803 | 804 | #ifndef WGL_NV_video_output 805 | #define WGL_NV_video_output 1 806 | #ifdef WGL_WGLEXT_PROTOTYPES 807 | extern BOOL WINAPI wglGetVideoDeviceNV (HDC hDC, int numDevices, HPVIDEODEV *hVideoDevice); 808 | extern BOOL WINAPI wglReleaseVideoDeviceNV (HPVIDEODEV hVideoDevice); 809 | extern BOOL WINAPI wglBindVideoImageNV (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer); 810 | extern BOOL WINAPI wglReleaseVideoImageNV (HPBUFFERARB hPbuffer, int iVideoBuffer); 811 | extern BOOL WINAPI wglSendPbufferToVideoNV (HPBUFFERARB hPbuffer, int iBufferType, unsigned long *pulCounterPbuffer, BOOL bBlock); 812 | extern BOOL WINAPI wglGetVideoInfoNV (HPVIDEODEV hpVideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); 813 | #endif /* WGL_WGLEXT_PROTOTYPES */ 814 | typedef BOOL (WINAPI * PFNWGLGETVIDEODEVICENVPROC) (HDC hDC, int numDevices, HPVIDEODEV *hVideoDevice); 815 | typedef BOOL (WINAPI * PFNWGLRELEASEVIDEODEVICENVPROC) (HPVIDEODEV hVideoDevice); 816 | typedef BOOL (WINAPI * PFNWGLBINDVIDEOIMAGENVPROC) (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer); 817 | typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOIMAGENVPROC) (HPBUFFERARB hPbuffer, int iVideoBuffer); 818 | typedef BOOL (WINAPI * PFNWGLSENDPBUFFERTOVIDEONVPROC) (HPBUFFERARB hPbuffer, int iBufferType, unsigned long *pulCounterPbuffer, BOOL bBlock); 819 | typedef BOOL (WINAPI * PFNWGLGETVIDEOINFONVPROC) (HPVIDEODEV hpVideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); 820 | #endif 821 | 822 | #ifndef WGL_NV_swap_group 823 | #define WGL_NV_swap_group 1 824 | #ifdef WGL_WGLEXT_PROTOTYPES 825 | extern BOOL WINAPI wglJoinSwapGroupNV (HDC hDC, GLuint group); 826 | extern BOOL WINAPI wglBindSwapBarrierNV (GLuint group, GLuint barrier); 827 | extern BOOL WINAPI wglQuerySwapGroupNV (HDC hDC, GLuint *group, GLuint *barrier); 828 | extern BOOL WINAPI wglQueryMaxSwapGroupsNV (HDC hDC, GLuint *maxGroups, GLuint *maxBarriers); 829 | extern BOOL WINAPI wglQueryFrameCountNV (HDC hDC, GLuint *count); 830 | extern BOOL WINAPI wglResetFrameCountNV (HDC hDC); 831 | #endif /* WGL_WGLEXT_PROTOTYPES */ 832 | typedef BOOL (WINAPI * PFNWGLJOINSWAPGROUPNVPROC) (HDC hDC, GLuint group); 833 | typedef BOOL (WINAPI * PFNWGLBINDSWAPBARRIERNVPROC) (GLuint group, GLuint barrier); 834 | typedef BOOL (WINAPI * PFNWGLQUERYSWAPGROUPNVPROC) (HDC hDC, GLuint *group, GLuint *barrier); 835 | typedef BOOL (WINAPI * PFNWGLQUERYMAXSWAPGROUPSNVPROC) (HDC hDC, GLuint *maxGroups, GLuint *maxBarriers); 836 | typedef BOOL (WINAPI * PFNWGLQUERYFRAMECOUNTNVPROC) (HDC hDC, GLuint *count); 837 | typedef BOOL (WINAPI * PFNWGLRESETFRAMECOUNTNVPROC) (HDC hDC); 838 | #endif 839 | 840 | #ifndef WGL_NV_gpu_affinity 841 | #define WGL_NV_gpu_affinity 1 842 | #ifdef WGL_WGLEXT_PROTOTYPES 843 | extern BOOL WINAPI wglEnumGpusNV (UINT iGpuIndex, HGPUNV *phGpu); 844 | extern BOOL WINAPI wglEnumGpuDevicesNV (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice); 845 | extern HDC WINAPI wglCreateAffinityDCNV (const HGPUNV *phGpuList); 846 | extern BOOL WINAPI wglEnumGpusFromAffinityDCNV (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu); 847 | extern BOOL WINAPI wglDeleteDCNV (HDC hdc); 848 | #endif /* WGL_WGLEXT_PROTOTYPES */ 849 | typedef BOOL (WINAPI * PFNWGLENUMGPUSNVPROC) (UINT iGpuIndex, HGPUNV *phGpu); 850 | typedef BOOL (WINAPI * PFNWGLENUMGPUDEVICESNVPROC) (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice); 851 | typedef HDC (WINAPI * PFNWGLCREATEAFFINITYDCNVPROC) (const HGPUNV *phGpuList); 852 | typedef BOOL (WINAPI * PFNWGLENUMGPUSFROMAFFINITYDCNVPROC) (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu); 853 | typedef BOOL (WINAPI * PFNWGLDELETEDCNVPROC) (HDC hdc); 854 | #endif 855 | 856 | #ifndef WGL_AMD_gpu_association 857 | #define WGL_AMD_gpu_association 1 858 | #ifdef WGL_WGLEXT_PROTOTYPES 859 | extern UINT WINAPI wglGetGPUIDsAMD (UINT maxCount, UINT *ids); 860 | extern INT WINAPI wglGetGPUInfoAMD (UINT id, int property, GLenum dataType, UINT size, void *data); 861 | extern UINT WINAPI wglGetContextGPUIDAMD (HGLRC hglrc); 862 | extern HGLRC WINAPI wglCreateAssociatedContextAMD (UINT id); 863 | extern HGLRC WINAPI wglCreateAssociatedContextAttribsAMD (UINT id, HGLRC hShareContext, const int *attribList); 864 | extern BOOL WINAPI wglDeleteAssociatedContextAMD (HGLRC hglrc); 865 | extern BOOL WINAPI wglMakeAssociatedContextCurrentAMD (HGLRC hglrc); 866 | extern HGLRC WINAPI wglGetCurrentAssociatedContextAMD (void); 867 | extern VOID WINAPI wglBlitContextFramebufferAMD (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); 868 | #endif /* WGL_WGLEXT_PROTOTYPES */ 869 | typedef UINT (WINAPI * PFNWGLGETGPUIDSAMDPROC) (UINT maxCount, UINT *ids); 870 | typedef INT (WINAPI * PFNWGLGETGPUINFOAMDPROC) (UINT id, int property, GLenum dataType, UINT size, void *data); 871 | typedef UINT (WINAPI * PFNWGLGETCONTEXTGPUIDAMDPROC) (HGLRC hglrc); 872 | typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTAMDPROC) (UINT id); 873 | typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTATTRIBSAMDPROC) (UINT id, HGLRC hShareContext, const int *attribList); 874 | typedef BOOL (WINAPI * PFNWGLDELETEASSOCIATEDCONTEXTAMDPROC) (HGLRC hglrc); 875 | typedef BOOL (WINAPI * PFNWGLMAKEASSOCIATEDCONTEXTCURRENTAMDPROC) (HGLRC hglrc); 876 | typedef HGLRC (WINAPI * PFNWGLGETCURRENTASSOCIATEDCONTEXTAMDPROC) (void); 877 | typedef VOID (WINAPI * PFNWGLBLITCONTEXTFRAMEBUFFERAMDPROC) (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); 878 | #endif 879 | 880 | #ifndef WGL_NV_video_capture 881 | #define WGL_NV_video_capture 1 882 | #ifdef WGL_WGLEXT_PROTOTYPES 883 | extern BOOL WINAPI wglBindVideoCaptureDeviceNV (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice); 884 | extern UINT WINAPI wglEnumerateVideoCaptureDevicesNV (HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList); 885 | extern BOOL WINAPI wglLockVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice); 886 | extern BOOL WINAPI wglQueryVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int *piValue); 887 | extern BOOL WINAPI wglReleaseVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice); 888 | #endif /* WGL_WGLEXT_PROTOTYPES */ 889 | typedef BOOL (WINAPI * PFNWGLBINDVIDEOCAPTUREDEVICENVPROC) (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice); 890 | typedef UINT (WINAPI * PFNWGLENUMERATEVIDEOCAPTUREDEVICESNVPROC) (HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList); 891 | typedef BOOL (WINAPI * PFNWGLLOCKVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice); 892 | typedef BOOL (WINAPI * PFNWGLQUERYVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int *piValue); 893 | typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice); 894 | #endif 895 | 896 | #ifndef WGL_NV_copy_image 897 | #define WGL_NV_copy_image 1 898 | #ifdef WGL_WGLEXT_PROTOTYPES 899 | extern BOOL WINAPI wglCopyImageSubDataNV (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); 900 | #endif /* WGL_WGLEXT_PROTOTYPES */ 901 | typedef BOOL (WINAPI * PFNWGLCOPYIMAGESUBDATANVPROC) (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); 902 | #endif 903 | 904 | #ifndef WGL_NV_multisample_coverage 905 | #define WGL_NV_multisample_coverage 1 906 | #endif 907 | 908 | #ifndef WGL_NV_DX_interop 909 | #define WGL_NV_DX_interop 1 910 | #ifdef WGL_WGLEXT_PROTOTYPES 911 | extern BOOL WINAPI wglDXSetResourceShareHandleNV (void *dxObject, HANDLE shareHandle); 912 | extern HANDLE WINAPI wglDXOpenDeviceNV (void *dxDevice); 913 | extern BOOL WINAPI wglDXCloseDeviceNV (HANDLE hDevice); 914 | extern HANDLE WINAPI wglDXRegisterObjectNV (HANDLE hDevice, void *dxObject, GLuint name, GLenum type, GLenum access); 915 | extern BOOL WINAPI wglDXUnregisterObjectNV (HANDLE hDevice, HANDLE hObject); 916 | extern BOOL WINAPI wglDXObjectAccessNV (HANDLE hObject, GLenum access); 917 | extern BOOL WINAPI wglDXLockObjectsNV (HANDLE hDevice, GLint count, HANDLE *hObjects); 918 | extern BOOL WINAPI wglDXUnlockObjectsNV (HANDLE hDevice, GLint count, HANDLE *hObjects); 919 | #endif /* WGL_WGLEXT_PROTOTYPES */ 920 | typedef BOOL (WINAPI * PFNWGLDXSETRESOURCESHAREHANDLENVPROC) (void *dxObject, HANDLE shareHandle); 921 | typedef HANDLE (WINAPI * PFNWGLDXOPENDEVICENVPROC) (void *dxDevice); 922 | typedef BOOL (WINAPI * PFNWGLDXCLOSEDEVICENVPROC) (HANDLE hDevice); 923 | typedef HANDLE (WINAPI * PFNWGLDXREGISTEROBJECTNVPROC) (HANDLE hDevice, void *dxObject, GLuint name, GLenum type, GLenum access); 924 | typedef BOOL (WINAPI * PFNWGLDXUNREGISTEROBJECTNVPROC) (HANDLE hDevice, HANDLE hObject); 925 | typedef BOOL (WINAPI * PFNWGLDXOBJECTACCESSNVPROC) (HANDLE hObject, GLenum access); 926 | typedef BOOL (WINAPI * PFNWGLDXLOCKOBJECTSNVPROC) (HANDLE hDevice, GLint count, HANDLE *hObjects); 927 | typedef BOOL (WINAPI * PFNWGLDXUNLOCKOBJECTSNVPROC) (HANDLE hDevice, GLint count, HANDLE *hObjects); 928 | #endif 929 | 930 | #ifndef WGL_NV_DX_interop2 931 | #define WGL_NV_DX_interop2 1 932 | #endif 933 | 934 | #ifndef WGL_EXT_swap_control_tear 935 | #define WGL_EXT_swap_control_tear 1 936 | #endif 937 | 938 | 939 | #ifdef __cplusplus 940 | } 941 | #endif 942 | 943 | #endif 944 | -------------------------------------------------------------------------------- /for_glfw/Makefile.cocoa: -------------------------------------------------------------------------------- 1 | 2 | GLFW_HEADER = ./ 3 | GLFW_LIB = ./libglfw.a 4 | all: 5 | mkdir -p uitest.app/Contents/MacOS/; 6 | g++ -I$(GLFW_HEADER) -framework Cocoa -framework OpenGL -framework IOKit $(GLFW_LIB) uitest.cpp -o uitest.app/Contents/MacOS/uitest 7 | -------------------------------------------------------------------------------- /for_glfw/README: -------------------------------------------------------------------------------- 1 | 2 | Step1. Please locate GLFW file 3 | ./GL/glfw.h 4 | ./libglfw.a 5 | 6 | Step2. Let's make command. 7 | ex. make -f Makefile.cocoa 8 | 9 | Enjoy SimpleUI 10 | 11 | 12 | -------------------------------------------------------------------------------- /for_glfw/uitest.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // GLFW + SimpleUI Test 3 | // 4 | // 2014.04.16 coded by kioku 5 | // 6 | // GLFW - http://www.glfw.org/ 7 | // SimpleUI - https://github.com/kioku-systemk/SimpleUI 8 | // 9 | // base code is accuracy.c / GLFW 10 | // 11 | // 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | #include "../UI/SimpleGUI.h" 19 | 20 | // UI 21 | static SimpleGUI::GUIManager* m_gui = 0; 22 | static SimpleGUI::Slider* m_slider[3]; 23 | static float m_col[3]; 24 | static void changeRedSlider (float v, void* thisptr){ m_col[0] = v; } 25 | static void changeGreenSlider(float v, void* thisptr){ m_col[1] = v; } 26 | static void changeBlueSlider (float v, void* thisptr){ m_col[2] = v; } 27 | static void clickBlack(void* thisptr) { 28 | m_slider[0]->SetValue(0.0f); 29 | m_slider[1]->SetValue(0.0f); 30 | m_slider[2]->SetValue(0.0f); 31 | } 32 | static void clickWhite(void* thisptr) { 33 | m_slider[0]->SetValue(1.0f); 34 | m_slider[1]->SetValue(1.0f); 35 | m_slider[2]->SetValue(1.0f); 36 | } 37 | 38 | static int cursor_x = 0, cursor_y = 0; 39 | static int window_width = 640, window_height = 480; 40 | 41 | static void GLFWCALL window_size_callback(int width, int height) 42 | { 43 | window_width = width; 44 | window_height = height; 45 | 46 | glViewport(0, 0, window_width, window_height); 47 | 48 | glMatrixMode(GL_PROJECTION); 49 | glLoadIdentity(); 50 | gluOrtho2D(0.f, window_width, 0.f, window_height); 51 | 52 | if (m_gui) 53 | m_gui->Resize(width,height); 54 | } 55 | 56 | static void GLFWCALL mouse_pos_callback(int x, int y) 57 | { 58 | cursor_x = x; 59 | cursor_y = y; 60 | if (m_gui) 61 | m_gui->MouseMove(cursor_x, cursor_y); 62 | } 63 | 64 | static void GLFWCALL mouse_button_callback(int btn, int act) 65 | { 66 | if (!m_gui) 67 | return; 68 | 69 | if (act == GLFW_PRESS) 70 | m_gui->MouseDown(btn, cursor_x, cursor_y); 71 | else if(act == GLFW_RELEASE) 72 | m_gui->MouseUp(btn, cursor_x, cursor_y); 73 | } 74 | 75 | 76 | void Render() 77 | { 78 | glClearColor(m_col[0],m_col[1],m_col[2],0); 79 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 80 | 81 | glColor3f(1.f, 1.f, 1.f); 82 | glBegin(GL_LINES); 83 | glVertex2f(0.f, (GLfloat) window_height - cursor_y); 84 | glVertex2f((GLfloat) window_width, (GLfloat) window_height - cursor_y); 85 | glVertex2f((GLfloat) cursor_x, 0.f); 86 | glVertex2f((GLfloat) cursor_x, (GLfloat) window_height); 87 | glEnd(); 88 | 89 | glClear(GL_DEPTH_BUFFER_BIT); 90 | m_gui->Draw(); 91 | 92 | glfwSwapBuffers(); 93 | } 94 | 95 | void CreateUI(int width, int height) 96 | { 97 | m_col[0] = 0.5; 98 | m_col[1] = 0.5; 99 | m_col[2] = 0.5; 100 | 101 | m_gui = new SimpleGUI::GUIManager(); 102 | m_gui->Resize(width, height); 103 | 104 | SimpleGUI::Dialog* diag = new SimpleGUI::Dialog(m_gui, 50,50,150,130); 105 | m_gui->GetRoot()->AddChild(diag); 106 | 107 | 108 | SimpleGUI::Caption* txt = new SimpleGUI::Caption(m_gui,2,2, "Dialog", SimpleGUI::UITextSize); 109 | diag->AddChild(txt); 110 | 111 | 112 | SimpleGUI::Caption* txt1 = new SimpleGUI::Caption(m_gui,5,30, "Red", SimpleGUI::UITextSize); 113 | diag->AddChild(txt1); 114 | SimpleGUI::Caption* txt2 = new SimpleGUI::Caption(m_gui,5,50, "Green", SimpleGUI::UITextSize); 115 | diag->AddChild(txt2); 116 | SimpleGUI::Caption* txt3 = new SimpleGUI::Caption(m_gui,5,70, "Blue", SimpleGUI::UITextSize); 117 | diag->AddChild(txt3); 118 | 119 | m_slider[0] = new SimpleGUI::Slider(m_gui,45,32, 100,20,1); 120 | m_slider[0]->SetValue(m_col[0]); 121 | m_slider[0]->SetChangedFunc(changeRedSlider,0); 122 | diag->AddChild(m_slider[0]); 123 | m_slider[1] = new SimpleGUI::Slider(m_gui,45,52, 100,20,1); 124 | m_slider[1]->SetValue(m_col[1]); 125 | m_slider[1]->SetChangedFunc(changeGreenSlider,0); 126 | diag->AddChild(m_slider[1]); 127 | m_slider[2] = new SimpleGUI::Slider(m_gui,45,72, 100,20,1); 128 | m_slider[2]->SetValue(m_col[2]); 129 | m_slider[2]->SetChangedFunc(changeBlueSlider,0); 130 | diag->AddChild(m_slider[2]); 131 | 132 | SimpleGUI::Button* btn = new SimpleGUI::Button(m_gui, "Black", 20,100,50,18); 133 | btn->SetClickedFunc(clickBlack, 0); 134 | diag->AddChild(btn); 135 | SimpleGUI::Button* btn2 = new SimpleGUI::Button(m_gui, "White", 80,100,50,18); 136 | btn2->SetClickedFunc(clickWhite, 0); 137 | diag->AddChild(btn2); 138 | } 139 | 140 | int main(void) 141 | { 142 | if (!glfwInit()) 143 | { 144 | fprintf(stderr, "Failed to initialize GLFW\n"); 145 | exit(EXIT_FAILURE); 146 | } 147 | 148 | if (!glfwOpenWindow(window_width, window_height, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) 149 | { 150 | glfwTerminate(); 151 | 152 | fprintf(stderr, "Failed to open GLFW window\n"); 153 | exit(EXIT_FAILURE); 154 | } 155 | 156 | CreateUI(window_width, window_height); 157 | 158 | glfwSetWindowTitle("GLFW + SimpleUI"); 159 | glfwSetMousePosCallback(mouse_pos_callback); 160 | glfwSetMouseButtonCallback(mouse_button_callback); 161 | glfwSetWindowSizeCallback(window_size_callback); 162 | glfwSwapInterval(1); 163 | 164 | while (glfwGetWindowParam(GLFW_OPENED)) 165 | { 166 | Render(); 167 | } 168 | 169 | glfwTerminate(); 170 | exit(EXIT_SUCCESS); 171 | } 172 | 173 | -------------------------------------------------------------------------------- /screenshots/screenshot_linux.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kioku-systemk/SimpleUI/ef04d2269ff9590a050185d84c60ea7c851b7de5/screenshots/screenshot_linux.png -------------------------------------------------------------------------------- /screenshots/screenshot_mac.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kioku-systemk/SimpleUI/ef04d2269ff9590a050185d84c60ea7c851b7de5/screenshots/screenshot_mac.png -------------------------------------------------------------------------------- /screenshots/screenshot_win.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kioku-systemk/SimpleUI/ef04d2269ff9590a050185d84c60ea7c851b7de5/screenshots/screenshot_win.png -------------------------------------------------------------------------------- /test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // test.cpp 3 | // SimpleUI Test 4 | // 5 | // Created by kioku on 12/09/14. 6 | // Copyright (c) 2012 System K. All rights reserved. 7 | // 8 | 9 | // Cross Platform Window header 10 | #include "Core/CoreWindow.h" 11 | 12 | // Simple GUI header 13 | #include "UI/SimpleGUI.h" 14 | 15 | // GL Headers 16 | 17 | #if defined(__EMSCRIPTEN__) 18 | #include 19 | 20 | #elif defined(__APPLE__) 21 | #include 22 | #else 23 | #include 24 | #endif 25 | 26 | #include 27 | 28 | class MainWindow : public CoreWindow 29 | { 30 | public: 31 | MainWindow(int x, int y, int width, int height) 32 | : CoreWindow(x, y, width, height, "Simple UI Test") 33 | { 34 | m_col[0] = 0.5; 35 | m_col[1] = 0.5; 36 | m_col[2] = 0.5; 37 | 38 | m_gui = new SimpleGUI::GUIManager(); 39 | m_gui->Resize(width, height); 40 | 41 | SimpleGUI::Dialog* diag = new SimpleGUI::Dialog(m_gui, 50,50,150,130); 42 | m_gui->GetRoot()->AddChild(diag); 43 | 44 | m_diag = diag; 45 | SimpleGUI::Caption* txt = new SimpleGUI::Caption(m_gui,2,2, "Dialog", SimpleGUI::UITextSize); 46 | diag->AddChild(txt); 47 | 48 | 49 | SimpleGUI::Caption* txt1 = new SimpleGUI::Caption(m_gui,5,30, "Red", SimpleGUI::UITextSize); 50 | diag->AddChild(txt1); 51 | SimpleGUI::Caption* txt2 = new SimpleGUI::Caption(m_gui,5,50, "Green", SimpleGUI::UITextSize); 52 | diag->AddChild(txt2); 53 | SimpleGUI::Caption* txt3 = new SimpleGUI::Caption(m_gui,5,70, "Blue", SimpleGUI::UITextSize); 54 | diag->AddChild(txt3); 55 | 56 | m_slider[0] = new SimpleGUI::Slider(m_gui,45,32, 100,20,1); 57 | m_slider[0]->SetValue(m_col[0]); 58 | m_slider[0]->SetChangedFunc(changeRedSlider,this); 59 | diag->AddChild(m_slider[0]); 60 | m_slider[1] = new SimpleGUI::Slider(m_gui,45,52, 100,20,1); 61 | m_slider[1]->SetValue(m_col[1]); 62 | m_slider[1]->SetChangedFunc(changeGreenSlider,this); 63 | diag->AddChild(m_slider[1]); 64 | m_slider[2] = new SimpleGUI::Slider(m_gui,45,72, 100,20,1); 65 | m_slider[2]->SetValue(m_col[2]); 66 | m_slider[2]->SetChangedFunc(changeBlueSlider,this); 67 | diag->AddChild(m_slider[2]); 68 | 69 | SimpleGUI::Button* btn = new SimpleGUI::Button(m_gui, "Black", 20,100,50,18); 70 | btn->SetClickedFunc(clickBlack, this); 71 | diag->AddChild(btn); 72 | SimpleGUI::Button* btn2 = new SimpleGUI::Button(m_gui, "White", 80,100,50,18); 73 | btn2->SetClickedFunc(clickWhite, this); 74 | diag->AddChild(btn2); 75 | 76 | SimpleGUI::Check* chk = new SimpleGUI::Check(m_gui, "Alpha", 80,2); 77 | chk->SetChangedFunc(changeAlphaCheck, this); 78 | diag->AddChild(chk); 79 | 80 | } 81 | ~MainWindow() 82 | { 83 | } 84 | 85 | static void changeRedSlider(float v, void* thisptr){ 86 | static_cast(thisptr)->changeRedSlider(v); 87 | } 88 | static void changeGreenSlider(float v, void* thisptr){ 89 | static_cast(thisptr)->changeGreenSlider(v); 90 | } 91 | static void changeBlueSlider(float v, void* thisptr){ 92 | static_cast(thisptr)->changeBlueSlider(v); 93 | } 94 | static void clickBlack(void* thisptr){ 95 | static_cast(thisptr)->clickBlack(); 96 | } 97 | static void clickWhite(void* thisptr){ 98 | static_cast(thisptr)->clickWhite(); 99 | } 100 | static void changeAlphaCheck(bool state, void* thisptr){ 101 | static_cast(thisptr)->changeAlphaCheck(state); 102 | } 103 | 104 | void changeRedSlider (float v){ m_col[0] = v; } 105 | void changeGreenSlider(float v){ m_col[1] = v; } 106 | void changeBlueSlider (float v){ m_col[2] = v; } 107 | void clickBlack() { 108 | m_slider[0]->SetValue(0.0f); 109 | m_slider[1]->SetValue(0.0f); 110 | m_slider[2]->SetValue(0.0f); 111 | } 112 | void clickWhite() { 113 | m_slider[0]->SetValue(1.0f); 114 | m_slider[1]->SetValue(1.0f); 115 | m_slider[2]->SetValue(1.0f); 116 | } 117 | void changeAlphaCheck(bool state) { 118 | if (state) 119 | m_diag->SetAlpha(0.5); 120 | else 121 | m_diag->SetAlpha(1.0); 122 | } 123 | 124 | void MouseLeftDown(int x, int y) 125 | { 126 | m_gui->MouseDown(0,x,y); 127 | } 128 | void MouseLeftUp(int x, int y) 129 | { 130 | m_gui->MouseUp(0,x,y); 131 | } 132 | void MouseMove(int x, int y) 133 | { 134 | m_gui->MouseMove(x,y); 135 | } 136 | 137 | void Draw() 138 | { 139 | glClearColor(m_col[0],m_col[1],m_col[2],0); 140 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 141 | 142 | // own graphics code. 143 | 144 | glClear(GL_DEPTH_BUFFER_BIT); 145 | m_gui->Draw(); 146 | 147 | SwapBuffer(); 148 | } 149 | 150 | void Resize(int w, int h) 151 | { 152 | glViewport(0, 0, w, h); 153 | m_gui->Resize(w,h); 154 | Draw(); 155 | } 156 | void Idle() 157 | { 158 | Draw(); 159 | } 160 | 161 | private: 162 | SimpleGUI::GUIManager* m_gui; 163 | SimpleGUI::Slider* m_slider[3]; 164 | SimpleGUI::Dialog* m_diag; 165 | int m_mode; 166 | float m_col[3]; 167 | }; 168 | 169 | int main(int argc, char *argv[]) 170 | { 171 | MainWindow win(32, 32, 720, 480); 172 | CoreWindow::MainLoop(); 173 | return 0; 174 | } 175 | -------------------------------------------------------------------------------- /vcproj/CoreWindowTest.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual C++ Express 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CoreWindowTest", "CoreWindowTest.vcxproj", "{9A35F694-6B16-47B3-B4C5-78068501B1F4}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {9A35F694-6B16-47B3-B4C5-78068501B1F4}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {9A35F694-6B16-47B3-B4C5-78068501B1F4}.Debug|Win32.Build.0 = Debug|Win32 14 | {9A35F694-6B16-47B3-B4C5-78068501B1F4}.Release|Win32.ActiveCfg = Release|Win32 15 | {9A35F694-6B16-47B3-B4C5-78068501B1F4}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /vcproj/CoreWindowTest.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {9A35F694-6B16-47B3-B4C5-78068501B1F4} 15 | Win32Proj 16 | CoreWindowTest 17 | 18 | 19 | 20 | Application 21 | true 22 | MultiByte 23 | 24 | 25 | Application 26 | false 27 | true 28 | MultiByte 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | true 42 | 43 | 44 | false 45 | 46 | 47 | 48 | 49 | 50 | Level3 51 | Disabled 52 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 53 | 54 | 55 | Console 56 | true 57 | opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 58 | 59 | 60 | 61 | 62 | Level3 63 | 64 | 65 | MaxSpeed 66 | true 67 | true 68 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 69 | 70 | 71 | Console 72 | true 73 | true 74 | true 75 | opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /vcproj/CoreWindowTest.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | ソース ファイル 20 | 21 | 22 | ソース ファイル 23 | 24 | 25 | ソース ファイル 26 | 27 | 28 | 29 | 30 | ヘッダー ファイル 31 | 32 | 33 | ヘッダー ファイル 34 | 35 | 36 | ヘッダー ファイル 37 | 38 | 39 | -------------------------------------------------------------------------------- /xcode/SimpleUI-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | net.sys-k.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSHumanReadableCopyright 28 | Copyright © 2012年 kioku. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /xcode/SimpleUI-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'SimpleUI' target in the 'SimpleUI' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /xcode/SimpleUI.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 7751800B160240BA00A89B24 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7751800A160240BA00A89B24 /* Cocoa.framework */; }; 11 | 7751802D1602414D00A89B24 /* test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7751802C1602414D00A89B24 /* test.cpp */; }; 12 | 775180341602415500A89B24 /* CoreWindow_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 775180311602415500A89B24 /* CoreWindow_mac.mm */; }; 13 | 775180371602417100A89B24 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 775180361602417100A89B24 /* OpenGL.framework */; }; 14 | /* End PBXBuildFile section */ 15 | 16 | /* Begin PBXFileReference section */ 17 | 77518006160240BA00A89B24 /* SimpleUI.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SimpleUI.app; sourceTree = BUILT_PRODUCTS_DIR; }; 18 | 7751800A160240BA00A89B24 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 19 | 7751800D160240BA00A89B24 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; 20 | 7751800E160240BA00A89B24 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; 21 | 7751800F160240BA00A89B24 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 22 | 77518012160240BA00A89B24 /* SimpleUI-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "SimpleUI-Info.plist"; sourceTree = ""; }; 23 | 77518018160240BA00A89B24 /* SimpleUI-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SimpleUI-Prefix.pch"; sourceTree = ""; }; 24 | 7751802C1602414D00A89B24 /* test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = test.cpp; path = ../test.cpp; sourceTree = ""; }; 25 | 7751802F1602415500A89B24 /* CoreWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoreWindow.h; sourceTree = ""; }; 26 | 775180301602415500A89B24 /* CoreWindow_mac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoreWindow_mac.h; sourceTree = ""; }; 27 | 775180311602415500A89B24 /* CoreWindow_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CoreWindow_mac.mm; sourceTree = ""; }; 28 | 775180361602417100A89B24 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; }; 29 | 77C4CE061613D2B200AE3AB7 /* icons.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = icons.h; sourceTree = ""; }; 30 | 77C4CE071613D2B200AE3AB7 /* mplus1cmedium.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mplus1cmedium.h; sourceTree = ""; }; 31 | 77C4CE091613D2B200AE3AB7 /* SimpleGraphics_impl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SimpleGraphics_impl.h; sourceTree = ""; }; 32 | 77C4CE0A1613D2B200AE3AB7 /* SimpleGraphics.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SimpleGraphics.h; sourceTree = ""; }; 33 | 77C4CE0B1613D2B200AE3AB7 /* SimpleGUI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SimpleGUI.h; sourceTree = ""; }; 34 | 77C4CE0C1613D2B200AE3AB7 /* SimpleShader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SimpleShader.h; sourceTree = ""; }; 35 | 77C4CE0D1613D2B200AE3AB7 /* SimpleTex.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SimpleTex.h; sourceTree = ""; }; 36 | 77C4CE0E1613D2B200AE3AB7 /* SimpleVB.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SimpleVB.h; sourceTree = ""; }; 37 | 77C4CE0F1613D2B200AE3AB7 /* skBaseGUI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = skBaseGUI.h; sourceTree = ""; }; 38 | 77C4CE101613D2B200AE3AB7 /* stb_truetype.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stb_truetype.h; sourceTree = ""; }; 39 | /* End PBXFileReference section */ 40 | 41 | /* Begin PBXFrameworksBuildPhase section */ 42 | 77518003160240BA00A89B24 /* Frameworks */ = { 43 | isa = PBXFrameworksBuildPhase; 44 | buildActionMask = 2147483647; 45 | files = ( 46 | 775180371602417100A89B24 /* OpenGL.framework in Frameworks */, 47 | 7751800B160240BA00A89B24 /* Cocoa.framework in Frameworks */, 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | /* End PBXFrameworksBuildPhase section */ 52 | 53 | /* Begin PBXGroup section */ 54 | 77517FFB160240BA00A89B24 = { 55 | isa = PBXGroup; 56 | children = ( 57 | 7751802C1602414D00A89B24 /* test.cpp */, 58 | 775180381602430700A89B24 /* UI */, 59 | 7751802E1602415500A89B24 /* Core */, 60 | 77518010160240BA00A89B24 /* SimpleUI */, 61 | 77518009160240BA00A89B24 /* Frameworks */, 62 | 77518007160240BA00A89B24 /* Products */, 63 | ); 64 | sourceTree = ""; 65 | }; 66 | 77518007160240BA00A89B24 /* Products */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 77518006160240BA00A89B24 /* SimpleUI.app */, 70 | ); 71 | name = Products; 72 | sourceTree = ""; 73 | }; 74 | 77518009160240BA00A89B24 /* Frameworks */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 775180361602417100A89B24 /* OpenGL.framework */, 78 | 7751800A160240BA00A89B24 /* Cocoa.framework */, 79 | 7751800C160240BA00A89B24 /* Other Frameworks */, 80 | ); 81 | name = Frameworks; 82 | sourceTree = ""; 83 | }; 84 | 7751800C160240BA00A89B24 /* Other Frameworks */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 7751800D160240BA00A89B24 /* AppKit.framework */, 88 | 7751800E160240BA00A89B24 /* CoreData.framework */, 89 | 7751800F160240BA00A89B24 /* Foundation.framework */, 90 | ); 91 | name = "Other Frameworks"; 92 | sourceTree = ""; 93 | }; 94 | 77518010160240BA00A89B24 /* SimpleUI */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 77518011160240BA00A89B24 /* Supporting Files */, 98 | ); 99 | path = SimpleUI; 100 | sourceTree = ""; 101 | }; 102 | 77518011160240BA00A89B24 /* Supporting Files */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | 77518012160240BA00A89B24 /* SimpleUI-Info.plist */, 106 | 77518018160240BA00A89B24 /* SimpleUI-Prefix.pch */, 107 | ); 108 | name = "Supporting Files"; 109 | sourceTree = ""; 110 | }; 111 | 7751802E1602415500A89B24 /* Core */ = { 112 | isa = PBXGroup; 113 | children = ( 114 | 7751802F1602415500A89B24 /* CoreWindow.h */, 115 | 775180301602415500A89B24 /* CoreWindow_mac.h */, 116 | 775180311602415500A89B24 /* CoreWindow_mac.mm */, 117 | ); 118 | name = Core; 119 | path = ../Core; 120 | sourceTree = ""; 121 | }; 122 | 775180381602430700A89B24 /* UI */ = { 123 | isa = PBXGroup; 124 | children = ( 125 | 77C4CE061613D2B200AE3AB7 /* icons.h */, 126 | 77C4CE071613D2B200AE3AB7 /* mplus1cmedium.h */, 127 | 77C4CE091613D2B200AE3AB7 /* SimpleGraphics_impl.h */, 128 | 77C4CE0A1613D2B200AE3AB7 /* SimpleGraphics.h */, 129 | 77C4CE0B1613D2B200AE3AB7 /* SimpleGUI.h */, 130 | 77C4CE0C1613D2B200AE3AB7 /* SimpleShader.h */, 131 | 77C4CE0D1613D2B200AE3AB7 /* SimpleTex.h */, 132 | 77C4CE0E1613D2B200AE3AB7 /* SimpleVB.h */, 133 | 77C4CE0F1613D2B200AE3AB7 /* skBaseGUI.h */, 134 | 77C4CE101613D2B200AE3AB7 /* stb_truetype.h */, 135 | ); 136 | name = UI; 137 | path = ../UI; 138 | sourceTree = ""; 139 | }; 140 | /* End PBXGroup section */ 141 | 142 | /* Begin PBXNativeTarget section */ 143 | 77518005160240BA00A89B24 /* SimpleUI */ = { 144 | isa = PBXNativeTarget; 145 | buildConfigurationList = 77518024160240BA00A89B24 /* Build configuration list for PBXNativeTarget "SimpleUI" */; 146 | buildPhases = ( 147 | 77518002160240BA00A89B24 /* Sources */, 148 | 77518003160240BA00A89B24 /* Frameworks */, 149 | 77518004160240BA00A89B24 /* Resources */, 150 | ); 151 | buildRules = ( 152 | ); 153 | dependencies = ( 154 | ); 155 | name = SimpleUI; 156 | productName = SimpleUI; 157 | productReference = 77518006160240BA00A89B24 /* SimpleUI.app */; 158 | productType = "com.apple.product-type.application"; 159 | }; 160 | /* End PBXNativeTarget section */ 161 | 162 | /* Begin PBXProject section */ 163 | 77517FFD160240BA00A89B24 /* Project object */ = { 164 | isa = PBXProject; 165 | attributes = { 166 | LastUpgradeCheck = 0440; 167 | ORGANIZATIONNAME = kioku; 168 | }; 169 | buildConfigurationList = 77518000160240BA00A89B24 /* Build configuration list for PBXProject "SimpleUI" */; 170 | compatibilityVersion = "Xcode 3.2"; 171 | developmentRegion = English; 172 | hasScannedForEncodings = 0; 173 | knownRegions = ( 174 | en, 175 | ); 176 | mainGroup = 77517FFB160240BA00A89B24; 177 | productRefGroup = 77518007160240BA00A89B24 /* Products */; 178 | projectDirPath = ""; 179 | projectRoot = ""; 180 | targets = ( 181 | 77518005160240BA00A89B24 /* SimpleUI */, 182 | ); 183 | }; 184 | /* End PBXProject section */ 185 | 186 | /* Begin PBXResourcesBuildPhase section */ 187 | 77518004160240BA00A89B24 /* Resources */ = { 188 | isa = PBXResourcesBuildPhase; 189 | buildActionMask = 2147483647; 190 | files = ( 191 | ); 192 | runOnlyForDeploymentPostprocessing = 0; 193 | }; 194 | /* End PBXResourcesBuildPhase section */ 195 | 196 | /* Begin PBXSourcesBuildPhase section */ 197 | 77518002160240BA00A89B24 /* Sources */ = { 198 | isa = PBXSourcesBuildPhase; 199 | buildActionMask = 2147483647; 200 | files = ( 201 | 7751802D1602414D00A89B24 /* test.cpp in Sources */, 202 | 775180341602415500A89B24 /* CoreWindow_mac.mm in Sources */, 203 | ); 204 | runOnlyForDeploymentPostprocessing = 0; 205 | }; 206 | /* End PBXSourcesBuildPhase section */ 207 | 208 | /* Begin XCBuildConfiguration section */ 209 | 77518022160240BA00A89B24 /* Debug */ = { 210 | isa = XCBuildConfiguration; 211 | buildSettings = { 212 | ALWAYS_SEARCH_USER_PATHS = NO; 213 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 214 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 215 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 216 | COPY_PHASE_STRIP = NO; 217 | GCC_C_LANGUAGE_STANDARD = gnu99; 218 | GCC_DYNAMIC_NO_PIC = NO; 219 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 220 | GCC_OPTIMIZATION_LEVEL = 0; 221 | GCC_PREPROCESSOR_DEFINITIONS = ( 222 | "DEBUG=1", 223 | "$(inherited)", 224 | ); 225 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 226 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 227 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 228 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 229 | GCC_WARN_UNUSED_VARIABLE = YES; 230 | MACOSX_DEPLOYMENT_TARGET = 10.7; 231 | ONLY_ACTIVE_ARCH = YES; 232 | SDKROOT = macosx; 233 | }; 234 | name = Debug; 235 | }; 236 | 77518023160240BA00A89B24 /* Release */ = { 237 | isa = XCBuildConfiguration; 238 | buildSettings = { 239 | ALWAYS_SEARCH_USER_PATHS = NO; 240 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 241 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 242 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 243 | COPY_PHASE_STRIP = YES; 244 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 245 | GCC_C_LANGUAGE_STANDARD = gnu99; 246 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 247 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 248 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 249 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 250 | GCC_WARN_UNUSED_VARIABLE = YES; 251 | MACOSX_DEPLOYMENT_TARGET = 10.7; 252 | SDKROOT = macosx; 253 | }; 254 | name = Release; 255 | }; 256 | 77518025160240BA00A89B24 /* Debug */ = { 257 | isa = XCBuildConfiguration; 258 | buildSettings = { 259 | COMBINE_HIDPI_IMAGES = YES; 260 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 261 | GCC_PREFIX_HEADER = "SimpleUI-Prefix.pch"; 262 | INFOPLIST_FILE = "SimpleUI-Info.plist"; 263 | PRODUCT_NAME = "$(TARGET_NAME)"; 264 | WRAPPER_EXTENSION = app; 265 | }; 266 | name = Debug; 267 | }; 268 | 77518026160240BA00A89B24 /* Release */ = { 269 | isa = XCBuildConfiguration; 270 | buildSettings = { 271 | COMBINE_HIDPI_IMAGES = YES; 272 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 273 | GCC_PREFIX_HEADER = "SimpleUI-Prefix.pch"; 274 | INFOPLIST_FILE = "SimpleUI-Info.plist"; 275 | PRODUCT_NAME = "$(TARGET_NAME)"; 276 | WRAPPER_EXTENSION = app; 277 | }; 278 | name = Release; 279 | }; 280 | /* End XCBuildConfiguration section */ 281 | 282 | /* Begin XCConfigurationList section */ 283 | 77518000160240BA00A89B24 /* Build configuration list for PBXProject "SimpleUI" */ = { 284 | isa = XCConfigurationList; 285 | buildConfigurations = ( 286 | 77518022160240BA00A89B24 /* Debug */, 287 | 77518023160240BA00A89B24 /* Release */, 288 | ); 289 | defaultConfigurationIsVisible = 0; 290 | defaultConfigurationName = Release; 291 | }; 292 | 77518024160240BA00A89B24 /* Build configuration list for PBXNativeTarget "SimpleUI" */ = { 293 | isa = XCConfigurationList; 294 | buildConfigurations = ( 295 | 77518025160240BA00A89B24 /* Debug */, 296 | 77518026160240BA00A89B24 /* Release */, 297 | ); 298 | defaultConfigurationIsVisible = 0; 299 | defaultConfigurationName = Release; 300 | }; 301 | /* End XCConfigurationList section */ 302 | }; 303 | rootObject = 77517FFD160240BA00A89B24 /* Project object */; 304 | } 305 | -------------------------------------------------------------------------------- /xcode/SimpleUI.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | --------------------------------------------------------------------------------