Merge pull request #271 from erwincoumans/master
btHingeConstraint to set/get ERP, refactor gfx backends (work-in-progress)
This commit is contained in:
51
btgui/OpenGLWindow/CommonGraphicsApp.h
Normal file
51
btgui/OpenGLWindow/CommonGraphicsApp.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef COMMON_GRAPHICS_APP_H
|
||||
#define COMMON_GRAPHICS_APP_H
|
||||
|
||||
struct DrawGridData
|
||||
{
|
||||
int gridSize;
|
||||
float upOffset;
|
||||
int upAxis;
|
||||
float gridColor[4];
|
||||
|
||||
DrawGridData()
|
||||
:gridSize(10),
|
||||
upOffset(0.001f),
|
||||
upAxis(1)
|
||||
{
|
||||
gridColor[0] = 0.6f;
|
||||
gridColor[1] = 0.6f;
|
||||
gridColor[2] = 0.6f;
|
||||
gridColor[3] = 1.f;
|
||||
}
|
||||
};
|
||||
|
||||
struct CommonGraphicsApp
|
||||
{
|
||||
CommonGraphicsApp()
|
||||
:m_window(0),
|
||||
m_renderer(0),
|
||||
m_parameterInterface(0)
|
||||
{
|
||||
}
|
||||
virtual ~CommonGraphicsApp()
|
||||
{
|
||||
}
|
||||
|
||||
class b3gWindowInterface* m_window;
|
||||
struct CommonRenderInterface* m_renderer;
|
||||
struct CommonParameterInterface* m_parameterInterface;
|
||||
|
||||
virtual void drawGrid(DrawGridData data=DrawGridData()) = 0;
|
||||
virtual void setUpAxis(int axis) = 0;
|
||||
virtual int getUpAxis() const = 0;
|
||||
|
||||
virtual void swapBuffer() = 0;
|
||||
virtual void drawText( const char* txt, int posX, int posY) = 0;
|
||||
|
||||
virtual int registerCubeShape(float halfExtentsX,float halfExtentsY, float halfExtentsZ)=0;
|
||||
virtual int registerGraphicsSphereShape(float radius, bool usePointSprites=true, int largeSphereThreshold=100, int mediumSphereThreshold=10)=0;
|
||||
};
|
||||
|
||||
|
||||
#endif //COMMON_GRAPHICS_APP_H
|
||||
53
btgui/OpenGLWindow/CommonRenderInterface.h
Normal file
53
btgui/OpenGLWindow/CommonRenderInterface.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef COMMON_RENDER_INTERFACE_H
|
||||
#define COMMON_RENDER_INTERFACE_H
|
||||
|
||||
enum
|
||||
{
|
||||
B3_GL_TRIANGLES = 1,
|
||||
B3_GL_POINTS
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
B3_DEFAULT_RENDERMODE=1,
|
||||
//B3_WIREFRAME_RENDERMODE,
|
||||
B3_CREATE_SHADOWMAP_RENDERMODE,
|
||||
B3_USE_SHADOWMAP_RENDERMODE,
|
||||
};
|
||||
|
||||
struct CommonRenderInterface
|
||||
{
|
||||
virtual void init()=0;
|
||||
virtual void updateCamera(int upAxis)=0;
|
||||
virtual void removeAllInstances() = 0;
|
||||
virtual void setCameraDistance(float dist) = 0;
|
||||
virtual void setCameraPitch(float pitch) = 0;
|
||||
virtual void setCameraTargetPosition(float x, float y, float z)=0;
|
||||
|
||||
|
||||
virtual void getCameraPosition(float cameraPos[4])=0;
|
||||
virtual void getCameraPosition(double cameraPos[4])=0;
|
||||
|
||||
virtual void setCameraTargetPosition(float cameraPos[4])=0;
|
||||
virtual void getCameraTargetPosition(float cameraPos[4]) const=0;
|
||||
virtual void getCameraTargetPosition(double cameraPos[4]) const=0;
|
||||
|
||||
virtual void renderScene()=0;
|
||||
|
||||
virtual int getScreenWidth() = 0;
|
||||
virtual int getScreenHeight() = 0;
|
||||
|
||||
virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling)=0;
|
||||
virtual int registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling)=0;
|
||||
virtual void drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize)=0;
|
||||
virtual void drawLine(const float from[4], const float to[4], const float color[4], float lineWidth) = 0;
|
||||
virtual void drawLine(const double from[4], const double to[4], const double color[4], double lineWidth) = 0;
|
||||
virtual int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1)=0;
|
||||
|
||||
virtual void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex)=0;
|
||||
virtual void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)=0;
|
||||
virtual void writeTransforms()=0;
|
||||
virtual void enableBlend(bool blend)=0;
|
||||
};
|
||||
#endif//COMMON_RENDER_INTERFACE_H
|
||||
|
||||
@@ -380,7 +380,8 @@ GLInstancingRenderer::GLInstancingRenderer(int maxNumObjectCapacity, int maxShap
|
||||
m_textureinitialized(false),
|
||||
m_screenWidth(0),
|
||||
m_screenHeight(0),
|
||||
m_upAxis(1)
|
||||
m_upAxis(1),
|
||||
m_enableBlend(false)
|
||||
{
|
||||
|
||||
m_data = new InternalDataRenderer;
|
||||
@@ -951,7 +952,7 @@ void GLInstancingRenderer::init()
|
||||
}
|
||||
|
||||
|
||||
void b3CreateFrustum(
|
||||
static void b3CreateFrustum(
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
@@ -984,14 +985,14 @@ void b3CreateFrustum(
|
||||
}
|
||||
|
||||
|
||||
void b3Matrix4x4Mul(GLfloat aIn[4][4], GLfloat bIn[4][4], GLfloat result[4][4])
|
||||
static void b3Matrix4x4Mul(GLfloat aIn[4][4], GLfloat bIn[4][4], GLfloat result[4][4])
|
||||
{
|
||||
for (int j=0;j<4;j++)
|
||||
for (int i=0;i<4;i++)
|
||||
result[j][i] = aIn[0][i] * bIn[j][0] + aIn[1][i] * bIn[j][1] + aIn[2][i] * bIn[j][2] + aIn[3][i] * bIn[j][3];
|
||||
}
|
||||
|
||||
void b3Matrix4x4Mul16(GLfloat aIn[16], GLfloat bIn[16], GLfloat result[16])
|
||||
static void b3Matrix4x4Mul16(GLfloat aIn[16], GLfloat bIn[16], GLfloat result[16])
|
||||
{
|
||||
for (int j=0;j<4;j++)
|
||||
for (int i=0;i<4;i++)
|
||||
@@ -999,7 +1000,7 @@ void b3Matrix4x4Mul16(GLfloat aIn[16], GLfloat bIn[16], GLfloat result[16])
|
||||
}
|
||||
|
||||
|
||||
void b3CreateDiagonalMatrix(GLfloat value, GLfloat result[4][4])
|
||||
static void b3CreateDiagonalMatrix(GLfloat value, GLfloat result[4][4])
|
||||
{
|
||||
for (int i=0;i<4;i++)
|
||||
{
|
||||
@@ -1016,7 +1017,7 @@ void b3CreateDiagonalMatrix(GLfloat value, GLfloat result[4][4])
|
||||
}
|
||||
}
|
||||
|
||||
void b3CreateOrtho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar, GLfloat result[4][4])
|
||||
static void b3CreateOrtho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar, GLfloat result[4][4])
|
||||
{
|
||||
b3CreateDiagonalMatrix(1.f,result);
|
||||
|
||||
@@ -1028,7 +1029,7 @@ void b3CreateOrtho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLf
|
||||
result[3][2] = - (zFar + zNear) / (zFar - zNear);
|
||||
}
|
||||
|
||||
void b3CreateLookAt(const b3Vector3& eye, const b3Vector3& center,const b3Vector3& up, GLfloat result[16])
|
||||
static void b3CreateLookAt(const b3Vector3& eye, const b3Vector3& center,const b3Vector3& up, GLfloat result[16])
|
||||
{
|
||||
b3Vector3 f = (center - eye).normalized();
|
||||
b3Vector3 u = up.normalized();
|
||||
@@ -1172,9 +1173,13 @@ float GLInstancingRenderer::getCameraPitch() const
|
||||
return m_data->m_azi;
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::setCameraTargetPosition(float x, float y, float z)
|
||||
{
|
||||
m_data->m_cameraTargetPosition = b3MakeVector3(x,y,z);
|
||||
}
|
||||
void GLInstancingRenderer::setCameraTargetPosition(float cameraPos[4])
|
||||
{
|
||||
m_data->m_cameraTargetPosition = b3MakeVector3(cameraPos[0],cameraPos[1],cameraPos[2]);
|
||||
setCameraTargetPosition(cameraPos[0],cameraPos[1],cameraPos[2]);
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::getCameraTargetPosition(float cameraPos[4]) const
|
||||
@@ -1437,6 +1442,14 @@ void GLInstancingRenderer::drawLines(const float* positions, const float color[4
|
||||
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::drawLine(const double fromIn[4], const double toIn[4], const double colorIn[4], double lineWidthIn)
|
||||
{
|
||||
float from[4]={float(fromIn[0]),float(fromIn[1]),float(fromIn[2]),float(fromIn[3])};
|
||||
float to[4]={float(toIn[0]),float(toIn[1]),float(toIn[2]),float(toIn[3])};
|
||||
float color[4]={float(colorIn[0]),float(colorIn[1]),float(colorIn[2]),float(colorIn[3])};
|
||||
float lineWidth=float(lineWidthIn);
|
||||
drawLine(from,to,color,lineWidth);
|
||||
}
|
||||
void GLInstancingRenderer::drawLine(const float from[4], const float to[4], const float color[4], float lineWidth)
|
||||
{
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
@@ -1589,14 +1602,14 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
||||
|
||||
// m_data->m_shadowMap->disable();
|
||||
// return;
|
||||
// glEnable(GL_CULL_FACE);
|
||||
// glCullFace(GL_BACK); // Cull back-facing triangles -> draw only front-facing triangles
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK); // Cull back-facing triangles -> draw only front-facing triangles
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
} else
|
||||
{
|
||||
glDisable(GL_CULL_FACE);
|
||||
//glCullFace(GL_BACK);
|
||||
//glDisable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
}
|
||||
|
||||
@@ -1747,7 +1760,7 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
glUseProgram(instancingShaderPointSprite);
|
||||
glUniformMatrix4fv(ProjectionMatrixPointSprite, 1, false, &projectionMatrix[0]);
|
||||
glUniformMatrix4fv(ModelViewMatrixPointSprite, 1, false, &modelviewMatrix[0]);
|
||||
glUniform1f(screenWidthPointSprite,m_screenWidth);
|
||||
glUniform1f(screenWidthPointSprite,float(m_screenWidth));
|
||||
|
||||
//glUniform1i(uniform_texture_diffusePointSprite, 0);
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
@@ -1790,6 +1803,12 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
case B3_USE_SHADOWMAP_RENDERMODE:
|
||||
{
|
||||
if (m_enableBlend)
|
||||
{
|
||||
glEnable (GL_BLEND);
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
glUseProgram(useShadowMapInstancingShader);
|
||||
glUniformMatrix4fv(useShadow_ProjectionMatrix, 1, false, &projectionMatrix[0]);
|
||||
glUniformMatrix4fv(useShadow_ModelViewMatrix, 1, false, &modelviewMatrix[0]);
|
||||
@@ -1804,7 +1823,12 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
glBindTexture(GL_TEXTURE_2D, m_data->m_shadowTexture);
|
||||
glUniform1i(useShadow_shadowMap,1);
|
||||
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances);
|
||||
break;
|
||||
if (m_enableBlend)
|
||||
{
|
||||
glDisable (GL_BLEND);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@ subject to the following restrictions:
|
||||
#define GL_INSTANCING_RENDERER_H
|
||||
|
||||
#include "Bullet3Common/b3AlignedObjectArray.h"
|
||||
#include "OpenGLWindow/CommonRenderInterface.h"
|
||||
|
||||
|
||||
void b3DefaultMouseButtonCallback( int button, int state, float x, float y);
|
||||
@@ -24,21 +25,9 @@ void b3DefaultMouseMoveCallback( float x, float y);
|
||||
void b3DefaultKeyboardCallback(int key, int state);
|
||||
void b3DefaultWheelCallback( float deltax, float deltay);
|
||||
|
||||
enum
|
||||
{
|
||||
B3_GL_TRIANGLES = 1,
|
||||
B3_GL_POINTS
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
B3_DEFAULT_RENDERMODE=1,
|
||||
//B3_WIREFRAME_RENDERMODE,
|
||||
B3_CREATE_SHADOWMAP_RENDERMODE,
|
||||
B3_USE_SHADOWMAP_RENDERMODE,
|
||||
};
|
||||
|
||||
class GLInstancingRenderer
|
||||
class GLInstancingRenderer : public CommonRenderInterface
|
||||
{
|
||||
|
||||
b3AlignedObjectArray<struct b3GraphicsInstance*> m_graphicsInstances;
|
||||
@@ -54,7 +43,8 @@ class GLInstancingRenderer
|
||||
int m_screenHeight;
|
||||
|
||||
int m_upAxis;
|
||||
|
||||
bool m_enableBlend;
|
||||
|
||||
void renderSceneInternal(int renderMode=B3_DEFAULT_RENDERMODE);
|
||||
|
||||
|
||||
@@ -62,29 +52,29 @@ public:
|
||||
GLInstancingRenderer(int m_maxObjectCapacity, int maxShapeCapacityInBytes = 56*1024*1024);
|
||||
virtual ~GLInstancingRenderer();
|
||||
|
||||
void init();
|
||||
virtual void init();
|
||||
|
||||
void renderScene();
|
||||
virtual void renderScene();
|
||||
|
||||
void InitShaders();
|
||||
void CleanupShaders();
|
||||
void removeAllInstances();
|
||||
|
||||
void updateShape(int shapeIndex, const float* vertices);
|
||||
virtual void updateShape(int shapeIndex, const float* vertices);
|
||||
|
||||
///vertices must be in the format x,y,z, nx,ny,nz, u,v
|
||||
int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1);
|
||||
virtual int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1);
|
||||
|
||||
int registerTexture(const unsigned char* texels, int width, int height);
|
||||
virtual int registerTexture(const unsigned char* texels, int width, int height);
|
||||
|
||||
///position x,y,z, quaternion x,y,z,w, color r,g,b,a, scaling x,y,z
|
||||
int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling);
|
||||
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 int registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling);
|
||||
|
||||
void writeTransforms();
|
||||
|
||||
void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex);
|
||||
void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)
|
||||
virtual void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex);
|
||||
virtual void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)
|
||||
{
|
||||
float pos[4];
|
||||
float orn[4];
|
||||
@@ -100,22 +90,23 @@ public:
|
||||
|
||||
}
|
||||
|
||||
void writeSingleInstanceTransformToGPU(float* position, float* orientation, int srcIndex);
|
||||
virtual void writeSingleInstanceTransformToGPU(float* position, float* orientation, int srcIndex);
|
||||
|
||||
void writeSingleInstanceColorToCPU(float* color, int srcIndex);
|
||||
virtual void writeSingleInstanceColorToCPU(float* color, int srcIndex);
|
||||
|
||||
void getMouseDirection(float* dir, int mouseX, int mouseY);
|
||||
virtual void getMouseDirection(float* dir, int mouseX, int mouseY);
|
||||
|
||||
struct GLInstanceRendererInternalData* getInternalData();
|
||||
|
||||
void drawLine(const float from[4], const float to[4], const float color[4], float lineWidth=1);
|
||||
void drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize);
|
||||
void drawPoints(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, float pointDrawSize);
|
||||
void drawPoint(const float* position, const float color[4], float pointSize=1);
|
||||
void updateCamera(int upAxis=1);
|
||||
virtual void drawLine(const float from[4], const float to[4], const float color[4], float lineWidth=1);
|
||||
virtual void drawLine(const double from[4], const double to[4], const double color[4], double lineWidth=1);
|
||||
virtual void drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize);
|
||||
virtual void drawPoints(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, float pointDrawSize);
|
||||
virtual void drawPoint(const float* position, const float color[4], float pointSize=1);
|
||||
virtual void updateCamera(int upAxis=1);
|
||||
|
||||
void getCameraPosition(float cameraPos[4]);
|
||||
void getCameraPosition(double cameraPos[4])
|
||||
virtual void getCameraPosition(float cameraPos[4]);
|
||||
virtual void getCameraPosition(double cameraPos[4])
|
||||
{
|
||||
float campos[4];
|
||||
getCameraPosition(campos);
|
||||
@@ -125,13 +116,14 @@ public:
|
||||
cameraPos[3] = campos[3];
|
||||
}
|
||||
|
||||
void setCameraDistance(float dist);
|
||||
float getCameraDistance() const;
|
||||
virtual void setCameraDistance(float dist);
|
||||
virtual float getCameraDistance() const;
|
||||
|
||||
//set the camera 'target'
|
||||
void setCameraTargetPosition(float cameraPos[4]);
|
||||
void getCameraTargetPosition(float cameraPos[4]) const;
|
||||
void getCameraTargetPosition(double cameraPos[4]) const
|
||||
virtual void setCameraTargetPosition(float x, float y, float z);
|
||||
virtual void setCameraTargetPosition(float cameraPos[4]);
|
||||
virtual void getCameraTargetPosition(float cameraPos[4]) const;
|
||||
virtual void getCameraTargetPosition(double cameraPos[4]) const
|
||||
{
|
||||
float campos[4];
|
||||
getCameraTargetPosition(campos);
|
||||
@@ -142,30 +134,34 @@ public:
|
||||
|
||||
}
|
||||
|
||||
void setCameraYaw(float yaw);
|
||||
void setCameraPitch(float pitch);
|
||||
float getCameraYaw() const;
|
||||
float getCameraPitch() const;
|
||||
virtual void setCameraYaw(float yaw);
|
||||
virtual void setCameraPitch(float pitch);
|
||||
virtual float getCameraYaw() const;
|
||||
virtual float getCameraPitch() const;
|
||||
|
||||
void resize(int width, int height);
|
||||
int getScreenWidth()
|
||||
virtual void resize(int width, int height);
|
||||
virtual int getScreenWidth()
|
||||
{
|
||||
return m_screenWidth;
|
||||
}
|
||||
int getScreenHeight()
|
||||
virtual int getScreenHeight()
|
||||
{
|
||||
return m_screenHeight;
|
||||
}
|
||||
|
||||
int getMaxShapeCapacity() const
|
||||
virtual int getMaxShapeCapacity() const
|
||||
{
|
||||
return m_maxShapeCapacityInBytes;
|
||||
}
|
||||
int getInstanceCapacity() const
|
||||
virtual int getInstanceCapacity() const
|
||||
{
|
||||
return m_maxNumObjectCapacity;
|
||||
}
|
||||
void enableShadowMap();
|
||||
virtual void enableShadowMap();
|
||||
virtual void enableBlend(bool blend)
|
||||
{
|
||||
m_enableBlend = blend;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef _GL_PRIMITIVE_RENDERER_H
|
||||
#define _GL_PRIMITIVE_RENDERER_H
|
||||
|
||||
#include "OpenGLInclude.h"
|
||||
//#include "OpenGLInclude.h"
|
||||
|
||||
class GLPrimitiveRenderer
|
||||
{
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "Gwen/Gwen.h"
|
||||
#include "Gwen/BaseRender.h"
|
||||
#include "GLPrimitiveRenderer.h"
|
||||
#include "OpenGLWindow/OpenGLInclude.h"
|
||||
|
||||
struct sth_stash;
|
||||
#include "fontstash.h"
|
||||
#include "Gwen/Texture.h"
|
||||
@@ -74,14 +76,14 @@ class GwenOpenGL3CoreRenderer : public Gwen::Renderer::Base
|
||||
GLuint m_fontTextureId;
|
||||
MyTextureLoader* m_textureLoader;
|
||||
public:
|
||||
GwenOpenGL3CoreRenderer (GLPrimitiveRenderer* primRender, sth_stash* font,float screenWidth, float screenHeight, float retinaScale)
|
||||
GwenOpenGL3CoreRenderer (GLPrimitiveRenderer* primRender, sth_stash* font,float screenWidth, float screenHeight, float retinaScale, MyTextureLoader* loader=0)
|
||||
:m_primitiveRenderer(primRender),
|
||||
m_font(font),
|
||||
m_screenWidth(screenWidth),
|
||||
m_screenHeight(screenHeight),
|
||||
m_retinaScale(retinaScale),
|
||||
m_useTrueTypeFont(false),
|
||||
m_textureLoader(0)
|
||||
m_textureLoader(loader)
|
||||
{
|
||||
///only enable true type fonts on Macbook Retina, it looks gorgeous
|
||||
if (retinaScale==2.0f)
|
||||
@@ -323,10 +325,6 @@ public:
|
||||
return Gwen::Renderer::Base::MeasureText(pFont,text);
|
||||
}
|
||||
|
||||
void setTextureLoader(MyTextureLoader* loader)
|
||||
{
|
||||
m_textureLoader = loader;
|
||||
}
|
||||
|
||||
virtual void LoadTexture( Gwen::Texture* pTexture )
|
||||
{
|
||||
|
||||
@@ -56,10 +56,25 @@ public:
|
||||
{
|
||||
m_keyboardCallback = keyboardCallback;
|
||||
}
|
||||
|
||||
virtual b3MouseMoveCallback getMouseMoveCallback()
|
||||
{
|
||||
return m_mouseMoveCallback;
|
||||
}
|
||||
virtual b3MouseButtonCallback getMouseButtonCallback()
|
||||
{
|
||||
return m_mouseButtonCallback;
|
||||
}
|
||||
virtual b3ResizeCallback getResizeCallback();
|
||||
virtual b3WheelCallback getWheelCallback()
|
||||
{
|
||||
return m_wheelCallback;
|
||||
}
|
||||
|
||||
b3KeyboardCallback getKeyboardCallback()
|
||||
{
|
||||
return m_keyboardCallback;
|
||||
}
|
||||
return m_keyboardCallback;
|
||||
}
|
||||
|
||||
void setWheelCallback (b3WheelCallback wheelCallback)
|
||||
{
|
||||
|
||||
@@ -53,6 +53,7 @@ void dumpInfo(void)
|
||||
-(float) GetWindowWidth;
|
||||
-(float) GetWindowHeight;
|
||||
-(void) setResizeCallback:(b3ResizeCallback) callback;
|
||||
-(b3ResizeCallback) getResizeCallback;
|
||||
@end
|
||||
|
||||
float loop;
|
||||
@@ -70,6 +71,11 @@ float loop;
|
||||
return m_lastHeight;
|
||||
}
|
||||
|
||||
-(b3ResizeCallback) getResizeCallback
|
||||
{
|
||||
return m_resizeCallback;
|
||||
}
|
||||
|
||||
-(void)setResizeCallback:(b3ResizeCallback)callback
|
||||
{
|
||||
m_resizeCallback = callback;
|
||||
@@ -1057,4 +1063,7 @@ void MacOpenGLWindow::setResizeCallback(b3ResizeCallback resizeCallback)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
b3ResizeCallback MacOpenGLWindow::getResizeCallback()
|
||||
{
|
||||
return [m_internalData->m_myview getResizeCallback];
|
||||
}
|
||||
|
||||
@@ -52,5 +52,5 @@ void main(void)
|
||||
if (visibility<0.6)
|
||||
visibility=0.6f;
|
||||
|
||||
color = vec4(ct * visibility, 1.f);//at * af);
|
||||
color = vec4(ct * visibility, fragment.color.w);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,6 @@ static const char* useShadowMapInstancingFragmentShader= \
|
||||
" if (visibility<0.6)\n"
|
||||
" visibility=0.6f;\n"
|
||||
" \n"
|
||||
" color = vec4(ct * visibility, 1.f);//at * af); \n"
|
||||
" color = vec4(ct * visibility, fragment.color.w);\n"
|
||||
"}\n"
|
||||
;
|
||||
|
||||
260
btgui/OpenGLWindow/SimpleCamera.cpp
Normal file
260
btgui/OpenGLWindow/SimpleCamera.cpp
Normal file
@@ -0,0 +1,260 @@
|
||||
#include "OpenGLWindow/SimpleCamera.h"
|
||||
|
||||
#include "Bullet3Common/b3Vector3.h"
|
||||
#include "Bullet3Common/b3Quaternion.h"
|
||||
#include "Bullet3Common/b3Matrix3x3.h"
|
||||
|
||||
struct SimpleCameraInternalData
|
||||
{
|
||||
SimpleCameraInternalData()
|
||||
:m_cameraTargetPosition(b3MakeVector3(0,0,0)),
|
||||
m_cameraDistance(20),
|
||||
m_cameraUp(b3MakeVector3(0,1,0)),
|
||||
m_cameraUpAxis(1),
|
||||
m_cameraForward(b3MakeVector3(1,0,0)),
|
||||
m_frustumZNear(1),
|
||||
m_frustumZFar(10000),
|
||||
m_yaw(20),
|
||||
m_pitch(0),
|
||||
m_aspect(1)
|
||||
{
|
||||
}
|
||||
b3Vector3 m_cameraTargetPosition;
|
||||
float m_cameraDistance;
|
||||
b3Vector3 m_cameraUp;
|
||||
b3Vector3 m_cameraForward;
|
||||
int m_cameraUpAxis;
|
||||
//the m_cameraPosition is a cached value, recomputed from other values
|
||||
b3Vector3 m_cameraPosition;
|
||||
float m_yaw;
|
||||
|
||||
float m_pitch;
|
||||
float m_aspect;
|
||||
float m_frustumZNear;
|
||||
float m_frustumZFar;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
SimpleCamera::SimpleCamera()
|
||||
{
|
||||
m_data = new SimpleCameraInternalData;
|
||||
}
|
||||
SimpleCamera::~SimpleCamera()
|
||||
{
|
||||
delete m_data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void b3CreateFrustum(
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
float top,
|
||||
float nearVal,
|
||||
float farVal,
|
||||
float frustum[16])
|
||||
{
|
||||
|
||||
frustum[0*4+0] = (float(2) * nearVal) / (right - left);
|
||||
frustum[0*4+1] = float(0);
|
||||
frustum[0*4+2] = float(0);
|
||||
frustum[0*4+3] = float(0);
|
||||
|
||||
frustum[1*4+0] = float(0);
|
||||
frustum[1*4+1] = (float(2) * nearVal) / (top - bottom);
|
||||
frustum[1*4+2] = float(0);
|
||||
frustum[1*4+3] = float(0);
|
||||
|
||||
frustum[2*4+0] = (right + left) / (right - left);
|
||||
frustum[2*4+1] = (top + bottom) / (top - bottom);
|
||||
frustum[2*4+2] = -(farVal + nearVal) / (farVal - nearVal);
|
||||
frustum[2*4+3] = float(-1);
|
||||
|
||||
frustum[3*4+0] = float(0);
|
||||
frustum[3*4+1] = float(0);
|
||||
frustum[3*4+2] = -(float(2) * farVal * nearVal) / (farVal - nearVal);
|
||||
frustum[3*4+3] = float(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void b3CreateDiagonalMatrix(float value, float result[4][4])
|
||||
{
|
||||
for (int i=0;i<4;i++)
|
||||
{
|
||||
for (int j=0;j<4;j++)
|
||||
{
|
||||
if (i==j)
|
||||
{
|
||||
result[i][j] = value;
|
||||
} else
|
||||
{
|
||||
result[i][j] = 0.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void b3CreateOrtho(float left, float right, float bottom, float top, float zNear, float zFar, float result[4][4])
|
||||
{
|
||||
b3CreateDiagonalMatrix(1.f,result);
|
||||
|
||||
result[0][0] = 2.f / (right - left);
|
||||
result[1][1] = 2.f / (top - bottom);
|
||||
result[2][2] = - 2.f / (zFar - zNear);
|
||||
result[3][0] = - (right + left) / (right - left);
|
||||
result[3][1] = - (top + bottom) / (top - bottom);
|
||||
result[3][2] = - (zFar + zNear) / (zFar - zNear);
|
||||
}
|
||||
|
||||
static void b3CreateLookAt(const b3Vector3& eye, const b3Vector3& center,const b3Vector3& up, float result[16])
|
||||
{
|
||||
b3Vector3 f = (center - eye).normalized();
|
||||
b3Vector3 u = up.normalized();
|
||||
b3Vector3 s = (f.cross(u)).normalized();
|
||||
u = s.cross(f);
|
||||
|
||||
result[0*4+0] = s.x;
|
||||
result[1*4+0] = s.y;
|
||||
result[2*4+0] = s.z;
|
||||
|
||||
result[0*4+1] = u.x;
|
||||
result[1*4+1] = u.y;
|
||||
result[2*4+1] = u.z;
|
||||
|
||||
result[0*4+2] =-f.x;
|
||||
result[1*4+2] =-f.y;
|
||||
result[2*4+2] =-f.z;
|
||||
|
||||
result[0*4+3] = 0.f;
|
||||
result[1*4+3] = 0.f;
|
||||
result[2*4+3] = 0.f;
|
||||
|
||||
result[3*4+0] = -s.dot(eye);
|
||||
result[3*4+1] = -u.dot(eye);
|
||||
result[3*4+2] = f.dot(eye);
|
||||
result[3*4+3] = 1.f;
|
||||
}
|
||||
|
||||
void SimpleCamera::setCameraUpAxis(int upAxis)
|
||||
{
|
||||
m_data->m_cameraUpAxis = upAxis;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void SimpleCamera::update()
|
||||
{
|
||||
|
||||
int forwardAxis(-1);
|
||||
switch (m_data->m_cameraUpAxis)
|
||||
{
|
||||
case 1:
|
||||
forwardAxis = 2;
|
||||
m_data->m_cameraUp = b3MakeVector3(0,1,0);
|
||||
//gLightPos = b3MakeVector3(-50.f,100,30);
|
||||
break;
|
||||
case 2:
|
||||
forwardAxis = 1;
|
||||
m_data->m_cameraUp = b3MakeVector3(0,0,1);
|
||||
//gLightPos = b3MakeVector3(-50.f,30,100);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
b3Assert(0);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
b3Vector3 eyePos = b3MakeVector3(0,0,0);
|
||||
eyePos[forwardAxis] = -m_data->m_cameraDistance;
|
||||
|
||||
m_data->m_cameraForward = b3MakeVector3(eyePos[0],eyePos[1],eyePos[2]);
|
||||
if (m_data->m_cameraForward.length2() < B3_EPSILON)
|
||||
{
|
||||
m_data->m_cameraForward.setValue(1.f,0.f,0.f);
|
||||
} else
|
||||
{
|
||||
m_data->m_cameraForward.normalize();
|
||||
}
|
||||
|
||||
|
||||
// m_azi=m_azi+0.01;
|
||||
b3Scalar rele = m_data->m_yaw * b3Scalar(0.01745329251994329547);// rads per deg
|
||||
b3Scalar razi = m_data->m_pitch * b3Scalar(0.01745329251994329547);// rads per deg
|
||||
|
||||
|
||||
b3Quaternion rot(m_data->m_cameraUp,razi);
|
||||
|
||||
|
||||
b3Vector3 right = m_data->m_cameraUp.cross(m_data->m_cameraForward);
|
||||
b3Quaternion roll(right,-rele);
|
||||
|
||||
eyePos = b3Matrix3x3(rot) * b3Matrix3x3(roll) * eyePos;
|
||||
|
||||
m_data->m_cameraPosition = eyePos;
|
||||
m_data->m_cameraPosition+= m_data->m_cameraTargetPosition;
|
||||
|
||||
}
|
||||
|
||||
void SimpleCamera::getCameraProjectionMatrix(float projectionMatrix[16]) const
|
||||
{
|
||||
b3CreateFrustum(-m_data->m_aspect * m_data->m_frustumZNear, m_data->m_aspect * m_data->m_frustumZNear, -m_data->m_frustumZNear,m_data->m_frustumZNear, m_data->m_frustumZNear, m_data->m_frustumZFar,projectionMatrix);
|
||||
}
|
||||
void SimpleCamera::getCameraViewMatrix(float viewMatrix[16]) const
|
||||
{
|
||||
b3CreateLookAt(m_data->m_cameraPosition,m_data->m_cameraTargetPosition,m_data->m_cameraUp,viewMatrix);
|
||||
}
|
||||
|
||||
void SimpleCamera::getCameraTargetPosition(float pos[3]) const
|
||||
{
|
||||
pos[0] =m_data->m_cameraTargetPosition[0];
|
||||
pos[1] =m_data->m_cameraTargetPosition[1];
|
||||
pos[2] =m_data->m_cameraTargetPosition[2];
|
||||
}
|
||||
void SimpleCamera::getCameraPosition(float pos[3]) const
|
||||
{
|
||||
pos[0] =m_data->m_cameraPosition[0];
|
||||
pos[1] =m_data->m_cameraPosition[1];
|
||||
pos[2] =m_data->m_cameraPosition[2];
|
||||
}
|
||||
|
||||
void SimpleCamera::setCameraTargetPosition(float x,float y,float z)
|
||||
{
|
||||
m_data->m_cameraTargetPosition.setValue(x,y,z);
|
||||
update();
|
||||
}
|
||||
void SimpleCamera::setCameraDistance(float dist)
|
||||
{
|
||||
m_data->m_cameraDistance = dist;
|
||||
update();
|
||||
}
|
||||
void SimpleCamera::setCameraUpVector(float x,float y ,float z)
|
||||
{
|
||||
m_data->m_cameraUp.setValue(x,y,z);
|
||||
update();
|
||||
}
|
||||
|
||||
void SimpleCamera::setCameraYaw(float yaw)
|
||||
{
|
||||
m_data->m_yaw = yaw;
|
||||
update();
|
||||
}
|
||||
|
||||
void SimpleCamera::setCameraPitch(float pitch)
|
||||
{
|
||||
m_data->m_pitch = pitch;
|
||||
update();
|
||||
}
|
||||
|
||||
void SimpleCamera::setAspectRatio(float ratio)
|
||||
{
|
||||
m_data->m_aspect = ratio;
|
||||
update();
|
||||
}
|
||||
36
btgui/OpenGLWindow/SimpleCamera.h
Normal file
36
btgui/OpenGLWindow/SimpleCamera.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef SIMPLE_CAMERA_H
|
||||
#define SIMPLE_CAMERA_H
|
||||
|
||||
struct CommonCameraInterface
|
||||
{
|
||||
virtual void getCameraProjectionMatrix(float m[16])const = 0;
|
||||
virtual void getCameraViewMatrix(float m[16]) const = 0;
|
||||
};
|
||||
|
||||
struct SimpleCamera : public CommonCameraInterface
|
||||
{
|
||||
struct SimpleCameraInternalData* m_data;
|
||||
|
||||
SimpleCamera();
|
||||
virtual ~SimpleCamera();
|
||||
|
||||
void update();
|
||||
virtual void getCameraProjectionMatrix(float m[16]) const;
|
||||
virtual void getCameraViewMatrix(float m[16]) const;
|
||||
|
||||
virtual void getCameraTargetPosition(float pos[3]) const;
|
||||
virtual void getCameraPosition(float pos[3]) const;
|
||||
|
||||
virtual void setCameraTargetPosition(float x,float y,float z);
|
||||
virtual void setCameraDistance(float dist);
|
||||
virtual void setCameraUpVector(float x,float y, float z);
|
||||
///the setCameraUpAxis will call the 'setCameraUpVector' and 'setCameraForwardVector'
|
||||
virtual void setCameraUpAxis(int axis);
|
||||
virtual void setCameraYaw(float yaw);
|
||||
|
||||
virtual void setCameraPitch(float pitch);
|
||||
virtual void setAspectRatio(float ratio);
|
||||
|
||||
};
|
||||
|
||||
#endif //SIMPLE_CAMERA_H
|
||||
196
btgui/OpenGLWindow/SimpleOpenGL2App.cpp
Normal file
196
btgui/OpenGLWindow/SimpleOpenGL2App.cpp
Normal file
@@ -0,0 +1,196 @@
|
||||
#include "OpenGLWindow/SimpleOpenGL2App.h"
|
||||
#include "OpenGLWindow/OpenGLInclude.h"
|
||||
|
||||
#include "Bullet3Common/b3Logging.h"//b3Assert?
|
||||
#include "Bullet3Common/b3Scalar.h"
|
||||
#include "Bullet3Common/b3AlignedObjectArray.h"
|
||||
#include "Bullet3Common/b3Vector3.h"
|
||||
|
||||
|
||||
#include "stdlib.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include "OpenGLWindow/MacOpenGLWindow.h"
|
||||
#else
|
||||
|
||||
#include "OpenGLWindow/GlewWindows/GL/glew.h"
|
||||
//#include "GL/glew.h"
|
||||
#ifdef _WIN32
|
||||
#include "OpenGLWindow/Win32OpenGLWindow.h"
|
||||
#else
|
||||
//let's cross the fingers it is Linux/X11
|
||||
#include "OpenGLWindow/X11OpenGLWindow.h"
|
||||
#endif //_WIN32
|
||||
#endif//__APPLE__
|
||||
#include <stdio.h>
|
||||
#include "OpenGLWindow/CommonRenderInterface.h"
|
||||
|
||||
struct SimpleOpenGL2AppInternalData
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
SimpleOpenGL2App::SimpleOpenGL2App(const char* title, int width, int height)
|
||||
{
|
||||
m_data = new SimpleOpenGL2AppInternalData;
|
||||
|
||||
m_window = new b3gDefaultOpenGLWindow();
|
||||
b3gWindowConstructionInfo ci;
|
||||
ci.m_title = title;
|
||||
ci.m_openglVersion = 2;
|
||||
ci.m_width = width;
|
||||
ci.m_height = height;
|
||||
m_window->createWindow(ci);
|
||||
|
||||
m_window->setWindowTitle(title);
|
||||
|
||||
#ifndef __APPLE__
|
||||
#ifndef _WIN32
|
||||
//some Linux implementations need the 'glewExperimental' to be true
|
||||
glewExperimental = GL_TRUE;
|
||||
#endif
|
||||
|
||||
|
||||
if (glewInit() != GLEW_OK)
|
||||
{
|
||||
b3Error("glewInit failed");
|
||||
exit(1);
|
||||
}
|
||||
if (!GLEW_VERSION_2_1) // check that the machine supports the 2.1 API.
|
||||
{
|
||||
b3Error("GLEW_VERSION_2_1 needs to support 2_1");
|
||||
exit(1); // or handle the error in a nicer way
|
||||
}
|
||||
|
||||
#endif
|
||||
glGetError();//don't remove this call, it is needed for Ubuntu
|
||||
glClearColor(0.9,0.9,1,1);
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
//m_primRenderer = new GLPrimitiveRenderer(width,height);
|
||||
m_parameterInterface = 0;
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
//m_instancingRenderer = new GLInstancingRenderer(128*1024,32*1024*1024);
|
||||
//m_instancingRenderer->init();
|
||||
//m_instancingRenderer->resize(width,height);
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
//m_instancingRenderer->InitShaders();
|
||||
|
||||
}
|
||||
|
||||
SimpleOpenGL2App::~SimpleOpenGL2App()
|
||||
{
|
||||
delete m_data;
|
||||
}
|
||||
|
||||
void SimpleOpenGL2App::drawGrid(DrawGridData data)
|
||||
{
|
||||
int gridSize = data.gridSize;
|
||||
float upOffset = data.upOffset;
|
||||
int upAxis = data.upAxis;
|
||||
float gridColor[4];
|
||||
gridColor[0] = data.gridColor[0];
|
||||
gridColor[1] = data.gridColor[1];
|
||||
gridColor[2] = data.gridColor[2];
|
||||
gridColor[3] = data.gridColor[3];
|
||||
|
||||
int sideAxis=-1;
|
||||
int forwardAxis=-1;
|
||||
|
||||
switch (upAxis)
|
||||
{
|
||||
case 1:
|
||||
forwardAxis=2;
|
||||
sideAxis=0;
|
||||
break;
|
||||
case 2:
|
||||
forwardAxis=1;
|
||||
sideAxis=0;
|
||||
break;
|
||||
default:
|
||||
b3Assert(0);
|
||||
};
|
||||
//b3Vector3 gridColor = b3MakeVector3(0.5,0.5,0.5);
|
||||
|
||||
b3AlignedObjectArray<unsigned int> indices;
|
||||
b3AlignedObjectArray<b3Vector3> vertices;
|
||||
int lineIndex=0;
|
||||
for(int i=-gridSize;i<=gridSize;i++)
|
||||
{
|
||||
{
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
b3Vector3 from = b3MakeVector3(0,0,0);
|
||||
from[sideAxis] = float(i);
|
||||
from[upAxis] = upOffset;
|
||||
from[forwardAxis] = float(-gridSize);
|
||||
b3Vector3 to=b3MakeVector3(0,0,0);
|
||||
to[sideAxis] = float(i);
|
||||
to[upAxis] = upOffset;
|
||||
to[forwardAxis] = float(gridSize);
|
||||
vertices.push_back(from);
|
||||
indices.push_back(lineIndex++);
|
||||
vertices.push_back(to);
|
||||
indices.push_back(lineIndex++);
|
||||
// m_renderer->drawLine(from,to,gridColor);
|
||||
}
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
{
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
b3Vector3 from=b3MakeVector3(0,0,0);
|
||||
from[sideAxis] = float(-gridSize);
|
||||
from[upAxis] = upOffset;
|
||||
from[forwardAxis] = float(i);
|
||||
b3Vector3 to=b3MakeVector3(0,0,0);
|
||||
to[sideAxis] = float(gridSize);
|
||||
to[upAxis] = upOffset;
|
||||
to[forwardAxis] = float(i);
|
||||
vertices.push_back(from);
|
||||
indices.push_back(lineIndex++);
|
||||
vertices.push_back(to);
|
||||
indices.push_back(lineIndex++);
|
||||
// m_renderer->drawLine(from,to,gridColor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
m_renderer->drawLines(&vertices[0].x,
|
||||
gridColor,
|
||||
vertices.size(),sizeof(b3Vector3),&indices[0],indices.size(),1);
|
||||
|
||||
|
||||
m_renderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(1,0,0),b3MakeVector3(1,0,0),3);
|
||||
m_renderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(0,1,0),b3MakeVector3(0,1,0),3);
|
||||
m_renderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(0,0,1),b3MakeVector3(0,0,1),3);
|
||||
|
||||
// void GLInstancingRenderer::drawPoints(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, float pointDrawSize)
|
||||
|
||||
//we don't use drawPoints because all points would have the same color
|
||||
// b3Vector3 points[3] = { b3MakeVector3(1, 0, 0), b3MakeVector3(0, 1, 0), b3MakeVector3(0, 0, 1) };
|
||||
// m_instancingRenderer->drawPoints(&points[0].x, b3MakeVector3(1, 0, 0), 3, sizeof(b3Vector3), 6);
|
||||
}
|
||||
void SimpleOpenGL2App::setUpAxis(int axis)
|
||||
{
|
||||
}
|
||||
int SimpleOpenGL2App::getUpAxis() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void SimpleOpenGL2App::swapBuffer()
|
||||
{
|
||||
m_window->endRendering();
|
||||
m_window->startRendering();
|
||||
|
||||
}
|
||||
void SimpleOpenGL2App::drawText( const char* txt, int posX, int posY)
|
||||
{
|
||||
|
||||
}
|
||||
31
btgui/OpenGLWindow/SimpleOpenGL2App.h
Normal file
31
btgui/OpenGLWindow/SimpleOpenGL2App.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef SIMPLE_OPENGL2_APP_H
|
||||
#define SIMPLE_OPENGL2_APP_H
|
||||
|
||||
#include "OpenGLWindow/CommonGraphicsApp.h"
|
||||
|
||||
class SimpleOpenGL2App : public CommonGraphicsApp
|
||||
{
|
||||
protected:
|
||||
struct SimpleOpenGL2AppInternalData* m_data;
|
||||
|
||||
public:
|
||||
SimpleOpenGL2App(const char* title, int width, int height);
|
||||
virtual ~SimpleOpenGL2App();
|
||||
|
||||
virtual void drawGrid(DrawGridData data=DrawGridData());
|
||||
virtual void setUpAxis(int axis);
|
||||
virtual int getUpAxis() const;
|
||||
|
||||
virtual void swapBuffer();
|
||||
virtual void drawText( const char* txt, int posX, int posY);
|
||||
|
||||
virtual int registerCubeShape(float halfExtentsX,float halfExtentsY, float halfExtentsZ)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
virtual int registerGraphicsSphereShape(float radius, bool usePointSprites, int largeSphereThreshold, int mediumSphereThreshold)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
#endif //SIMPLE_OPENGL2_APP_H
|
||||
@@ -140,6 +140,7 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height)
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
m_instancingRenderer = new GLInstancingRenderer(128*1024,32*1024*1024);
|
||||
m_renderer = m_instancingRenderer ;
|
||||
m_instancingRenderer->init();
|
||||
m_instancingRenderer->resize(width,height);
|
||||
|
||||
|
||||
@@ -5,33 +5,16 @@
|
||||
#include "OpenGLWindow/GLPrimitiveRenderer.h"
|
||||
#include "OpenGLWindow/b3gWindowInterface.h"
|
||||
|
||||
struct DrawGridData
|
||||
{
|
||||
int gridSize;
|
||||
float upOffset;
|
||||
int upAxis;
|
||||
float gridColor[4];
|
||||
#include "OpenGLWindow/CommonGraphicsApp.h"
|
||||
|
||||
DrawGridData()
|
||||
:gridSize(10),
|
||||
upOffset(0.001f),
|
||||
upAxis(1)
|
||||
{
|
||||
gridColor[0] = 0.6f;
|
||||
gridColor[1] = 0.6f;
|
||||
gridColor[2] = 0.6f;
|
||||
gridColor[3] = 1.f;
|
||||
}
|
||||
};
|
||||
|
||||
struct SimpleOpenGL3App
|
||||
struct SimpleOpenGL3App : public CommonGraphicsApp
|
||||
{
|
||||
struct SimpleInternalData* m_data;
|
||||
|
||||
class b3gWindowInterface* m_window;
|
||||
class GLPrimitiveRenderer* m_primRenderer;
|
||||
class GLInstancingRenderer* m_instancingRenderer;
|
||||
struct CommonParameterInterface* m_parameterInterface;
|
||||
|
||||
|
||||
SimpleOpenGL3App(const char* title, int width,int height);
|
||||
virtual ~SimpleOpenGL3App();
|
||||
@@ -43,11 +26,11 @@ struct SimpleOpenGL3App
|
||||
void dumpFramesToVideo(const char* mp4Filename);
|
||||
|
||||
void drawGrid(DrawGridData data=DrawGridData());
|
||||
void setUpAxis(int axis);
|
||||
int getUpAxis() const;
|
||||
virtual void setUpAxis(int axis);
|
||||
virtual int getUpAxis() const;
|
||||
|
||||
void swapBuffer();
|
||||
void drawText( const char* txt, int posX, int posY);
|
||||
virtual void swapBuffer();
|
||||
virtual void drawText( const char* txt, int posX, int posY);
|
||||
struct sth_stash* getFontStash();
|
||||
|
||||
|
||||
|
||||
@@ -46,8 +46,13 @@ void Win32OpenGLWindow::enableOpenGL()
|
||||
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||
pfd.cColorBits = 32;
|
||||
pfd.cDepthBits = 16;
|
||||
pfd.cStencilBits = 1;
|
||||
pfd.cRedBits = 8;
|
||||
pfd.cGreenBits = 8;
|
||||
pfd.cBlueBits = 8;
|
||||
pfd.cAlphaBits = 8;
|
||||
|
||||
pfd.cDepthBits = 24;
|
||||
pfd.cStencilBits = 8;//1;
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
format = ChoosePixelFormat( m_data->m_hDC, &pfd );
|
||||
SetPixelFormat( m_data->m_hDC, format, &pfd );
|
||||
@@ -115,15 +120,15 @@ void Win32OpenGLWindow::closeWindow()
|
||||
void Win32OpenGLWindow::startRendering()
|
||||
{
|
||||
pumpMessage();
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //clear buffers
|
||||
//don't clear all 3 buffers because some AMD drivers are buggy
|
||||
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
//glCullFace(GL_BACK);
|
||||
//glFrontFace(GL_CCW);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -709,5 +709,21 @@ b3KeyboardCallback Win32Window::getKeyboardCallback()
|
||||
return m_data->m_keyboardCallback;
|
||||
}
|
||||
|
||||
b3MouseMoveCallback Win32Window::getMouseMoveCallback()
|
||||
{
|
||||
return m_data->m_mouseMoveCallback;
|
||||
}
|
||||
b3MouseButtonCallback Win32Window::getMouseButtonCallback()
|
||||
{
|
||||
return m_data->m_mouseButtonCallback;
|
||||
}
|
||||
b3ResizeCallback Win32Window::getResizeCallback()
|
||||
{
|
||||
return m_data->m_resizeCallback;
|
||||
}
|
||||
b3WheelCallback Win32Window::getWheelCallback()
|
||||
{
|
||||
return m_data->m_wheelCallback;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,11 @@ public:
|
||||
virtual void setResizeCallback(b3ResizeCallback resizeCallback);
|
||||
virtual void setWheelCallback(b3WheelCallback wheelCallback);
|
||||
virtual void setKeyboardCallback( b3KeyboardCallback keyboardCallback);
|
||||
|
||||
|
||||
virtual b3MouseMoveCallback getMouseMoveCallback();
|
||||
virtual b3MouseButtonCallback getMouseButtonCallback();
|
||||
virtual b3ResizeCallback getResizeCallback();
|
||||
virtual b3WheelCallback getWheelCallback();
|
||||
virtual b3KeyboardCallback getKeyboardCallback();
|
||||
|
||||
virtual void setRenderCallback( b3RenderCallback renderCallback);
|
||||
|
||||
@@ -964,10 +964,29 @@ void X11OpenGLWindow::setKeyboardCallback( b3KeyboardCallback keyboardCallback)
|
||||
|
||||
}
|
||||
|
||||
b3MouseMoveCallback X11OpenGLWindow::getMouseMoveCallback()
|
||||
{
|
||||
return m_data->m_mouseMoveCallback;
|
||||
}
|
||||
b3MouseButtonCallback X11OpenGLWindow::getMouseButtonCallback()
|
||||
{
|
||||
return m_data->m_mouseButtonCallback;
|
||||
}
|
||||
b3ResizeCallback X11OpenGLWindow::getResizeCallback()
|
||||
{
|
||||
return m_data->m_resizeCallback;
|
||||
}
|
||||
b3WheelCallback X11OpenGLWindow::getWheelCallback()
|
||||
{
|
||||
return m_data->m_wheelCallback;
|
||||
}
|
||||
|
||||
|
||||
b3KeyboardCallback X11OpenGLWindow::getKeyboardCallback()
|
||||
{
|
||||
return m_data->m_keyboardCallback;
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int X11OpenGLWindow::fileOpenDialog(char* filename, int maxNameLength)
|
||||
|
||||
@@ -53,7 +53,12 @@ public:
|
||||
virtual void setResizeCallback(b3ResizeCallback resizeCallback);
|
||||
virtual void setWheelCallback(b3WheelCallback wheelCallback);
|
||||
virtual void setKeyboardCallback( b3KeyboardCallback keyboardCallback);
|
||||
virtual b3KeyboardCallback getKeyboardCallback();
|
||||
|
||||
virtual b3MouseMoveCallback getMouseMoveCallback();
|
||||
virtual b3MouseButtonCallback getMouseButtonCallback();
|
||||
virtual b3ResizeCallback getResizeCallback();
|
||||
virtual b3WheelCallback getWheelCallback();
|
||||
virtual b3KeyboardCallback getKeyboardCallback();
|
||||
|
||||
virtual void setRenderCallback( b3RenderCallback renderCallback);
|
||||
|
||||
|
||||
@@ -98,9 +98,17 @@ class b3gWindowInterface
|
||||
|
||||
|
||||
virtual void setMouseMoveCallback(b3MouseMoveCallback mouseCallback)=0;
|
||||
virtual b3MouseMoveCallback getMouseMoveCallback()=0;
|
||||
|
||||
virtual void setMouseButtonCallback(b3MouseButtonCallback mouseCallback)=0;
|
||||
virtual b3MouseButtonCallback getMouseButtonCallback()=0;
|
||||
|
||||
virtual void setResizeCallback(b3ResizeCallback resizeCallback)=0;
|
||||
virtual b3ResizeCallback getResizeCallback()=0;
|
||||
|
||||
virtual void setWheelCallback(b3WheelCallback wheelCallback)=0;
|
||||
virtual b3WheelCallback getWheelCallback()=0;
|
||||
|
||||
virtual void setKeyboardCallback( b3KeyboardCallback keyboardCallback)=0;
|
||||
virtual b3KeyboardCallback getKeyboardCallback()=0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user