Saturday, March 29, 2014

OpenGL Texture is not (just) Picture

I'm a beginner in OpenGL for sure and one of the most confusing thing (read: naming convention) that has plagued me in these last two days is OpenGL texture. Contrary to the naming for functions, constants and objects used for OpenGL texture, everything related to texture on those "interfaces" don't really apply to image/picture only. It's much more general than that. OpenGL texture is basically a "lookup-table" (array) and it can store anything as long as the data type matches with the texture that you use in your code. The naming for OpenGL texture "interface" that usually implies the use of image/picture is a legacy of the past. It was used since the day of fixed-function video card and used until now to preserve API backward-compatibility--at least that's one of the reason that I'm aware of.

Anyway, these are some useful links regarding OpenGL texture:
http://www.mathematik.uni-dortmund.de/~goeddeke/gpgpu/tutorial.html#arrays1
http://www.arcsynthesis.org/gltut/Texturing/Tutorial%2014.html

Friday, March 21, 2014

Adding New Directory to CodeBlocks Code Completion

CodeBlocks (http://www.codeblocks.org) cannot enumerate all of the possible C/C++ include directories automatically in some cases. For example, when you are using 3rd party C/C++ libraries which are installed in non-standard path. At least that's the state of CodeBlocks v13.12.

Now, how do you go about adding new directories to be added to the codecompletion parser? The procedure is explained in CodeBlocks FAQ at http://wiki.codeblocks.org/index.php?title=FAQ-Settings. However, as I found out, only the second method works in CodeBlocks v13.12, i.e. only the per-project non-standard include directories (to be parsed) can be configured. These are the steps:

  1. Activate the project (either by double clicking on it in the Projects pane or right click on the project and then click "Activate")
  2. Click on the "Project | Properties" menu. 
  3. Click on the "C/C++ parser options" tab. 
  4. Add the additional include directory to be parsed by the Code Completion plugin.
  5. Click on OK.
Now, you should have code completion working in CodeBlocks editor. If it's not working yet, you might need to close the project and re-open the project again.

Wednesday, February 26, 2014

OpenGL Application Development in Windows 8.1 64-bit

I've been doing some OpenGL application development with Visual Studio 2012 for a week or so but I found it rather frustrating because M$ doesn't provide all headers required by C99 standards. Moreover, I have yet to configure GLSL syntax highlighting successfully in Visual Studio 2012. Well, it turned out it's much better to carryout OpenGL-related development with MinGW and using CodeBlocks as the IDE.

You can download CodeBlocks from www.codeblocks.org and use the 64-bit MinGW distribution from http://nuwen.net/mingw.html. The only missing library would be freeglut for MinGW which you can download from http://www.transmissionzero.co.uk/software/freeglut-devel/. The MinGW distribution from Stephan T. Lavavej (nuwen.net) already has GLEW in it, but it doesn't have glut or freeglut.

The way I setup my development environment as follows:
  1. Use CodeBlocks as the IDE, i.e. download and use CodeBlocks distribution that DOESN'T include MinGW because we are going to use the one from nuwen.net.
  2. Use nuwen.net MinGW as the source for base GCC, GLEW and GLM tools, libraries and includes.
  3. Use Freeglut for MinGW as the glut replacement.
Assuming you have setup all of the tools above correctly (consult their README files), it's time to create a sort of "Hello World" application in OpenGL. Head to http://en.wikibooks.org/wiki/OpenGL_Programming and try the first tutorial source code. This is how I create project in CodeBlocks for that tutorial:
  1. Create an empty project in CodeBlocks.
  2. Add all tutorial 01 source code from the basics arc (http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Introduction) into the empty project.
  3. Fix all required settings before building the project, i.e. compiler include directory search paths and libraries search paths. The details are explained below.
The following screen captures show the settings that I changed to compile tutorial 01 successfully. The tabs, menus and entries highlighted (in red box) are those that you should change according to your MinGW installation details.





Once everything compiled and linked successfully, you can run the application. This is how the application should look like.


Well done. Now, you can proceed developing all other OpenGL application in Windows without thinking about C99 and GLSL syntax highlighting matters :-).

Anyway, you could actually setup the compiler and linker setting in per-project basis in CodeBlocks via the Project|Build Option menu. Clicking this menu will open a similar dialog box as shown in the screenshot above. However, it will only apply to currently active project.

Tuesday, February 18, 2014

Up-to-Date OpenGL Tutorial for Beginner

I found the Swiftless series article on OpenGL at: OpenGL 2 Tutorials and OpenGL 4 Tutorials
to be very compelling for newbie on the subject. They are particularly easy to follow for complete newbie.
One thing that sets them apart from other articles on the subject is they cover recent implementation of OpenGL. Therefore, it's easier to follow on present day OpenGL library available on recent systems and also features supported by present day GPUs.

Nice stuff Swiftless. Kudos to your work :-)

If you want a quite lengthy but deep introduction, head to Learning Modern 3D Graphics Programming. This is the most complete tutorial I found on the Net so far. Well, it's very well structured for my taste. I think, it's even better than http://en.wikibooks.org/wiki/OpenGL_Programming.