Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 :

C++
#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)
		//fatalError("PxCreateFoundation failed!");
	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.
Posted
Updated 15-Nov-15 21:17pm
v2
Comments
Member 12142188 16-Nov-15 3:02am    
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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900