Dear everyone,
i try to integrate physx3.3.2 sdk into opengl graphic library. I use the simplest code to implement ,however i fail to integrate it. I have seen physx3.3.2 PhysXGuide and PhysXAPI,but the problem can not be solved. Hoping everyone can give some guidence or can give me some help or material information about physx3.3.2`s demos. Give my best wishes to everyone.
my code is :
#include <iostream>
#include
#include <pxphysicsapi.h>
#include <pxdefaulterrorcallback.h>
#include <pxdefaultallocator.h>
using namespace std;
using namespace physx;
#pragma comment(lib, "PhysX3_x86.lib")
#pragma comment(lib, "PhysXProfileSDKDEBUG.lib")
#pragma comment(lib, "PhysX3CommonDEBUG_x86.lib")
#pragma comment(lib, "PhysX3ExtensionsDEBUG.lib")
const int WINDOW_WIDTH=1024,
WINDOW_HEIGHT=768;
static PxPhysics* gPhysicsSDK = NULL;
physx::PxFoundation* mFoundation = NULL;
static PxDefaultErrorCallback gDefaultErrorCallback;
static PxDefaultAllocator gDefaultAllocatorCallback;
void InitializePhysX() {
mFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gDefaultAllocatorCallback,
gDefaultErrorCallback);
if(!mFoundation)
cerr<<"PxCreateFoundation failed!."<<endl;
bool recordMemoryAllocations = true;
PxProfileZoneManager* mProfileZoneManager = &PxProfileZoneManager::createProfileZoneManager(mFoundation);
if(!mProfileZoneManager)
cerr<<"PxProfileZoneManager::createProfileZoneManager failed!"<<endl;
gPhysicsSDK = PxCreatePhysics(PX_PHYSICS_VERSION, *mFoundation,
PxTolerancesScale(), recordMemoryAllocations, mProfileZoneManager);
if(!gPhysicsSDK)
cerr<<" PxCreatePhysics failed"<<endl;
}
void ShutdownPhysX() {
gPhysicsSDK->release();
mFoundation->release();
}
void InitGL() {
}
void OnReshape(int nw, int nh) {
glViewport(0,0,nw, nh);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat)nw / (GLfloat)nh, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
}
void OnRender() {
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glutSwapBuffers();
}
void OnShutdown() {
ShutdownPhysX();
}
void main(int argc, char** argv) {
atexit(OnShutdown);
glutInit(&argc, argv);
InitGL();
InitializePhysX();
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
glutCreateWindow("GLUT PhysX3 Demo");
glutDisplayFunc(OnRender);
glutReshapeFunc(OnReshape);
glutMainLoop();
}
[EDIT: Code formatting and inserted below text from comment]
My abnormal appear at the PxCreatePhysics(PX_PHYSICS_VERSION, *mFoundation,
PxTolerancesScale(), recordMemoryAllocations, mProfileZoneManager) function ,and i debug the code found the program crash appear at the PxCreateBasePhysics(version, foundation, scale, trackOutstandingAllocations, profileZoneManager) function.