mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-14 22:00:05 +00:00
add RenderInstancingDemo
allow to use OpenGL2 or OpenGL3 in same binary (will add command-line switch)
This commit is contained in:
parent
c7671779c2
commit
70221aeb3e
@ -29,10 +29,12 @@
|
||||
|
||||
#include "../bullet2/CollisionDetection/SupportFuncDemo.h"
|
||||
#include "../bullet2/BasicConcepts/CoordinateSystemDemo.h"
|
||||
|
||||
#include "../../Demos3/FiniteElementMethod/FiniteElementDemo.h"
|
||||
//#include "../../Demos3/bullet2/SoftDemo/SoftDemo.h"
|
||||
#include "../Geometry/SphereCreation.h"
|
||||
#include "../Geometry/DistributePoints.h"
|
||||
#include "../Geometry/RenderInstancingDemo.h"
|
||||
|
||||
#define MYCREATEFUNC(func) \
|
||||
static BulletDemoInterface* func##CreateFunc(CommonGraphicsApp* app)\
|
||||
@ -105,6 +107,7 @@ static BulletDemoEntry allDemos[]=
|
||||
{1,"SphereCreation", &SphereCreation::CreateFunc},
|
||||
{1,"DistributePoints", &DistributePoints::CreateFunc},
|
||||
{1,"Coordinate Frames", CoordinateFrameDemoPhysicsCreateFunc},
|
||||
{1,"Instanced Rendering", &RenderInstancingDemo::CreateFunc},
|
||||
// {0,"Soft Body", 0},
|
||||
|
||||
// {1,"Cloth1", SoftDemo::CreateFunc},
|
||||
|
@ -1,12 +1,9 @@
|
||||
//#include "OpenGLWindow/OpenGLInclude.h"
|
||||
#include "OpenGLWindow/OpenGLInclude.h"
|
||||
//#include "OpenGL/gl.h"
|
||||
//#define USE_OPENGL2
|
||||
#ifdef USE_OPENGL2
|
||||
#include "OpenGLWindow/SimpleOpenGL2App.h"
|
||||
#else
|
||||
|
||||
#include "OpenGLWindow/SimpleOpenGL2App.h"
|
||||
#include "OpenGLWindow/SimpleOpenGL3App.h"
|
||||
#endif
|
||||
|
||||
#include "OpenGLWindow/CommonRenderInterface.h"
|
||||
#ifdef __APPLE__
|
||||
@ -36,188 +33,10 @@
|
||||
#include "Bullet3AppSupport/GraphingTexture.h"
|
||||
|
||||
#include "OpenGLWindow/SimpleCamera.h"
|
||||
#include "OpenGLWindow/SimpleOpenGL2Renderer.h"
|
||||
|
||||
CommonGraphicsApp* app=0;
|
||||
#ifdef USE_OPENGL2
|
||||
struct TestRenderer : public CommonRenderInterface
|
||||
{
|
||||
int m_width;
|
||||
int m_height;
|
||||
SimpleCamera m_camera;
|
||||
|
||||
TestRenderer(int width, int height)
|
||||
:m_width(width),
|
||||
m_height(height)
|
||||
{
|
||||
|
||||
}
|
||||
virtual void init()
|
||||
{
|
||||
|
||||
}
|
||||
virtual void updateCamera(int upAxis)
|
||||
{
|
||||
float projection[16];
|
||||
float view[16];
|
||||
m_camera.setAspectRatio((float)m_width/(float)m_height);
|
||||
m_camera.update();
|
||||
m_camera.getCameraProjectionMatrix(projection);
|
||||
m_camera.getCameraViewMatrix(view);
|
||||
GLfloat projMat[16];
|
||||
GLfloat viewMat[16];
|
||||
for (int i=0;i<16;i++)
|
||||
{
|
||||
viewMat[i] = view[i];
|
||||
projMat[i] = projection[i];
|
||||
}
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMultMatrixf(projMat);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glMultMatrixf(viewMat);
|
||||
}
|
||||
virtual void removeAllInstances()
|
||||
{
|
||||
}
|
||||
virtual void setCameraDistance(float dist)
|
||||
{
|
||||
m_camera.setCameraDistance(dist);
|
||||
}
|
||||
virtual void setCameraPitch(float pitch)
|
||||
{
|
||||
m_camera.setCameraPitch(pitch);
|
||||
}
|
||||
virtual void setCameraTargetPosition(float x, float y, float z)
|
||||
{
|
||||
m_camera.setCameraTargetPosition(x,y,z);
|
||||
}
|
||||
|
||||
virtual void getCameraPosition(float cameraPos[4])
|
||||
{
|
||||
float pos[3];
|
||||
m_camera.getCameraPosition(pos);
|
||||
cameraPos[0] = pos[0];
|
||||
cameraPos[1] = pos[1];
|
||||
cameraPos[2] = pos[2];
|
||||
|
||||
}
|
||||
virtual void getCameraPosition(double cameraPos[4])
|
||||
{
|
||||
float pos[3];
|
||||
m_camera.getCameraPosition(pos);
|
||||
cameraPos[0] = pos[0];
|
||||
cameraPos[1] = pos[1];
|
||||
cameraPos[2] = pos[2];
|
||||
}
|
||||
|
||||
virtual void setCameraTargetPosition(float cameraPos[4])
|
||||
{
|
||||
m_camera.setCameraTargetPosition(cameraPos[0],cameraPos[1],cameraPos[2]);
|
||||
}
|
||||
virtual void getCameraTargetPosition(float cameraPos[4]) const
|
||||
{
|
||||
m_camera.getCameraTargetPosition(cameraPos);
|
||||
}
|
||||
virtual void getCameraTargetPosition(double cameraPos[4]) const
|
||||
{
|
||||
cameraPos[0] = 1;
|
||||
cameraPos[1] = 1;
|
||||
cameraPos[2] = 1;
|
||||
}
|
||||
|
||||
virtual void renderScene()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual int getScreenWidth()
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
virtual int getScreenHeight()
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
virtual int registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
virtual void drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize)
|
||||
{
|
||||
int pointStrideInFloats = pointStrideInBytes/4;
|
||||
glLineWidth(pointDrawSize);
|
||||
for (int i=0;i<numIndices;i+=2)
|
||||
{
|
||||
int index0 = indices[i];
|
||||
int index1 = indices[i+1];
|
||||
|
||||
btVector3 fromColor(color[0],color[1],color[2]);
|
||||
btVector3 toColor(color[0],color[1],color[2]);
|
||||
|
||||
btVector3 from(positions[index0*pointStrideInFloats],positions[index0*pointStrideInFloats+1],positions[index0*pointStrideInFloats+2]);
|
||||
btVector3 to(positions[index1*pointStrideInFloats],positions[index1*pointStrideInFloats+1],positions[index1*pointStrideInFloats+2]);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(fromColor.getX(), fromColor.getY(), fromColor.getZ());
|
||||
glVertex3d(from.getX(), from.getY(), from.getZ());
|
||||
glColor3f(toColor.getX(), toColor.getY(), toColor.getZ());
|
||||
glVertex3d(to.getX(), to.getY(), to.getZ());
|
||||
glEnd();
|
||||
|
||||
}
|
||||
}
|
||||
virtual void drawLine(const float from[4], const float to[4], const float color[4], float lineWidth)
|
||||
{
|
||||
glLineWidth(lineWidth);
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(color[0],color[1],color[2]);
|
||||
glVertex3d(from[0],from[1],from[2]);
|
||||
glVertex3d(to[0],to[1],to[2]);
|
||||
glEnd();
|
||||
}
|
||||
virtual int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex)
|
||||
{
|
||||
}
|
||||
virtual void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)
|
||||
{
|
||||
}
|
||||
virtual void writeTransforms()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual void drawLine(const double from[4], const double to[4], const double color[4], double lineWidth)
|
||||
{
|
||||
|
||||
}
|
||||
virtual void drawPoint(const float* position, const float color[4], float pointDrawSize)
|
||||
{
|
||||
}
|
||||
virtual void drawPoint(const double* position, const double color[4], double pointDrawSize)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void updateShape(int shapeIndex, const float* vertices)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void enableBlend(bool blend)
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
#endif //USE_OPENGL2
|
||||
b3gWindowInterface* s_window = 0;
|
||||
CommonParameterInterface* s_parameterInterface=0;
|
||||
CommonRenderInterface* s_instancingRenderer=0;
|
||||
@ -580,20 +399,24 @@ int main(int argc, char* argv[])
|
||||
b3Clock clock;
|
||||
|
||||
//float dt = 1./120.f;
|
||||
int width = 1024;
|
||||
int height=768;
|
||||
int width = 1024;
|
||||
int height=768;
|
||||
|
||||
// wci.m_resizeCallback = MyResizeCallback;
|
||||
|
||||
|
||||
#ifdef USE_OPENGL2
|
||||
app = new SimpleOpenGL2App("AllBullet2Demos",width,height);
|
||||
app->m_renderer = new TestRenderer(width,height);
|
||||
#else
|
||||
SimpleOpenGL3App* simpleApp = new SimpleOpenGL3App("AllBullet2Demos",width,height);
|
||||
app = simpleApp;
|
||||
#endif
|
||||
s_instancingRenderer = app->m_renderer;
|
||||
SimpleOpenGL3App* simpleApp=0;
|
||||
bool useOpenGL2=false;
|
||||
if (useOpenGL2)
|
||||
{
|
||||
app = new SimpleOpenGL2App("AllBullet2Demos",width,height);
|
||||
app->m_renderer = new SimpleOpenGL2Renderer(width,height);
|
||||
} else
|
||||
{
|
||||
simpleApp = new SimpleOpenGL3App("AllBullet2Demos",width,height);
|
||||
app = simpleApp;
|
||||
}
|
||||
|
||||
s_instancingRenderer = app->m_renderer;
|
||||
s_window = app->m_window;
|
||||
prevMouseMoveCallback = s_window->getMouseMoveCallback();
|
||||
s_window->setMouseMoveCallback(MyMouseMoveCallback);
|
||||
@ -627,12 +450,16 @@ int main(int argc, char* argv[])
|
||||
|
||||
gui = new GwenUserInterface;
|
||||
GL3TexLoader* myTexLoader = new GL3TexLoader;
|
||||
#ifdef USE_OPENGL2
|
||||
Gwen::Renderer::Base* gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
||||
#else
|
||||
sth_stash* fontstash=simpleApp->getFontStash();
|
||||
Gwen::Renderer::Base* gwenRenderer = new GwenOpenGL3CoreRenderer(simpleApp->m_primRenderer,fontstash,width,height,s_window->getRetinaScale(),myTexLoader);
|
||||
#endif
|
||||
|
||||
Gwen::Renderer::Base* gwenRenderer = 0;
|
||||
if (useOpenGL2)
|
||||
{
|
||||
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
||||
} else
|
||||
{
|
||||
sth_stash* fontstash=simpleApp->getFontStash();
|
||||
gwenRenderer = new GwenOpenGL3CoreRenderer(simpleApp->m_primRenderer,fontstash,width,height,s_window->getRetinaScale(),myTexLoader);
|
||||
}
|
||||
//
|
||||
|
||||
gui->init(width,height,gwenRenderer,s_window->getRetinaScale());
|
||||
@ -822,16 +649,16 @@ int main(int argc, char* argv[])
|
||||
if (!pauseSimulation)
|
||||
processProfileData(profWindow,false);
|
||||
{
|
||||
#ifdef USE_OPENGL2
|
||||
if (useOpenGL2)
|
||||
{
|
||||
saveOpenGLState(width,height);
|
||||
}
|
||||
#endif
|
||||
BT_PROFILE("Draw Gwen GUI");
|
||||
gui->draw(s_instancingRenderer->getScreenWidth(),s_instancingRenderer->getScreenHeight());
|
||||
#ifdef USE_OPENGL2
|
||||
restoreOpenGLState();
|
||||
#endif
|
||||
if (useOpenGL2)
|
||||
{
|
||||
restoreOpenGLState();
|
||||
}
|
||||
}
|
||||
}
|
||||
toggle=1-toggle;
|
||||
|
131
Demos3/Geometry/RenderInstancingDemo.h
Normal file
131
Demos3/Geometry/RenderInstancingDemo.h
Normal file
@ -0,0 +1,131 @@
|
||||
#ifndef RENDER_INSTANCING_DEMO_H
|
||||
#define RENDER_INSTANCING_DEMO_H
|
||||
|
||||
#include "Bullet3AppSupport/BulletDemoInterface.h"
|
||||
#include "OpenGLWindow/CommonGraphicsApp.h"
|
||||
#include "Bullet3Common/b3Quaternion.h"
|
||||
|
||||
|
||||
|
||||
///quick demo showing the right-handed coordinate system and positive rotations around each axis
|
||||
class RenderInstancingDemo : public BulletDemoInterface
|
||||
{
|
||||
CommonGraphicsApp* m_app;
|
||||
float m_x;
|
||||
float m_y;
|
||||
float m_z;
|
||||
b3AlignedObjectArray<int> m_movingInstances;
|
||||
enum
|
||||
{
|
||||
numCubesX = 20,
|
||||
numCubesY = 20
|
||||
};
|
||||
public:
|
||||
|
||||
RenderInstancingDemo(CommonGraphicsApp* app)
|
||||
:m_app(app),
|
||||
m_x(0),
|
||||
m_y(0),
|
||||
m_z(0)
|
||||
{
|
||||
m_app->setUpAxis(2);
|
||||
|
||||
{
|
||||
b3Vector3 extents=b3MakeVector3(100,100,100);
|
||||
extents[m_app->getUpAxis()]=1;
|
||||
|
||||
int xres = 20;
|
||||
int yres = 20;
|
||||
|
||||
b3Vector4 color0=b3MakeVector4(0.1, 0.1, 0.1,1);
|
||||
b3Vector4 color1=b3MakeVector4(0.6, 0.6, 0.6,1);
|
||||
m_app->registerGrid(xres, yres, color0, color1);
|
||||
}
|
||||
|
||||
{
|
||||
int boxId = m_app->registerCubeShape(0.1,0.1,0.1);
|
||||
|
||||
|
||||
|
||||
for (int i=-numCubesX/2;i<numCubesX/2;i++)
|
||||
{
|
||||
for (int j = -numCubesY/2;j<numCubesY/2;j++)
|
||||
{
|
||||
b3Vector3 pos=b3MakeVector3(i,j,j);
|
||||
pos[app->getUpAxis()] = 1;
|
||||
b3Quaternion orn(0,0,0,1);
|
||||
b3Vector4 color=b3MakeVector4(0.3,0.3,0.3,1);
|
||||
b3Vector3 scaling=b3MakeVector3(1,1,1);
|
||||
int instanceId = m_app->m_renderer->registerGraphicsInstance(boxId,pos,orn,color,scaling);
|
||||
m_movingInstances.push_back(instanceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_app->m_renderer->writeTransforms();
|
||||
}
|
||||
virtual ~RenderInstancingDemo()
|
||||
{
|
||||
m_app->m_renderer->enableBlend(false);
|
||||
}
|
||||
|
||||
static BulletDemoInterface* CreateFunc(CommonGraphicsApp* app)
|
||||
{
|
||||
return new RenderInstancingDemo(app);
|
||||
}
|
||||
virtual void physicsDebugDraw(int debugDrawMode)
|
||||
{
|
||||
|
||||
}
|
||||
virtual void initPhysics()
|
||||
{
|
||||
}
|
||||
virtual void exitPhysics()
|
||||
{
|
||||
|
||||
}
|
||||
virtual void stepSimulation(float deltaTime)
|
||||
{
|
||||
m_x+=0.01f;
|
||||
m_y+=0.01f;
|
||||
m_z+=0.01f;
|
||||
int index=0;
|
||||
for (int i=-numCubesX/2;i<numCubesX/2;i++)
|
||||
{
|
||||
for (int j = -numCubesY/2;j<numCubesY/2;j++)
|
||||
{
|
||||
b3Vector3 pos=b3MakeVector3(i,j,j);
|
||||
pos[m_app->getUpAxis()] = 1+1*b3Sin(m_x+i-j);
|
||||
float orn[4]={0,0,0,1};
|
||||
m_app->m_renderer->writeSingleInstanceTransformToCPU(pos,orn,m_movingInstances[index++]);
|
||||
}
|
||||
}
|
||||
m_app->m_renderer->writeTransforms();
|
||||
|
||||
}
|
||||
virtual void renderScene()
|
||||
{
|
||||
m_app->m_renderer->renderScene();
|
||||
}
|
||||
|
||||
|
||||
virtual void physicsDebugDraw()
|
||||
{
|
||||
|
||||
}
|
||||
virtual bool mouseMoveCallback(float x,float y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool mouseButtonCallback(int button, int state, float x, float y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool keyboardCallback(int key, int state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
#endif //RENDER_INSTANCING_DEMO_H
|
||||
|
@ -54,6 +54,7 @@ struct CommonRenderInterface
|
||||
virtual void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)=0;
|
||||
virtual void writeSingleInstanceColorToCPU(float* color, int srcIndex)=0;
|
||||
virtual void writeSingleInstanceColorToCPU(double* color, int srcIndex)=0;
|
||||
|
||||
virtual void writeTransforms()=0;
|
||||
virtual void enableBlend(bool blend)=0;
|
||||
};
|
||||
|
55
btgui/OpenGLWindow/OpenGL2Include.h
Normal file
55
btgui/OpenGLWindow/OpenGL2Include.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
Copyright (c) 2012 Advanced Micro Devices, Inc.
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
//Originally written by Erwin Coumans
|
||||
|
||||
|
||||
#ifndef __OPENGL_INCLUDE_H
|
||||
#define __OPENGL_INCLUDE_H
|
||||
|
||||
|
||||
//think different
|
||||
#if defined(__APPLE__) && !defined (VMDMESA)
|
||||
#include <OpenGL/OpenGL.h>
|
||||
#include <OpenGL/gl.h>
|
||||
#else
|
||||
|
||||
#include "GlewWindows/GL/glew.h"
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include <windows.h>
|
||||
//#include <GL/gl.h>
|
||||
//#include <GL/glu.h>
|
||||
#else
|
||||
//#include <GL/gl.h>
|
||||
//#include <GL/glu.h>
|
||||
#endif //_WINDOWS
|
||||
#endif //APPLE
|
||||
|
||||
//disable glGetError
|
||||
//#undef glGetError
|
||||
//#define glGetError MyGetError
|
||||
//
|
||||
//GLenum inline MyGetError()
|
||||
//{
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
///on Linux only glDrawElementsInstancedARB is defined?!?
|
||||
//#ifdef __linux
|
||||
//#define glDrawElementsInstanced glDrawElementsInstancedARB
|
||||
//
|
||||
//#endif //__linux
|
||||
|
||||
#endif //__OPENGL_INCLUDE_H
|
||||
|
@ -194,3 +194,14 @@ void SimpleOpenGL2App::drawText( const char* txt, int posX, int posY)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SimpleOpenGL2App::drawText3D( const char* txt, float posX, float posZY, float posZ, float size)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SimpleOpenGL2App::registerGrid(int xres, int yres, float color0[4], float color1[4])
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
@ -27,5 +27,9 @@ public:
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
virtual void drawText3D( const char* txt, float posX, float posZY, float posZ, float size);
|
||||
virtual void registerGrid(int xres, int yres, float color0[4], float color1[4]);
|
||||
|
||||
|
||||
};
|
||||
#endif //SIMPLE_OPENGL2_APP_H
|
199
btgui/OpenGLWindow/SimpleOpenGL2Renderer.cpp
Normal file
199
btgui/OpenGLWindow/SimpleOpenGL2Renderer.cpp
Normal file
@ -0,0 +1,199 @@
|
||||
|
||||
#include "SimpleOpenGL2Renderer.h"
|
||||
#include "OpenGL2Include.h"
|
||||
#include "Bullet3Common/b3Vector3.h"
|
||||
|
||||
|
||||
SimpleOpenGL2Renderer::SimpleOpenGL2Renderer(int width, int height)
|
||||
:m_width(width),
|
||||
m_height(height)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::init()
|
||||
{
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::updateCamera(int upAxis)
|
||||
{
|
||||
float projection[16];
|
||||
float view[16];
|
||||
m_camera.setAspectRatio((float)m_width/(float)m_height);
|
||||
m_camera.update();
|
||||
m_camera.getCameraProjectionMatrix(projection);
|
||||
m_camera.getCameraViewMatrix(view);
|
||||
GLfloat projMat[16];
|
||||
GLfloat viewMat[16];
|
||||
for (int i=0;i<16;i++)
|
||||
{
|
||||
viewMat[i] = view[i];
|
||||
projMat[i] = projection[i];
|
||||
}
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMultMatrixf(projMat);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glMultMatrixf(viewMat);
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::removeAllInstances()
|
||||
{
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::setCameraDistance(float dist)
|
||||
{
|
||||
m_camera.setCameraDistance(dist);
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::setCameraPitch(float pitch)
|
||||
{
|
||||
m_camera.setCameraPitch(pitch);
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::setCameraTargetPosition(float x, float y, float z)
|
||||
{
|
||||
m_camera.setCameraTargetPosition(x,y,z);
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::getCameraPosition(float cameraPos[4])
|
||||
{
|
||||
float pos[3];
|
||||
m_camera.getCameraPosition(pos);
|
||||
cameraPos[0] = pos[0];
|
||||
cameraPos[1] = pos[1];
|
||||
cameraPos[2] = pos[2];
|
||||
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::getCameraPosition(double cameraPos[4])
|
||||
{
|
||||
float pos[3];
|
||||
m_camera.getCameraPosition(pos);
|
||||
cameraPos[0] = pos[0];
|
||||
cameraPos[1] = pos[1];
|
||||
cameraPos[2] = pos[2];
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::setCameraTargetPosition(float cameraPos[4])
|
||||
{
|
||||
m_camera.setCameraTargetPosition(cameraPos[0],cameraPos[1],cameraPos[2]);
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::getCameraTargetPosition(float cameraPos[4]) const
|
||||
{
|
||||
m_camera.getCameraTargetPosition(cameraPos);
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::getCameraTargetPosition(double cameraPos[4]) const
|
||||
{
|
||||
cameraPos[0] = 1;
|
||||
cameraPos[1] = 1;
|
||||
cameraPos[2] = 1;
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::writeSingleInstanceColorToCPU(float* color, int srcIndex)
|
||||
{
|
||||
}
|
||||
void SimpleOpenGL2Renderer::writeSingleInstanceColorToCPU(double* color, int srcIndex)
|
||||
{
|
||||
|
||||
}
|
||||
void SimpleOpenGL2Renderer::getCameraViewMatrix(float viewMat[16]) const
|
||||
{
|
||||
b3Assert(0);
|
||||
}
|
||||
void SimpleOpenGL2Renderer::getCameraProjectionMatrix(float projMat[16]) const
|
||||
{
|
||||
b3Assert(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SimpleOpenGL2Renderer::renderScene()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int SimpleOpenGL2Renderer::registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SimpleOpenGL2Renderer::registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize)
|
||||
{
|
||||
int pointStrideInFloats = pointStrideInBytes/4;
|
||||
glLineWidth(pointDrawSize);
|
||||
for (int i=0;i<numIndices;i+=2)
|
||||
{
|
||||
int index0 = indices[i];
|
||||
int index1 = indices[i+1];
|
||||
|
||||
b3Vector3 fromColor = b3MakeVector3(color[0],color[1],color[2]);
|
||||
b3Vector3 toColor = b3MakeVector3(color[0],color[1],color[2]);
|
||||
|
||||
b3Vector3 from= b3MakeVector3(positions[index0*pointStrideInFloats],positions[index0*pointStrideInFloats+1],positions[index0*pointStrideInFloats+2]);
|
||||
b3Vector3 to= b3MakeVector3(positions[index1*pointStrideInFloats],positions[index1*pointStrideInFloats+1],positions[index1*pointStrideInFloats+2]);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(fromColor.getX(), fromColor.getY(), fromColor.getZ());
|
||||
glVertex3d(from.getX(), from.getY(), from.getZ());
|
||||
glColor3f(toColor.getX(), toColor.getY(), toColor.getZ());
|
||||
glVertex3d(to.getX(), to.getY(), to.getZ());
|
||||
glEnd();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::drawLine(const float from[4], const float to[4], const float color[4], float lineWidth)
|
||||
{
|
||||
glLineWidth(lineWidth);
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(color[0],color[1],color[2]);
|
||||
glVertex3d(from[0],from[1],from[2]);
|
||||
glVertex3d(to[0],to[1],to[2]);
|
||||
glEnd();
|
||||
}
|
||||
int SimpleOpenGL2Renderer::registerShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType, int textureIndex)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex)
|
||||
{
|
||||
}
|
||||
void SimpleOpenGL2Renderer::writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)
|
||||
{
|
||||
}
|
||||
void SimpleOpenGL2Renderer::writeTransforms()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SimpleOpenGL2Renderer::drawLine(const double from[4], const double to[4], const double color[4], double lineWidth)
|
||||
{
|
||||
|
||||
}
|
||||
void SimpleOpenGL2Renderer::drawPoint(const float* position, const float color[4], float pointDrawSize)
|
||||
{
|
||||
}
|
||||
void SimpleOpenGL2Renderer::drawPoint(const double* position, const double color[4], double pointDrawSize)
|
||||
{
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::updateShape(int shapeIndex, const float* vertices)
|
||||
{
|
||||
}
|
||||
|
||||
void SimpleOpenGL2Renderer::enableBlend(bool blend)
|
||||
{
|
||||
}
|
81
btgui/OpenGLWindow/SimpleOpenGL2Renderer.h
Normal file
81
btgui/OpenGLWindow/SimpleOpenGL2Renderer.h
Normal file
@ -0,0 +1,81 @@
|
||||
|
||||
#ifndef SIMPLE_OPENGL2_RENDERER_H
|
||||
#define SIMPLE_OPENGL2_RENDERER_H
|
||||
|
||||
#include "CommonRenderInterface.h"
|
||||
#include "SimpleCamera.h"
|
||||
|
||||
struct SimpleOpenGL2Renderer : public CommonRenderInterface
|
||||
{
|
||||
int m_width;
|
||||
int m_height;
|
||||
SimpleCamera m_camera;
|
||||
|
||||
SimpleOpenGL2Renderer(int width, int height);
|
||||
|
||||
virtual void init();
|
||||
|
||||
virtual void updateCamera(int upAxis);
|
||||
|
||||
virtual void removeAllInstances();
|
||||
|
||||
virtual void setCameraDistance(float dist);
|
||||
|
||||
virtual void setCameraPitch(float pitch);
|
||||
|
||||
virtual void setCameraTargetPosition(float x, float y, float z);
|
||||
|
||||
virtual void getCameraPosition(float cameraPos[4]);
|
||||
|
||||
virtual void getCameraPosition(double cameraPos[4]);
|
||||
|
||||
virtual void setCameraTargetPosition(float cameraPos[4]);
|
||||
|
||||
virtual void getCameraTargetPosition(float cameraPos[4]) const;
|
||||
|
||||
virtual void getCameraTargetPosition(double cameraPos[4]) const;
|
||||
|
||||
virtual void writeSingleInstanceColorToCPU(float* color, int srcIndex);
|
||||
virtual void writeSingleInstanceColorToCPU(double* color, int srcIndex);
|
||||
virtual void getCameraViewMatrix(float viewMat[16]) const;
|
||||
virtual void getCameraProjectionMatrix(float projMat[16]) const;
|
||||
|
||||
|
||||
virtual void renderScene();
|
||||
|
||||
virtual int getScreenWidth()
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
virtual int getScreenHeight()
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
virtual int registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling);
|
||||
|
||||
virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling);
|
||||
|
||||
virtual void drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize);
|
||||
|
||||
virtual void drawLine(const float from[4], const float to[4], const float color[4], float lineWidth);
|
||||
|
||||
virtual int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1);
|
||||
|
||||
virtual void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex);
|
||||
|
||||
virtual void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex);
|
||||
|
||||
virtual void writeTransforms();
|
||||
|
||||
virtual void drawLine(const double from[4], const double to[4], const double color[4], double lineWidth);
|
||||
|
||||
virtual void drawPoint(const float* position, const float color[4], float pointDrawSize);
|
||||
|
||||
virtual void drawPoint(const double* position, const double color[4], double pointDrawSize);
|
||||
|
||||
virtual void updateShape(int shapeIndex, const float* vertices);
|
||||
|
||||
virtual void enableBlend(bool blend);
|
||||
|
||||
};
|
||||
#endif //SIMPLE_OPENGL2_RENDERER_H
|
Loading…
Reference in New Issue
Block a user