aboutsummaryrefslogtreecommitdiffstats
path: root/CNativeCode/GLDrawableFactory_Win32_SunJDK13.c-jau
blob: 72a12eec4dfba6f5487a70188010c9e74cf52606 (plain)
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
#include "gl4java_drawable_Win32SunJDK13GLDrawableFactory.h"
#include "OpenGL_Win32_common.h"

/* FIXME: extend to support multiple monitors on Win2K/98 */
static HDC getScreenDC(int screen)
{
    return CreateDC("DISPLAY", NULL, NULL, NULL);
}

static void freeScreenDC(HDC dc)
{
    DeleteDC(dc);
}


JNIEXPORT jlong JNICALL Java_gl4java_drawable_Win32SunJDK13GLDrawableFactory_ChoosePixelFormatNum
  (JNIEnv *env, jclass unused, jint screen, jobject capsObj, jboolean verbose)
{
    HDC dc;
    PIXELFORMATDESCRIPTOR pfd;
    jboolean ok;
    GLCapabilities glCaps;
    int nPixelFormat;

    ok = javaGLCapabilities2NativeGLCapabilities ( env, capsObj, &glCaps );
    if(JNI_TRUE!=ok)
    {
        fprintf(stderr,"GL4Java Win32DrawableFactory.ChoosePixelFormatNum ERROR: gl4java/GLCapabilities fields not accessible\n");
	fflush(stderr);
        return JNI_FALSE;
    }

    /* dc = getScreenDC(screen); */
	dc = GetWindowDC(NULL);

    setPixelFormatByGLCapabilities(&pfd, &glCaps, JNI_FALSE, dc);

    if(JNI_TRUE==verbose)
    {
	    fprintf(stdout, "Win32DrawableFactory.ChoosePixelFormatNum: input capabilities:\n");
	    printGLCapabilities ( &glCaps );
    }

    nPixelFormat = ChoosePixelFormat(dc, &pfd);

    (void) setGLCapabilities (  dc, nPixelFormat, &glCaps );

    if(JNI_TRUE==verbose)
    {
		fprintf(stdout,"Win32DrawableFactory.ChoosePixelFormatNum: writing capabilities to GLContext's java object\n");
		printGLCapabilities ( &glCaps );
		fflush(stdout);
    }

    (void) nativeGLCapabilities2JavaGLCapabilities
                 (env, capsObj, &glCaps); 

    /* freeScreenDC(dc); */
	ReleaseDC(NULL, dc);
    return (jlong)nPixelFormat;
}