Featured Posts

8. Bump Mapping in GLSL8. Bump Mapping in GLSL Introduction Bump mapping is essential in todays computer games, and computer graphics in general. Would you like to know the best thing about it? It is extremely simple to implement. Bump mapping works...

Read more

Swiftless GLSL Shader DeveloperSwiftless GLSL Shader Developer Swiftless GLSL Shader Developer   Version 0.1a Currently Swiftless GLSL Shader Developer is in it's first public release, and is currently in alpha status, meaning it is not complete and may contain...

Read more

Wordpress Optimization Wordpress Website Optimizations Introduction Wordpress itself is a fairly wonderful tool. Since switching to it, I find it is a lot quicker to make changes to my website and it is also quicker to get...

Read more

36. OpenGL Framebuffers36. OpenGL Framebuffers Introduction Frame buffers are one of those mythical things that we have all heard of, but many beginner OpenGL developers avoid because there is not much information about them, and they can be confusing...

Read more

1. Terrain Class1. Terrain Class Terrain is one of those things that so far, hasn't been perfectly recreated in computer graphics. But it is almost there! Looking over a beautiful landscape can be one of the most amazing feelings in the...

Read more

  • Prev
  • Next

2. PhysX Windows

Posted on : 25-03-2010 | By : Swiftless | In : Physx

0

Jump To:
main.cpp Source
Download

Main.CPP File:

Now that we have our workspace setup for coding with the PhysX SDK, lets get a basic program up and running that incorporates OpenGL. I am going to start off with a base OpenGL program with a display function and reshape function, and the base GLUT code in our main function. The base of this program looks simply like this:

// #include <GLglut.h>
// #include <GLgl.h>

// void display(void){
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// glLoadIdentity();

// glutSwapBuffers();
// }

// void reshape(int w, int h){

// glViewport(0,0, (GLsizei)w, (GLsizei)h);
// glMatrixMode(GL_PROJECTION);
// glLoadIdentity();
// gluPerspective(60, (GLfloat)w / (GLfloat)h, 0.1f, 100.0f);
// glMatrixMode(GL_MODELVIEW);
// }

// int main(int argc, char** argv) {
// glutInit(&argc, argv);
// glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_STENCIL);
// glutInitWindowSize(500, 500);
// glutInitWindowPosition(100, 100);
// glutCreateWindow("Physics");

// glutDisplayFunc(display);
// glutIdleFunc(display);
// glutReshapeFunc(reshape);

// glutMainLoop();

// return 0;

// }

So lets go ahead and create a function to initialize our PhysX SDK with. I am going to call this initNX. This is going to contain the code from the previous tutorial for Physics SDK:

// void initNX(void){
// gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);
// }

Now that we have initialized the PhysX SDK, lets go ahead and create a cleanup function which I am going to call deinitNX:

// void deinitNX(void){
// gPhysicsSDK->release();
// }

These functions are going to be called from inside our main function:

// int main(int argc, char** argv) {
// glutInit(&argc, argv);

// glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_STENCIL);
// glutInitWindowSize(500, 500);
// glutInitWindowPosition(100, 100);
// glutCreateWindow("Physics");

// initNX();

// glutDisplayFunc(display);
// glutIdleFunc(display);
// glutReshapeFunc(reshape);

// glutMainLoop();

// deinitNX();

// return 0;
// }

In my opinion, this is looking much neater and much more like a program than the last tutorial. So next up we are going to create a virtual scene for our physics calculations to take place. Check it out here.

If you have any questions, just email me at swiftless@gmail.com

#include <stdio.h>

#include <GLglut.h>
#include <GLgl.h>

#include <PhysicsincludeNxPhysics.h>

#define NOMINMAX

#include <windows.h>

#pragma comment(lib,"PhysXLoader.lib")
#pragma comment(lib,"NxCharacter.lib")
#pragma comment(lib,"NxCooking.lib")
#pragma comment(lib,"NxExtensions.lib")

static NxPhysicsSDK* gPhysicsSDK = NULL;

void initNX(void){
gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);
}

void deinitNX(void){
gPhysicsSDK->release();

}

void display(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glLoadIdentity();

glutSwapBuffers();
}

void reshape(int w, int h){
glViewport(0,0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat)w / (GLfloat)h, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);

}

int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_STENCIL);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);

glutCreateWindow("Physics");

initNX();

glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);

glutMainLoop();

deinitNX();

return 0;
}

Download:

Download main.cpp Source Code for this Tutorial

VN:F [1.9.3_1094]
Please rate so I know where to improve the site. 1 means needs a lot of improvement, 10 means perfect. If you leave a low rating, please state why. I don't want people just coming to bash the site.
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Related posts:

  1. 5. PhysX Materials
  2. 3. PhysX Scenes
  3. 4. PhysX Parameters
  4. 1. PhysX Includes

Write a comment

Improve the web with Nofollow Reciprocity.