Simple texture loading with DevIL revisited

I wrote an article a while back about loading images to use as textures in OpenGL, and in it I’d written my own single line image to texture-handle function because I couldn’t get the built-in ilutGLLoadImage function to work. Since I’ve been getting blank looks and failure to compile reports about it, I thought I’d go and take a look at it again, and this time ilutGLLoadImage seems to work just fine, so let’s document it up properly shall we?

Pre-requisites

You will need:

  • A C++ compiler of your choice (I prefer Code::Blocks)
  • Working OpenGL drivers
  • A copy of DevIL
  • A copy of GLEW (GL Extension Wrangler – to make the functionality in your OpenGL drivers availble for use)
  • A copy of GLFW (GL FrameWork – to quickly and easily set up a OpenGL context)
  • An image to load

Preparation and libraries

Create a new project in your IDE of choice, and link in the following libraries:
DevIL required libraries

You’ll have to figure out where the libraries are on your own system but these are where they are on mine, where a /usr/local/ address indicates packages I’ve build myself, /usr/lib/ indicates standard system installed packages, and no prefix uses any paths defined by the compiler (in this case /usr/ where the lib and include directories are assumed). I’ve also added /usr/local/ to the include path so that any headers in /usr/local/include/ are picked up before any in /usr/include. Yes, library paths are a pain ;)

Also, be sure that your project includes its own directory as the working directory (i.e. the directory to be in when executing) so that you can place your image (in this example, a file called abstract-image.jpg) in the main project directory and it’ll be picked up when we try to load it. The way that you specify the working directory will vary depending on the IDE you’re using, but in Code::Blocks you set it from Project | Properties | Build targets like this:

Code::Blocks Working Directory

Source Code

Create a new project with source code something like this:

End Result

If you’ve linked in the libraries and used source code like the above, you should end up with a working texture that looks something like this:
ilutGLLoadImage Example

And information regarding the image being used that looks something like this:
DevIL Image Data

I’ve attached a copy of my Code::Blocks project here for anyone who wants it.

Cheers!

Credits: The wallpaper I used as the texture in this guide is Life by N.Design Studio, which you can find here.

How to: Build GLEW on Debian

GLEW - The GL Extension WranglerI’ve just jumped ship from Ubuntu to Linux Mint Debian Edition (20011-08 RC1, 64-bit Gnome version) because as much as I tried, I just couldn’t get along with Xfce and Thunar, and I’ve had it up to my eyeballs with the Ubuntu desktop experience *@&%ers making decisions for me.

So now I need to be able to build the latest version of a few packages. Again. In this case, it’s GLEW 1.7.0 – but thankfully this one’s pretty do-able:

1.) Install some GLEW build pre-req’s with:

2.) Get the GLEW source and extract it.

3.) If you want to install in /usr/local/ instead of /usr/ (which is generally a good idea for packages you’ve built yourself so you can easily distinguish them from “system packages”) then edit the Makefile in your extracted glew folder and make the following change:

Should be modified to read:

4.) On Debian it appears that /usr/local/lib64 doesn’t already exist as a symlink to /usr/local/lib (which means that you could end up with some of your stuff in the local/lib folder and some in the local/lib64 folder – which would be rubbish), so create the symlink yourself first with:

5.) Run make then sudo make install

6.) Finally, once you have your GLEW stuff installed, don’t forget to link in libGL.so to your OpenGL projects, which if you’re making the switch from Ubuntu to Debian like I am, have now moved from /usr/lib/libGL.so to /usr/lib/x86_64-linux-gnu/libGL.so, at least on my 64-bit setup.

Fun, eh? Sheesh!

How to: manipulate webcam streams with OpenCV and OpenGL

Okay – third and final part… I saw a video, I wanted to recreate the effect they used, and now I have, on a live, real-time-processed webcam stream using C++, OpenCV and OpenGL. Yay! =D

Full source code after the jump =D

Continue reading How to: manipulate webcam streams with OpenCV and OpenGL

2D C++ OpenGL/GLFW Basecode

I’m teaching some games programming stuff this year, and we’d started off using SDL, but the students are having a hard time with it – the main problems being:
– It’s bulky,
– It demands control of the mainline and then bloats it,
– The documentation is okay, but significantly less than stellar.

This isn’t to say that I have much against SDL – it does a lot of good things, but I’m concerned it’s providing too much specific functionality, which I don’t want to rely on and be tied to when (not if) things change in the future. So with this in mind, I’ve spent the evening reading about OpenGL frameworks and have decided to take the class in a new direction – namely GLFW, the cross-platform OpenGL framework.

We’re mainly going to be working in 2D, so I’ve put together some OpenGL/GLFW basecode that initialises a window, sets orthogonal projection (i.e. things further away don’t get any smaller) and just draws a line from the top-left to the bottom-right (so is easy to strip out when you want to adapt it to your own purposes) – and the entire thing is only around 100 lines of code! (and that’s with stacks of whitespace). The equivalent in SDL is closer to 350 lines and is significantly more complex/complex-looking.

Check it out…

How streamlined is that?!? Sweeeeeeet!

Next task – do stuff with it! =D

P.S. If you wanted to add GLEW to it to take care of all your extension wrangling needs, then just add the glew.h header before glfw.h, include the glew library in your project and add the following to the top of the initGL function:

Cheers!

Update: Modified initGL() function to disable the depth testing correctly via glDisable(GL_DEPTH_TEST) and not glDisable(GL_DEPTH) – silly mistake.