NovaCoder
Posts: 6
Joined: Mon May 29, 2017 11:37 pm

OpenGL with X11

Wed May 15, 2019 12:22 am

Hi,

I'm just starting off on the pi and with OpenGL development using C++.

I found this tutorial https://github.com/gamedevtech/X11OpenGLWindow

Would this be a good place to start?

I've already enabled the hardware OpenGL driver on my pi, do I need to install/update any other libraries?

My interest is with porting 90's games so not after learning cutting edge OpenGL.

Thanks

User avatar
Gavinmc42
Posts: 3142
Joined: Wed Aug 28, 2013 3:31 am

Re: OpenGL with X11

Wed May 15, 2019 12:46 am

I currently play with the Mesa3D demo examples in Sakaki's Gentoo64 which has newer OpenGL drivers.
https://www.mesa3d.org/repository.html
Raspbian is still using mesa 13, Gentoo64 is 19 , type glxinfo to check.

But most of my time is taking up doing 2D with OpenVG and AJ Starks library/examples.
https://github.com/ajstarks
I had been wondering if this could be used to make simple games and GUI's as it seems like it gets neglected..

Raspbian is a Linux X11 Desktop and they prefer OpenGL.
Android use their own desktop based on OpenGLES.
I'm trying to make a simple one with OpenVG, just for fun :D

I figure if I learn OpenVG first, then OpenGLES will be easy and then OpenGL will be easier again, by which time Vulkan will be on Pi's.
Probably should just learn Vulkan and skip some learning, but Pi's are about learning ;)
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

NovaCoder
Posts: 6
Joined: Mon May 29, 2017 11:37 pm

Re: OpenGL with X11

Wed May 15, 2019 1:22 am

Gavinmc42 wrote:
Wed May 15, 2019 12:46 am
I currently play with the Mesa3D demo examples in Sakaki's Gentoo64 which has newer OpenGL drivers.
https://www.mesa3d.org/repository.html
Raspbian is still using mesa 13, Gentoo64 is 19 , type glxinfo to check.
Cool, thanks for the info :D

So if I swap from Rasbian to Gentoo64 then it will support this kind of code out of the box?

Code: Select all

// Open the display
	display = XOpenDisplay(NULL);
	if (display == NULL) {
		std::cout << "Could not open display\n";
		return 1;
	}
	screen = DefaultScreenOfDisplay(display);
	screenId = DefaultScreen(display);

	
	// Check GLX version
	GLint majorGLX, minorGLX = 0;
	glXQueryVersion(display, &majorGLX, &minorGLX);
	if (majorGLX <= 1 && minorGLX < 2) {
		std::cout << "GLX 1.2 or greater is required.\n";
		XCloseDisplay(display);
		return 1;
	}
	else {
		std::cout << "GLX version: " << majorGLX << "." << minorGLX << '\n';
	}

	// GLX, create XVisualInfo, this is the minimum visuals we want
	GLint glxAttribs[] = {
		GLX_RGBA,
		GLX_DOUBLEBUFFER,
		GLX_DEPTH_SIZE,     24,
		GLX_STENCIL_SIZE,   8,
		GLX_RED_SIZE,       8,
		GLX_GREEN_SIZE,     8,
		GLX_BLUE_SIZE,      8,
		GLX_SAMPLE_BUFFERS, 0,
		GLX_SAMPLES,        0,
		None
	};
	XVisualInfo* visual = glXChooseVisual(display, screenId, glxAttribs);
	
	if (visual == 0) {
		std::cout << "Could not create correct visual window.\n";
		XCloseDisplay(display);
		return 1;
	}

	// Open the window
	XSetWindowAttributes windowAttribs;
	windowAttribs.border_pixel = BlackPixel(display, screenId);
	windowAttribs.background_pixel = WhitePixel(display, screenId);
	windowAttribs.override_redirect = True;
	windowAttribs.colormap = XCreateColormap(display, RootWindow(display, screenId), visual->visual, AllocNone);
	windowAttribs.event_mask = ExposureMask;
	window = XCreateWindow(display, RootWindow(display, screenId), 0, 0, 320, 200, 0, visual->depth, InputOutput, visual->visual, CWBackPixel | CWColormap | CWBorderPixel | CWEventMask, &windowAttribs);

	// Create GLX OpenGL context
	GLXContext context = glXCreateContext(display, visual, NULL, GL_TRUE);
	glXMakeCurrent(display, window, context);
?

User avatar
Gavinmc42
Posts: 3142
Joined: Wed Aug 28, 2013 3:31 am

Re: OpenGL with X11

Wed May 15, 2019 2:37 am

So if I swap from Rasbian to Gentoo64 then it will support this kind of code out of the box?
Only one way to tell if it works ;)
https://www.raspberrypi.org/forums/view ... 4&t=188448

The other reason I like the mesa examples is they are usually just one small file, so easy to read, hack, compile and learn.
Big difference between Raspbian and Gentoo64 last time I compared them.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

NovaCoder
Posts: 6
Joined: Mon May 29, 2017 11:37 pm

Re: OpenGL with X11

Wed May 15, 2019 3:00 am

Thanks Gavin, I'll give it a try and see what I can break ;)

Return to “Graphics programming”