Browsed by
Category: Technical

“Hello World” OpenGL on Linux

“Hello World” OpenGL on Linux

Writing the OpenGL context creation plumbing on Linux isn’t 100% intuitive. It’s always good to have a handy getting started guide. With developers increasingly using engines such as Unity, the number of people writing directly to OpenGL is shrinking – and so are some of the online resources to get over this initial step. I decided to collect a few links and copy critical sample code here for when I need to whip something up quickly.

 

Some links to good ‘hello world’ Linux GL samples:
https://github.com/jckarter/hello-gl
https://www.opengl.org/wiki/Tutorial:_OpenGL_3.0_Context_Creation_(GLX)
http://www-f9.ijs.si/~matevz/docs/007-2392-003/sgi_html/ch04.html

 

Code:
Taken from: https://www.opengl.org/sdk/docs/man2/xhtml/glXIntro.xml

Below is a minimal example of creating an RGBA-format X window that’s compatible with OpenGL using GLX 1.3 commands. The window is cleared to yellow when the program runs. The program does minimal error checking; all return values should be checked.

#include < stdio.h >
#include < stdlib.h >
#include < GL/gl.h >
#include < GL/glx.h >

int singleBufferAttributess[] = {
    GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
    GLX_RENDER_TYPE,   GLX_RGBA_BIT,
    GLX_RED_SIZE,      1,   /* Request a single buffered color buffer */
    GLX_GREEN_SIZE,    1,   /* with the maximum number of color bits  */
    GLX_BLUE_SIZE,     1,   /* for each component                     */
    None
};

int doubleBufferAttributes[] = {
    GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
    GLX_RENDER_TYPE,   GLX_RGBA_BIT,
    GLX_DOUBLEBUFFER,  True,  /* Request a double-buffered color buffer with */
    GLX_RED_SIZE,      1,     /* the maximum number of bits per component    */
    GLX_GREEN_SIZE,    1, 
    GLX_BLUE_SIZE,     1,
    None
};


static Bool WaitForNotify( Display *dpy, XEvent *event, XPointer arg ) {
    return (event->type == MapNotify) && (event->xmap.window == (Window) arg);
}
int main( int argc, char *argv[] )
{
    Display              *dpy;
    Window                xWin;
    XEvent                event;
    XVisualInfo          *vInfo;
    XSetWindowAttributes  swa;
    GLXFBConfig          *fbConfigs;
    GLXContext            context;
    GLXWindow             glxWin;
    int                   swaMask;
    int                   numReturned;
    int                   swapFlag = True;

    /* Open a connection to the X server */
    dpy = XOpenDisplay( NULL );
    if ( dpy == NULL ) {
        printf( "Unable to open a connection to the X servern" );
        exit( EXIT_FAILURE );
    }

    /* Request a suitable framebuffer configuration - try for a double 
    ** buffered configuration first */
    fbConfigs = glXChooseFBConfig( dpy, DefaultScreen(dpy),
                                   doubleBufferAttributes, &numReturned );

    if ( fbConfigs == NULL ) {  /* no double buffered configs available */
      fbConfigs = glXChooseFBConfig( dpy, DefaultScreen(dpy),
                                     singleBufferAttributess, &numReturned );
      swapFlag = False;
    }

    /* Create an X colormap and window with a visual matching the first
    ** returned framebuffer config */
    vInfo = glXGetVisualFromFBConfig( dpy, fbConfigs[0] );

    swa.border_pixel = 0;
    swa.event_mask = StructureNotifyMask;
    swa.colormap = XCreateColormap( dpy, RootWindow(dpy, vInfo->screen),
                                    vInfo->visual, AllocNone );

    swaMask = CWBorderPixel | CWColormap | CWEventMask;

    xWin = XCreateWindow( dpy, RootWindow(dpy, vInfo->screen), 0, 0, 256, 256,
                          0, vInfo->depth, InputOutput, vInfo->visual,
                          swaMask, &swa );

    /* Create a GLX context for OpenGL rendering */
    context = glXCreateNewContext( dpy, fbConfigs[0], GLX_RGBA_TYPE,
				 NULL, True );

    /* Create a GLX window to associate the frame buffer configuration
    ** with the created X window */
    glxWin = glXCreateWindow( dpy, fbConfigs[0], xWin, NULL );
    
    /* Map the window to the screen, and wait for it to appear */
    XMapWindow( dpy, xWin );
    XIfEvent( dpy, &event, WaitForNotify, (XPointer) xWin );

    /* Bind the GLX context to the Window */
    glXMakeContextCurrent( dpy, glxWin, glxWin, context );

    /* OpenGL rendering ... */
    glClearColor( 1.0, 1.0, 0.0, 1.0 );
    glClear( GL_COLOR_BUFFER_BIT );

    glFlush();
    
    if ( swapFlag )
        glXSwapBuffers( dpy, glxWin );

    sleep( 10 );
    exit( EXIT_SUCCESS );
}

 

The value of ESP was not properly saved across a function call…

The value of ESP was not properly saved across a function call…

Windows can trigger this error, but sometimes it’s not easy to figure out what’s going on.

I recently got this error when trying to use the OpenGL ES ANGLE library on Windows 10. When compiling against the ANGLE library, the error came when trying to call into the ANGLE and used eglGetProcAddress().

eglGetProcAddress() returns function pointers for important GL extensions, so I couldn’t just ignore it or work around it.

In looking around, the obvious first step is to make sure you’re defining the function pointers correctly, but that turns out not to be my problem.

In looking at this article, I realized I probably had a mismatch of compiler and linker settings. The Visual Studio projects (VS2008) that came with ANGLE required a certain set of compiler and linker flags that were not standard. I had migrated the Visual Studio projects to VS2015, so that also added an element of uncertainty. I simply opened both project settings up next to each other and compared the settings for the ANGLE library build and the final project and found a few mismatches. I change a number of them to be the same, and things worked great.

Summary:
Check the linking AND compiling flags for not only your project, but the project files that generate the libraries you’re linking against. Differences in compiler settings can cause this error.

NVidia GTX 1070’s – flickering and artifacts

NVidia GTX 1070’s – flickering and artifacts

If you own a GeForce GTX 1070, you might want to pay attention to this news item as you could be effected by this memory issue.

Some users have reported they noticed occasional flickering or graphical artifacts on multiple brands of the 1070. Right now most of the major vendors are working on (or already issuing) a BIOS firmware update for their graphics cards.

Investigation has shown the issues are graphics memory related. GeForce GTX 1070 cards fitted with Samsung memory do not appear to have any issues but some manufacturers have switched towards Micron chips and these appear to be the culprit. This is noticed most during overclocking the graphics memory subsystem. The problem is in the the speed of the voltage adjustment from the low power idle P-States for memory voltage under load. If you can keep the idle voltage above 0.800V before you apply the overclock, you never see the issue.

A number of manufacturers have been working on VBIOS updates, so be sure to check your vendor:

Full info:
http://www.guru3d.com/news-story/manufacturers-roll-out-firmware-updates-for-geforce-gtx-1070-due-to-memory-issue.html

Dynamic projection mapping onto deforming non-rigid surface

Dynamic projection mapping onto deforming non-rigid surface

Amazing work from the University of Tokyo. Dynamic projection mapping on non-rigid and self-occluding surfaces at 1000 fps and 3ms delay.

Projection mapping attracts attentions as an emerging technology to extend the real world. However, almost realized examples have been limited to static or quasi-static environments. This research aims at overcoming this limitation and realizes dynamic projection mapping in which dynamically changing real-world and virtual visual information are completely merged in the level of human visual perception. This high-speed dynamic projection mapping requires a high-speed projector enabling high-frame-rate and low-latency projection. In order to meet this demand, we have developed a high-speed projector “DynaFlash” that can project 8-bit images up to 1,000fps with 3ms delay.

Using these base technologies including DynaFlash and Deformable Dot Cluster Marker, we realize a new dynamic projection mapping onto deforming non-rigid surface. In this demonstration, by drawing the marker on the target with IR ink, we allow the marker to be invisible to human and enable robust sensing independently of the projected images. In our technology, both the projection and sensing are operated at a speed of 1,000 fps. Therefore, it is possible to keep the projection consistent with the deformation and extend the real world as if the projected image is printed or existed as an original (digital) texture on the target. Especially, focusing on new paradigms in the field of user interface and fashion, we have demonstrated dynamic projection mapping onto a deformed sheet of paper and T-shirt. Also we show that projection to multiple targets can be controlled flexibly by using multiple markers.

Mag-lev turntable

Mag-lev turntable

The first 45 seconds is gut-bustingly laughable, over the top, self-aggrandizing hyperbole – but it is certainly a cool looking invention.

The engineer in me wonders how they guarantee the exact RPM’s on this given the variable drag of the needle or movement of air currents (likely very solvable but I wonder about the latency). It also seems to me that bumping the table would produce the commiserate disturbance in the magnetic field which wouldn’t protect against bigger bumps – just tiny ones. Guess we’ll find out when it arrives, but I’ll always have a soft spot in my heart for the JA Michell Transcriptor Hydraulic Reference Turntable seen in Clockwork Orange and 2001. I’m pretty sure this will find its way into a sci-fi movie as well at some point.

 

The Machine Learning Revolution and You

The Machine Learning Revolution and You

Remember studying about that “Industrial Revolution” or “Internet” thing and how it changed society and demographics? This is a really good write-up on how the next revolution of machine learning is about, and already, changing everything again. Get ready for it.

https://www.wired.com/2015/08/robots-will-steal-jobs-theyll-give-us-new-ones/

 

Talks by John E Williamson – PAX West 2016

Talks by John E Williamson – PAX West 2016

John Williamson posted his PAX West and PAX Dev presentations online. You can download them here.

Hollywood Narrative Tricks and Shortcuts
http://bit.ly/PAXDEV_Williamson

Family Game Night With A Twist: Make Your Own Video Game
http://bit.ly/PAX_2016_FamilyGameNight

Digipen Panel – PAX 2016

Digipen Panel – PAX 2016

A group of folks from Digipen reflected back on their time there and tips for getting into the game industry. Besides the very specific Digipen ones, there’s some general ones that I found to be good tips.

  • There is no real way to keep up with outside friends or family. You will be that busy. Few parties – social circles shrink dramatically if you want to get things done to the high quality you desire. Most didn’t even date.
  • School at Digipen was much harder than traditional college (some had done both).
    • You will not have a social life outside of school – and many breakups occurred.
    • If married, make sure you make the decision together – with all the realities of time explained. Huge – or you’ll likely be filing divorce.
    • All this mirrors what occurs in the game industry after college too. You’re going to spend most of your time with these people you work with. Especially during crunch.
  • You can’t hold a job while at school (Digipen) – one gal quit the job after the first week of classes. Working while at Digipen is not realistic despite the debt you’ll accumulate (which is substantial).
  • You’ll lose most of your social life outside the few friends you make inside Digipen. Even that is tough to maintain. Likely won’t be playing many games anymore – won’t have time.
  • Cross-discipline interaction is really good for you. You have exposure to the language of other areas: artists, programmers, developers, project leads, etc – even if you don’t study it directly. Helps you understand why/what is most important to those other areas and really helps you succeed.
  • Always act professionally. Conventions, planes, bars, etc. You never know who is listening in – high probability that someone will know someone. Especially when heading to conferences – odds are high a good portion of the people on your flights, buses, etc are all going too. Don’t alienate yourself to others by being rude, dismissive, or offensive. The industry is far too small and you’ll get a reputation that can make you unhirable.
  • You’ll work with people that have different opinions. If it doesn’t impact your work, then let it go. Did we mention never burning bridges?
  • Find ways to keep motivated even when things don’t go as you expect. Many times you’ll get stuck working on something you don’t want to. You need a way to stay motivated, working quickly, and with high quality output so you will be recognized and be able to move to the next good thing.
  • 3 keys to a good hire: be personable, do good work, work quickly. Make everything presentable in as best way possible. Being personable trumps the others. You can be the smartest, fastest person around – but if you’re hard to get along with – nobody will want you.
  • For art reels, show your best stuff. A demo reel should be 1-2 minutes of your best work. It’s only as good as the weakest piece. Constantly update it and show new stuff.
  • For designers, show quantity of output.
  • For programmer, it’s about communicating your work/talking skills. You need to be able to narrate how your design works, thought process, and algorithms.
  • Start personal branding very soon. One fellow started 2 years before graduation and it made all the hard work you need to do much easier. Branding includes websites, collected pictures of work, demo reels, posting your work on sites like Polygon Count, etc. All takes lots of time to collect and get presentable. Don’t try to do it at the end – because you can’t and it will show.
  • As soon as you get an assignment and read through it, open a notepad and put ideas in there to start with. Don’t wait because often you’ll get so busy that all you have the day before it’s due is the idea(s) you put in there first. Don’t get yourself into a last-minute corner.
  • Network as much as you can everywhere you can. Every conference, meetup, professional group, etc. That is where your jobs come from.
  • People don’t want to work with someone that is just good – they also want someone they’ll like working with since you’re going to spend so much time together.