Wednesday, May 9, 2012

School Parallel Project: OpenGL + Havok + Intel TBB

So I recently had to create a project for my class on parallel computing. It was a semester long project (with lots of homework in between on things like OpenMP, P Threads, CUDA, MPI and OpenCL )and I just recently finished it. I turned it in yesterday but found more time to benchmark it this morning. I will post the project here soon in some way so you can see it for your self but for now here are some stats from my two machines...


  • Laptop - [AMD Phenom 2 N830 [3-Core] 2.10 GHz] [8GB Ram] [Windows 7 64bit] [ATI Mobility Radeon HD 4200]
    • Single Threaded: 10fps
    • Multi Threaded: 15fps
  • Desktop - [Intel i7 2600 [4-Core Hyperthreaded] 3.40 GHz] [16GB Ram] [Windows 7 64bit] [nVidia GeForce GTX 480]
    • Single Threaded: 19fps
    • Multi Threaded: 75fps
Holy crap does it scale well... gDebugger reports poor desktop utilization on my 5th and 7th cores but all the same it's a crazy improvement. 

I'll post more later. Go TBB and Havok!

Tuesday, May 8, 2012

Windows: Getting the Device Context without painful setup

So I use OpenGL a lot. Because of this I use GLFW a lot. GLFW is like GLUT or Free GLUT or SDL or SFML except it's not lame (not saying these kits are all lame but GLUT is lame and SDL is lame lol ). GLFW is a lot more light weight and for me easier to work with.

Using GLFW to create your window and context is painless. However there is no obvious way to get your window's context from GLFW once it's made. In my case, I needed the context for an OpenGL OpenCL interop.

To get the window handle and device context you can go right after your glfwInit() and glfwOpenWindow(...) and call...


HWND *ptr_hwnd = GetForegroundWindow();
HDC ptr_dc = GetDC( *ptr_hwnd );


And that should do it! No pain, some gain. So long window setup code hello actually doing wtf you wanted to make the window for.

Friday, May 4, 2012

Asus P8 Z68-V Pro/GEN3 Blue Screen of Death

I recently upgraded my desktop for development I'll be doing this summer. When starting up Windows 7 I got a quick BSOD followed by a restart. Forums reveal that this issue isn't uncommon but none of the solutions seemed to work for me. Combining them did though...


  • Make sure you have/get Corsair Vengeance ram. It's made for the board and even has the board's picture on the front of the product's box lol.
  • In the bios, go to the auto tuning for overclocking and switch from Auto or Manual to XMP.
  • Go to your Advanced settings and...
    • Turn off all Marvell stuff. It's crap. It won't work (didn't for me and doesn't for most it seems).
    • Switch the SATA from AHCI to IDE.
Doing that fixed everything for me. The machine then started up fine and so did Windows. Hope this helps.

Also, you may want to go into your msconfig > startup and turn off like all of the non-essential stuff. I believe I have old software setup for my old AMD processor. My new Intel isn't jiving with it. Turning those off made my system stable. You may also just want to get a new hard drive (or wipe your existing one).

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 )

gDEBugger you a good life

Debugging graphics can be a pain. It definitely takes an amount of skill and knowledge that comes to you slowly over whats perhaps a long period of practice. Seeing an ambiguous error pop up and knowing that it has something to do with a color inside of a texture on the graphics device is something that may not be obvious to some.

There exists an amazing gift from humanity to itself (specifically the amazing developers at Graphic Remedy ), and it is called gDEBugger. Simply put it is a must have tool that will change the way you develop OpenGL applications for the better, without question. It's like Pix for DirectX (but I think it may be older and thus the original).

Some of it's features include pausing/breaking execution, examining every texture/buffer active, a performance report of your number of OpenGL calls made a frame, frame rate, examining the depth buffer and adjusting the Z-Near/Far, inverting textures, a full report of every active uniform on the device, all shaders in use, which shader program is currently active (I even think you can edit them in real time for hot changes, haven't tried it though so don't quote me), and tons more things like bottleneck locating by either killing all graphics, setting the view port to a 1x1 stenciled pixel... tons of stuff. This tool is a must.

You can get it for FREE. It's free. That's insane: http://www.gremedy.com/.

So yea. Don't say I never gave you anything lol.

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.

Sunday, April 1, 2012

Havok Tutorial: A way to detect bullet collisions

Hey. This will be less of a tutorial and more of a "here's a way to do something".

One way you can detect your bullets hitting objects in Havok is through the use of Phantoms. These are aabb's that exist simply to report what collides with them (and to apply events to those colliding objects if you'd like). This makes Phantoms great for things like triggering events based on a player's location, and bullets.

Check out the demo at: Demo\Demos\Physics\Api\Dynamics\Phantoms\PhantomObject for example code on using Phantoms.

So for example, you can draw your bullets as particles, and maintain a phantom for each of these bullets. When a bullet phantom's collision list contains an enemy you can say doBulletHitEnemy() or whatever.