Showing posts with label C. Show all posts
Showing posts with label C. Show all posts

Saturday, May 12, 2012

A Good Place to Start OpenGL

Many people want to learn OpenGL. Most of these people have no idea where to start. About everyone will learn OpenGL in some deprecated or round-a-bout way that discourages them from continuing their studies.

Well that's stupid and I'd like to at least point people in the right direction for getting started. This definitely isn't a tutorial, but I hope that it does serve to broaden your knowledge of available OpenGL tools, libraries and resources.

Here are the resources:

Basically you should walk through the samples provided over at g-truc to get an idea of what it means to create a current generation OpenGL project. The authors say that the code is not for beginners but they are only being modest and probably just don't intend for them to be used by beginners. I can honestly say that they are some of the best examples of OpenGL code available.

To build them on Windows for Visual Studio 2010 you need to install cmake. After that open up command line by running it as administrator. In this cmd window change to the samples folder that contains the /data, /external, /samples... the top level of the folder. Run the command [cmake -G "Visual Studio 10"]. Do not use the cmake GUI for this as it won't work. Now you should have vs2010 projects built that you can explore by opening the .sln.

What I suggest that you do is copy the projects and get accustomed to how they use OpenGL to express themselves. Their image loading tool, GLI, is for bringing in images to the program to use as textures. FreeGLUT is a "make windows and other stuff" utility that some people use. I honestly think all GLUT stuff is lame and suggest you learn to use GLFW instead. GLM is a great way to encapsulate all of your math needs for things such as vectors and matricies (which you will make heavy use of). It gives you a portable math solution that works great with OpenGL.

Friday, May 4, 2012

GLEW VS2010 Wont Link?!?!

This is quite a painful problem that can actually be solved easily if you know what to do.

You'll want to use the static library  (glew32s.lib) and define the preprocessor directive 'GLEW_STATIC'.
You should be able to just download the Windows binaries for this but you can build it yourself also if you'd like (it's also simple to do).

With Binaries:

  • Download glew (32 and 64 as you may need to try both. 32 will probably work though).
  • Properties > Linker > Input > Additional Dependencies : Add ( glew32s.lib, glu32.lib, opengl32.lib ).
  • Properties > General > Additional Library Directories : Add ( --your path to the glew libs-- ).
  • Properties > C/C++ > Preprocessor > Preprocessor Definitions : (Add --GLEW_STATIC-- ).
  • Copy the glew32.dll into the folder with your programs executable.
Building yourself:
  • Download glew.
  • Open up the build/vc6 project.sln.
  • Change build target from Debug to Release.
  • Go to the solution explorer on the right( or left ) side of VS2010 > right click static > build.
  • Copy the newly built .lib to what ever folder you use for your project's libraries.
  • Copy the glew32.dll into the folder with your programs executable.

And that should do it.

I can't stress enough how much of a rut I was stuck in trying to get this to work. Hours down the drain. Rage and frustration at an ever-living wall of linker errors for methods I knew should be linking.

So seriously, use the static build, make your call to glewInit(), and get back to the real work of your project.

Thanks for the solution go to ( many others not included here )

Friday, April 20, 2012

Qt, OpenGL and VS2010 How To

Resources:
My guide:

First, install [1]. Next install [2]. After that, you can notice a new Qt button at the top of your VS2010 toolbar. I haven't had to use the button for anything yet but know that it's there.

Development for me using Qt and VS2010 involves using VS to program my widgets and QtDesigner to create the UI layout.

You can open up your file.ui for designing by:
  • Double clicking it in your VS2010 Solution Explorer.
  • Or by opening QtDesigner directly, finding the file.ui of your project in Explorer, and using the designers opening dialog to go to that path and open it.
I normally use the 2nd longer direct approach.

While following the Zhao Wuluo walkthrough something to look out for is the mainwidget.cpp constructor:

MainWidget::MainWidget(QWidget *parent, Qt::WFlags flags)
 : QWidget(parent, flags),
 ui(new Ui::mainwidgetClass)
{
 ui->setupUi(this);
}


That's what my constructor looks like. The auto-generated class file lacked the ui(new Ui::mainwidgetClass) constructor call and this caused my GLWidget to throw an access violation error when being constructed itself. So don't do that, construct your ui.

Thoughts on beginning Qt:

It's nice. It can seem very overwhelming at first but I believe it's a matter of how you look at it. Let go of the idea of the GUI writing itself completely through the designer. Accept the idea that the entire endeavor is regular code and brackets programming with a nice designer tool to help where it can. Also, be sure to check out the "Qt Examples and Demos" app that comes installed with your SDK because running them and checking out their documentation in the QtAssistant has helped me a lot.

I will post more as I learn more. I hope this was helpful.