aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2014-04-01 12:10:46 +0200
committerWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2014-04-01 12:10:46 +0200
commitb266315a333cb4037b6f0fbc2fcc24c9c3fa8c0e (patch)
tree596462825dff8afbc2514b809468a926fb7e31b6
parent47abffdbf565fabb56a735930886fe32e00cb779 (diff)
downloadwglarb-b266315a333cb4037b6f0fbc2fcc24c9c3fa8c0e.tar.gz
wglarb-b266315a333cb4037b6f0fbc2fcc24c9c3fa8c0e.tar.bz2
layered window testcase
-rw-r--r--test/.gitignore1
-rw-r--r--test/Makefile6
-rw-r--r--test/layered.c277
-rw-r--r--wglarb.c5
-rw-r--r--wglarb.h3
5 files changed, 288 insertions, 4 deletions
diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644
index 0000000..b883f1f
--- /dev/null
+++ b/test/.gitignore
@@ -0,0 +1 @@
+*.exe
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..05fd8ee
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,6 @@
+CC=x86_64-w64-mingw32-gcc
+CFLAGS=-static-libgcc -static-libstdc++ -I..
+LIBS=-lopengl32 -lgdi32
+
+layered.exe: layered.c
+ $(CC) $(CFLAGS) -o layered.exe layered.c ../wglarb.c $(LIBS)
diff --git a/test/layered.c b/test/layered.c
new file mode 100644
index 0000000..26f0c02
--- /dev/null
+++ b/test/layered.c
@@ -0,0 +1,277 @@
+#include <windows.h>
+#include <wingdi.h>
+
+#include <stdio.h>
+#include <math.h>
+
+#include <GL/gl.h>
+#include <GL/glext.h>
+
+#include <wglarb.h>
+
+LRESULT CALLBACK ViewProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
+
+void reshape(int w,int h);
+void display();
+
+HWND hWnd;
+HDC hDC;
+HGLRC hRC;
+
+int win_width;
+int win_height;
+
+BOOL OpenGLWindowCreate(
+ LPCTSTR lpszWindowName,
+ LPCTSTR lpszClassName,
+ WNDPROC lpfnWndProc,
+ HINSTANCE hInstance,
+ DWORD dwStyle,
+ DWORD dwExStyle )
+{
+ if(!hInstance) {
+ hInstance = GetModuleHandle(NULL);
+ }
+
+ WNDCLASS wc;
+ memset(&wc,0,sizeof(wc));
+ wc.hInstance = hInstance;
+ wc.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
+
+ /* Register DefWindowProc with each the intermediary and the
+ * proper window class. We're setting the window proc of the
+ * proper window to the user supplied window proc later so that
+ * we can use the default proper window class name if no class
+ * name was supplied by the user. It also allows to use the same
+ * user supplied window class name with multiple, different
+ * window functions. */
+ wc.lpfnWndProc = DefWindowProc;
+ /* register proper window class */
+ if( !lpszClassName ) {
+ return FALSE;
+ }
+ wc.lpszClassName = lpszClassName;
+ RegisterClass(&wc);
+
+ fprintf(stderr, "creating proper window...\n");
+ hWnd = CreateWindowEx( dwExStyle,
+ wc.lpszClassName,
+ lpszWindowName,
+ dwStyle,
+ 0,0,100,100,
+ NULL,NULL,
+ hInstance,
+ NULL);
+
+ if(!hWnd) {
+ return FALSE;
+ }
+
+ SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)ViewProc);
+
+ fprintf(stderr, "retrieving proper DC...\n");
+ hDC = GetDC(hWnd);
+ if(!hDC) {
+ fprintf(stderr, "error retrieving proper DC\n");
+ DestroyWindow(hWnd);
+ return FALSE;
+ }
+
+ int attribs[] = {
+ WGL_DRAW_TO_WINDOW_ARB, TRUE,
+ WGL_DOUBLE_BUFFER_ARB, TRUE,
+ WGL_SUPPORT_OPENGL_ARB, TRUE,
+ WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
+ WGL_COLOR_BITS_ARB, 24,
+ WGL_RED_BITS_ARB, 8,
+ WGL_GREEN_BITS_ARB, 8,
+ WGL_BLUE_BITS_ARB, 8,
+ WGL_ALPHA_BITS_ARB, 8,
+ WGL_DEPTH_BITS_ARB, 24,
+ WGL_STENCIL_BITS_ARB, 8,
+ 0, 0
+ };
+
+ INT iPF;
+ PIXELFORMATDESCRIPTOR pfd;
+ fprintf(stderr, "choosing proper pixelformat...\n");
+ UINT num_formats_choosen;
+ if( !wglarb_ChoosePixelFormatARB(
+ hDC,
+ attribs,
+ NULL,
+ 1,
+ &iPF,
+ &num_formats_choosen) ) {
+ fprintf(stderr, "error choosing proper pixel format\n");
+ return FALSE;
+ }
+
+ /* now this is a kludge; we need to pass something in the PIXELFORMATDESCRIPTOR
+ * to SetPixelFormat; it will be ignored, mostly. OTOH we want to send something
+ * sane, we're nice people after all - it doesn't hurt if this fails. */
+ DescribePixelFormat(hDC, iPF, sizeof(pfd), &pfd);
+
+ fprintf(stderr, "setting proper pixelformat...\n");
+ if( !SetPixelFormat(hDC, iPF, &pfd) ) {
+ fprintf(stderr, "error setting proper pixel format\n");
+ ReleaseDC(hWnd, hDC);
+ DestroyWindow(hWnd);
+
+ return FALSE;
+ }
+
+ fprintf(stderr, "creating proper OpenGL context...\n");
+ int context_attribs[] = {
+ WGL_CONTEXT_MAJOR_VERSION_ARB, 2,
+ WGL_CONTEXT_MINOR_VERSION_ARB, 1,
+ 0, 0
+ };
+ hRC = wglarb_CreateContextAttribsARB(hDC, NULL, context_attribs);
+ if(!hRC) {
+ ReleaseDC(hWnd, hDC);
+ DestroyWindow(hWnd);
+
+ return FALSE;
+ }
+
+ /* Finally we can bind the proper OpenGL context to our window */
+ wglMakeCurrent(hDC, hRC);
+
+ SetLayeredWindowAttributes(hWnd, RGB(0,0,0), 0xff, LWA_ALPHA);
+ UpdateWindow(hWnd);
+ ShowWindow(hWnd, SW_SHOW);
+
+ return TRUE;
+
+fail_create_rc:
+fail_set_pf:
+fail_choose_pf:
+ ReleaseDC(hWnd, hDC);
+fail_get_dc:
+ DestroyWindow(hWnd);
+fail_create_wnd:
+
+ return FALSE;
+}
+
+void OnOpenGLWindowDestroy()
+{
+ wglMakeCurrent(NULL,NULL);
+ wglDeleteContext(hRC);
+ ReleaseDC(hWnd,hDC);
+ PostQuitMessage(0);
+}
+
+BOOL cursor_needs_setting = TRUE;
+
+LRESULT CALLBACK ViewProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
+{
+ switch(uMsg)
+ {
+ case WM_MOUSELEAVE:
+ cursor_needs_setting = TRUE;
+ break;
+
+ case WM_MOUSEMOVE:
+ if( cursor_needs_setting ) {
+ SetClassLongPtr(hWnd, GCLP_HCURSOR, (LONG_PTR)LoadCursor(NULL, IDC_ARROW));
+ cursor_needs_setting = FALSE;
+ }
+
+ break;
+
+ case WM_DESTROY:
+ OnOpenGLWindowDestroy();
+ break;
+
+ case WM_PAINT:
+ display();
+ break;
+
+ case WM_SIZE:
+ reshape(LOWORD(lParam),HIWORD(lParam));
+ break;
+ default:
+ break;
+ }
+ return DefWindowProc(hWnd,uMsg,wParam,lParam);
+}
+
+
+void reshape(int w,int h)
+{
+ win_width = w;
+ win_height = h;
+}
+
+
+void display()
+{
+ float const ratio = (float)win_width/(float)win_height;
+ glViewport(
+ 0,
+ 0,
+ win_width,
+ win_height);
+
+ glClearColor(0., 0., 0., 0.25);
+ glClearDepth(1.);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-ratio, ratio, -1., 1., -1, 1);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ float const cos60 = cosf(M_PI*60./180.);
+ float const sin60 = sinf(M_PI*60./180.);
+
+ GLfloat const triangle[] = {
+ -1., -sin60, 1., 0., 0.,
+ 1., -sin60, 0., 1., 0.,
+ 0., sin60, 0., 0., 1.
+ };
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+
+ glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*5, &triangle[0]);
+ glColorPointer( 3, GL_FLOAT, sizeof(GLfloat)*5, &triangle[0]);
+
+ glDrawArrays(GL_TRIANGLES, 0, 3);
+
+ SwapBuffers(hDC);
+}
+
+int CALLBACK WinMain(
+ HINSTANCE hInstance,
+ HINSTANCE hPrevInstance,
+ LPSTR lpCmdLine,
+ int nCmdShow)
+{
+ MSG msg;
+ BOOL bRet;
+
+ if( !OpenGLWindowCreate(
+ "Test", "TestWnd",
+ ViewProc,
+ hInstance,
+ WS_OVERLAPPEDWINDOW,
+ WS_EX_APPWINDOW | WS_EX_LAYERED) ) {
+ return -1;
+ }
+
+ while( (bRet = GetMessage(&msg, NULL, 0, 0)) ) {
+ if(bRet == -1) {
+ // Handle Error
+ }
+ else {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+ return msg.wParam;
+}
diff --git a/wglarb.c b/wglarb.c
index 2e8b9c1..383b5f7 100644
--- a/wglarb.c
+++ b/wglarb.c
@@ -19,10 +19,9 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
+#include <GL/gl.h>
#include "wglarb.h"
-#include <stdio.h>
-
#define WGLARB_INTERMEDIARY_CLASS "wglarb intermediary"
#define WGLARB_INTERMEDIARY_STYLE 0
#define WGLARB_INTERMEDIARY_EXSTYLE 0
@@ -168,7 +167,7 @@ BOOL WINAPI wglarb_ChoosePixelFormatARB(
BOOL ret = FALSE;
if( impl ) {
ret = impl(
- hDC,
+ hdc,
piAttribIList,
pfAttribFList,
nMaxFormats,
diff --git a/wglarb.h b/wglarb.h
index 10ba8fe..c056115 100644
--- a/wglarb.h
+++ b/wglarb.h
@@ -24,7 +24,8 @@ THE SOFTWARE.
#ifndef WGLARB_H
#define WGLARB_H
-#include <windows.h>
+// #include <windows.h>
+#include <GL/wglext.h>
HGLRC WINAPI wglarb_CreateContextAttribsARB(
HDC hDC,