Skip to content
Snippets Groups Projects

Add check-gl draw a triangle using opengl test

Merged Jeremy Whiting requested to merge wip/jpwhiting/check-gl into master
Files
2
+ 28
27
@@ -42,7 +42,11 @@ static const char *argv0;
class HelloTriangleGLApplication {
public:
HelloTriangleGLApplication(bool visible)
: m_visible(visible)
: m_visible(visible),
m_display(nullptr),
m_window(0),
m_context(0),
m_visualID(0)
{
}
@@ -66,7 +70,7 @@ private:
throw std::runtime_error("Unable to open display");
}
make_window(m_display, "test-gl", 0, 0, &m_window, &m_context, &m_visualID);
makeWindow();
if (m_visible)
XMapWindow(m_display, m_window);
@@ -94,9 +98,7 @@ private:
glEnable(GL_NORMALIZE);
}
void make_window( Display *dpy, const char *name,
int x, int y,
Window *winRet, GLXContext *ctxRet, VisualID *visRet)
void makeWindow()
{
int attribs[64];
int i = 0;
@@ -105,8 +107,6 @@ private:
XSetWindowAttributes attr;
unsigned long mask;
Window root;
Window win;
GLXContext ctx;
XVisualInfo *visinfo;
/* Singleton attributes. */
@@ -125,10 +125,10 @@ private:
attribs[i++] = None;
scrnum = DefaultScreen( dpy );
root = RootWindow( dpy, scrnum );
scrnum = DefaultScreen(m_display);
root = RootWindow(m_display, scrnum);
visinfo = glXChooseVisual(dpy, scrnum, attribs);
visinfo = glXChooseVisual(m_display, scrnum, attribs);
if (!visinfo)
{
throw std::runtime_error("Error: couldn't get an RGB, Double-buffered visual");
@@ -138,38 +138,33 @@ private:
/* window attributes */
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
attr.colormap = XCreateColormap(m_display, root, visinfo->visual, AllocNone);
attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
/* XXX this is a bad way to get a borderless window! */
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
win = XCreateWindow( dpy, root, x, y, WIDTH, HEIGHT,
m_window = XCreateWindow( m_display, root, 0, 0, WIDTH, HEIGHT,
0, visinfo->depth, InputOutput,
visinfo->visual, mask, &attr );
/* set hints and properties */
{
XSizeHints sizehints;
sizehints.x = x;
sizehints.y = y;
sizehints.x = 0;
sizehints.y = 0;
sizehints.width = WIDTH;
sizehints.height = HEIGHT;
sizehints.flags = USSize | USPosition;
XSetNormalHints(dpy, win, &sizehints);
XSetStandardProperties(dpy, win, name, name,
XSetNormalHints(m_display, m_window, &sizehints);
XSetStandardProperties(m_display, m_window, "check-gl", "check-gl",
None, (char **)NULL, 0, &sizehints);
}
ctx = glXCreateContext( dpy, visinfo, NULL, True );
if (!ctx)
m_context = glXCreateContext(m_display, visinfo, NULL, True );
if (!m_context)
{
throw std::runtime_error("Error: glXCreateContext failed");
}
*winRet = win;
*ctxRet = ctx;
*visRet = visinfo->visualid;
XFree(visinfo);
}
@@ -180,10 +175,16 @@ private:
}
void cleanup() {
glXMakeCurrent(m_display, None, NULL);
glXDestroyContext(m_display, m_context);
XDestroyWindow(m_display, m_window);
XCloseDisplay(m_display);
if (m_display) {
glXMakeCurrent(m_display, None, nullptr);
if (m_context) {
glXDestroyContext(m_display, m_context);
}
if (m_window) {
XDestroyWindow(m_display, m_window);
}
XCloseDisplay(m_display);
}
}
void drawFrame() {
Loading