-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenGLFrame.xs
129 lines (111 loc) · 4.57 KB
/
OpenGLFrame.xs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright (c) Robert May 2006..2009
*/
#define WIN32_LEAN_AND_MEAN
#define STRICT
#define WINVER 0x0400 /* NOT 0x0501 for VC6 compatibility */
#define _WIN32_WINNT 0x0400 /* NOT 0x0501 for VC6 compatibility */
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include <windows.h>
#include <gl/Gl.h>
MODULE = Win32::GUI::OpenGLFrame PACKAGE = Win32::GUI::OpenGLFrame
PROTOTYPES: ENABLE
##########################################################################
# (@)INTERNAL:_SetOpenGLPixelFormat([DOUBLEBUFFER=0, [DEPTH=0]])
# Set a suitable pixel format for OpenGL rendering
# If DOUBLEBUFFER is true, then sets PFD_DOUBLEBUFFER
# Returns a HDC on success (0 on failure)
HDC _SetOpenGLPixelFormat(hWnd, doubleBuffer=0, depth=0)
HWND hWnd
BOOL doubleBuffer
BOOL depth
PREINIT:
int best_format;
PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR) };
CODE:
/* Initialise the PIXELFORMATDESCRIPTOR structure */
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = (depth ? 32 : 0);
pfd.iLayerType = PFD_MAIN_PLANE; /* ignored */
if(doubleBuffer)
pfd.dwFlags |= PFD_DOUBLEBUFFER;
/* choose the most appropriate format for the DC */
if(RETVAL = GetDC(hWnd)) {
if((best_format = ChoosePixelFormat(RETVAL, &pfd)) && SetPixelFormat(RETVAL, best_format, &pfd)) {
/* success - we don't need to release the DC, as our class has a private DC (CS_OWNDC) */
}
else {
ReleaseDC(hWnd, RETVAL); /* Not necessary, but good form */
RETVAL = NULL;
}
}
OUTPUT:
RETVAL
##########################################################################
# (@)WIN32API:wglCreateContext(HDC)
# Create a new OpenGL rendering context suitable for use with
# Device Context hdc.
# returns the handle to the rendering context on success, false on failure
# See OpenGLFrame.pm for full documentation
HGLRC wglCreateContext(hdc)
HDC hdc
##########################################################################
# (@)WIN32API:wglDeleteContext(HDC)
# Delete an OpenGL rendering context
# returns true on success, false on failure
# See OpenGLFrame.pm for full documentation
BOOL wglDeleteContext(hglrc)
HGLRC hglrc
##########################################################################
# (@)WIN32API:wglMakeCurrent([HDC, [HGLRC]])
# Makes HGLRC the active rendering context for the current thread, and
# causes all drawing to HGLRC to be directed to HDC.
# If HDC and HGLRC are omitted, de-activates the thread's currently active
# rendering context, if any.
# returns true on success, false on failure
# See OpenGLFrame.pm for full documentation
BOOL wglMakeCurrent(hdc=NULL,hglrc=NULL)
HDC hdc
HGLRC hglrc
##########################################################################
# (@)WIN32API:wglGetCurrentDC()
# returns a handle to the DC for the threads currently active OpenGL
# rendering context, or false if the thread does not have an active
# rendering context.
# See OpenGLFrame.pm for full documentation
HDC wglGetCurrentDC()
##########################################################################
# (@)WIN32API:SwapBuffers(HDC)
# Swaps the front and back buffers of the device context if it has a
# current pixel format that supports double buffering, otherwise
# does nothing.
# Returns true on success or false on failure
# See OpenGLFrame.pm for full documentation
BOOL SwapBuffers(hdc)
HDC hdc
##########################################################################
# (@)WIN32API:glFlush()
# Force execution of OpenGL functions in a finite time
# See OpenGLFrame.pm for full documentation
void glFlush()
##########################################################################
# (@)WIN32API:glViewport(X,Y,W,H)
# Set the viewport dimenstions
# See OpenGLFrame.pm for full documentation
void glViewport(x,y,w,h)
GLint x
GLint y
GLsizei w
GLsizei h
##########################################################################
# (@)WIN32API:glClear()
# Clear all the buffers using preset(default) values.
# See OpenGLFrame.pm for full documentation
void glClear(mask=GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_ACCUM_BUFFER_BIT|GL_STENCIL_BUFFER_BIT)
GLbitfield mask