org.lwjgl.opengl.WGLARBCreateContext Java Examples

The following examples show how to use org.lwjgl.opengl.WGLARBCreateContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WGLContextCreator.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
protected void onNewConnection() {
	PIXELFORMATDESCRIPTOR pfd = PIXELFORMATDESCRIPTOR.calloc();
	pfd.dwFlags(GDI32.PFD_DRAW_TO_WINDOW | GDI32.PFD_SUPPORT_OPENGL | GDI32.PFD_DOUBLEBUFFER);
	pfd.iPixelType(GDI32.PFD_TYPE_RGBA);
	pfd.cColorBits((byte) 32);
	pfd.cStencilBits((byte) 1);

	pfd.cDepthBits((byte) 24);

	int pixel_format = GDI32.ChoosePixelFormat(windowDrawable, pfd);
	if(pixel_format == 0) throw new Error("Could not find pixel format!");
	GDI32.SetPixelFormat(windowDrawable, pixel_format, pfd);

	pfd.free();


	context = WGL.wglCreateContext(windowDrawable);
	WGL.wglMakeCurrent(windowDrawable, context);
	WGLCapabilities caps = GL.createCapabilitiesWGL();
	if(caps.WGL_ARB_create_context && caps.WGL_ARB_create_context_profile) {
		WGL.wglDeleteContext(context);
		context = 0;

		int i = debug ? 0 : 3;
		while(context == 0 && ctx_attrs.length > i) {
			context = WGLARBCreateContext.wglCreateContextAttribsARB(windowDrawable, 0, ctx_attrs[i]);
		}
	} else {
		if(debug) {
			WGL.wglDeleteContext(context);
			throw new Error("WGL could not create a debug context!");
		}
	}

	if(context == 0) throw new Error("Could not create WGL context!");
	parent.wrapNewContext();
}