add upAxis option for Y or Z up
remove some warnings
This commit is contained in:
@@ -18,7 +18,7 @@ subject to the following restrictions:
|
|||||||
bool useShadowMap=true;//false;//true;
|
bool useShadowMap=true;//false;//true;
|
||||||
float shadowMapWidth=8192;
|
float shadowMapWidth=8192;
|
||||||
float shadowMapHeight=8192;
|
float shadowMapHeight=8192;
|
||||||
float shadowMapWorldSize=200;
|
float shadowMapWorldSize=100;
|
||||||
float WHEEL_MULTIPLIER=0.01f;
|
float WHEEL_MULTIPLIER=0.01f;
|
||||||
float MOUSE_MOVE_MULTIPLIER = 0.4f;
|
float MOUSE_MOVE_MULTIPLIER = 0.4f;
|
||||||
#define MAX_POINTS_IN_BATCH 1024
|
#define MAX_POINTS_IN_BATCH 1024
|
||||||
@@ -68,6 +68,7 @@ float MOUSE_MOVE_MULTIPLIER = 0.4f;
|
|||||||
static InternalDataRenderer* sData2;
|
static InternalDataRenderer* sData2;
|
||||||
|
|
||||||
GLint lineWidthRange[2]={1,1};
|
GLint lineWidthRange[2]={1,1};
|
||||||
|
static b3Vector3 gLightPos=b3MakeVector3(-5,200,-40);
|
||||||
|
|
||||||
struct b3GraphicsInstance
|
struct b3GraphicsInstance
|
||||||
{
|
{
|
||||||
@@ -84,7 +85,16 @@ struct b3GraphicsInstance
|
|||||||
int m_vertexArrayOffset;
|
int m_vertexArrayOffset;
|
||||||
int m_primitiveType;
|
int m_primitiveType;
|
||||||
|
|
||||||
b3GraphicsInstance() :m_cube_vao(-1),m_index_vbo(-1),m_numIndices(-1),m_numVertices(-1),m_numGraphicsInstances(0),m_instanceOffset(0),m_vertexArrayOffset(0),m_primitiveType(B3_GL_TRIANGLES),m_texturehandle(0)
|
b3GraphicsInstance()
|
||||||
|
:m_cube_vao(-1),
|
||||||
|
m_index_vbo(-1),
|
||||||
|
m_texturehandle(0),
|
||||||
|
m_numIndices(-1),
|
||||||
|
m_numVertices(-1),
|
||||||
|
m_numGraphicsInstances(0),
|
||||||
|
m_instanceOffset(0),
|
||||||
|
m_vertexArrayOffset(0),
|
||||||
|
m_primitiveType(B3_GL_TRIANGLES)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +108,7 @@ bool m_ortho = false;
|
|||||||
static GLfloat projectionMatrix[16];
|
static GLfloat projectionMatrix[16];
|
||||||
static GLfloat modelviewMatrix[16];
|
static GLfloat modelviewMatrix[16];
|
||||||
|
|
||||||
static GLfloat depthLightModelviewMatrix[16];
|
//static GLfloat depthLightModelviewMatrix[16];
|
||||||
|
|
||||||
static void checkError(const char *functionName)
|
static void checkError(const char *functionName)
|
||||||
{
|
{
|
||||||
@@ -141,14 +151,15 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
|
|||||||
int m_rightMouseButton;
|
int m_rightMouseButton;
|
||||||
|
|
||||||
|
|
||||||
int m_altPressed;
|
|
||||||
int m_controlPressed;
|
|
||||||
|
|
||||||
GLuint m_defaultTexturehandle;
|
GLuint m_defaultTexturehandle;
|
||||||
b3AlignedObjectArray<GLuint> m_textureHandles;
|
b3AlignedObjectArray<GLuint> m_textureHandles;
|
||||||
|
|
||||||
GLRenderToTexture* m_shadowMap;
|
GLRenderToTexture* m_shadowMap;
|
||||||
GLuint m_shadowTexture;
|
GLuint m_shadowTexture;
|
||||||
|
int m_altPressed;
|
||||||
|
int m_controlPressed;
|
||||||
|
|
||||||
InternalDataRenderer() :
|
InternalDataRenderer() :
|
||||||
m_cameraPosition(b3MakeVector3(0,0,0)),
|
m_cameraPosition(b3MakeVector3(0,0,0)),
|
||||||
@@ -317,7 +328,7 @@ static GLuint instancingShaderPointSprite; // The point spr
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static bool done = false;
|
//static bool done = false;
|
||||||
|
|
||||||
static GLint lines_ModelViewMatrix=0;
|
static GLint lines_ModelViewMatrix=0;
|
||||||
static GLint lines_ProjectionMatrix=0;
|
static GLint lines_ProjectionMatrix=0;
|
||||||
@@ -334,6 +345,7 @@ GLuint linesIndexVbo = 0;
|
|||||||
|
|
||||||
static GLint useShadow_ModelViewMatrix=0;
|
static GLint useShadow_ModelViewMatrix=0;
|
||||||
static GLint useShadow_MVP=0;
|
static GLint useShadow_MVP=0;
|
||||||
|
static GLint useShadow_lightDirIn=0;
|
||||||
|
|
||||||
static GLint useShadow_ProjectionMatrix=0;
|
static GLint useShadow_ProjectionMatrix=0;
|
||||||
static GLint useShadow_DepthBiasModelViewMatrix=0;
|
static GLint useShadow_DepthBiasModelViewMatrix=0;
|
||||||
@@ -344,13 +356,13 @@ static GLint createShadow_depthMVP=0;
|
|||||||
|
|
||||||
static GLint ModelViewMatrix=0;
|
static GLint ModelViewMatrix=0;
|
||||||
static GLint ProjectionMatrix=0;
|
static GLint ProjectionMatrix=0;
|
||||||
static GLint DepthModelViewMatrix=0;
|
|
||||||
static GLint uniform_texture_diffuse = 0;
|
static GLint uniform_texture_diffuse = 0;
|
||||||
|
|
||||||
static GLint screenWidthPointSprite=0;
|
static GLint screenWidthPointSprite=0;
|
||||||
static GLint ModelViewMatrixPointSprite=0;
|
static GLint ModelViewMatrixPointSprite=0;
|
||||||
static GLint ProjectionMatrixPointSprite=0;
|
static GLint ProjectionMatrixPointSprite=0;
|
||||||
static GLint uniform_texture_diffusePointSprite= 0;
|
//static GLint uniform_texture_diffusePointSprite= 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -490,15 +502,15 @@ void GLInstancingRenderer::writeSingleInstanceTransformToGPU(float* position, fl
|
|||||||
|
|
||||||
void GLInstancingRenderer::writeTransforms()
|
void GLInstancingRenderer::writeTransforms()
|
||||||
{
|
{
|
||||||
GLint err = glGetError();
|
|
||||||
b3Assert(err==GL_NO_ERROR);
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
||||||
glFlush();
|
glFlush();
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
char* orgBase = (char*)glMapBuffer( GL_ARRAY_BUFFER,GL_READ_WRITE);
|
char* orgBase = (char*)glMapBuffer( GL_ARRAY_BUFFER,GL_READ_WRITE);
|
||||||
if (orgBase)
|
if (orgBase)
|
||||||
@@ -568,8 +580,7 @@ void GLInstancingRenderer::writeTransforms()
|
|||||||
{
|
{
|
||||||
b3Error("ERROR glMapBuffer failed\n");
|
b3Error("ERROR glMapBuffer failed\n");
|
||||||
}
|
}
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glUnmapBuffer( GL_ARRAY_BUFFER);
|
glUnmapBuffer( GL_ARRAY_BUFFER);
|
||||||
//if this glFinish is removed, the animation is not always working/blocks
|
//if this glFinish is removed, the animation is not always working/blocks
|
||||||
@@ -577,17 +588,16 @@ void GLInstancingRenderer::writeTransforms()
|
|||||||
glFlush();
|
glFlush();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);//m_data->m_vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);//m_data->m_vbo);
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const double* pos1, const double* orn1, const double* color1, const double* scaling1)
|
int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const double* pos1, const double* orn1, const double* color1, const double* scaling1)
|
||||||
{
|
{
|
||||||
float pos[4] = {pos1[0],pos1[1],pos1[2],pos1[3]};
|
float pos[4] = {(float)pos1[0],(float)pos1[1],(float)pos1[2],(float)pos1[3]};
|
||||||
float orn[4] = {orn1[0],orn1[1],orn1[2],orn1[3]};
|
float orn[4] = {(float)orn1[0],(float)orn1[1],(float)orn1[2],(float)orn1[3]};
|
||||||
float color[4] = {color1[0],color1[1],color1[2],color1[3]};
|
float color[4] = {(float)color1[0],(float)color1[1],(float)color1[2],(float)color1[3]};
|
||||||
float scaling[4] = {scaling1[0],scaling1[1],scaling1[2],scaling1[3]};
|
float scaling[4] = {(float)scaling1[0],(float)scaling1[1],(float)scaling1[2],(float)scaling1[3]};
|
||||||
return registerGraphicsInstance(shapeIndex,pos,orn,color,scaling);
|
return registerGraphicsInstance(shapeIndex,pos,orn,color,scaling);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,8 +645,7 @@ int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const float*
|
|||||||
|
|
||||||
int GLInstancingRenderer::registerTexture(const unsigned char* texels, int width, int height)
|
int GLInstancingRenderer::registerTexture(const unsigned char* texels, int width, int height)
|
||||||
{
|
{
|
||||||
GLint err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
int textureIndex = m_data->m_textureHandles.size();
|
int textureIndex = m_data->m_textureHandles.size();
|
||||||
const GLubyte* image= (const GLubyte*)texels;
|
const GLubyte* image= (const GLubyte*)texels;
|
||||||
@@ -644,19 +653,15 @@ int GLInstancingRenderer::registerTexture(const unsigned char* texels, int width
|
|||||||
glGenTextures(1,(GLuint*)&textureHandle);
|
glGenTextures(1,(GLuint*)&textureHandle);
|
||||||
glBindTexture(GL_TEXTURE_2D,textureHandle);
|
glBindTexture(GL_TEXTURE_2D,textureHandle);
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
err = glGetError();
|
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width,height,0,GL_RGB,GL_UNSIGNED_BYTE,image);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width,height,0,GL_RGB,GL_UNSIGNED_BYTE,image);
|
||||||
|
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
|
|
||||||
m_data->m_textureHandles.push_back(textureHandle);
|
m_data->m_textureHandles.push_back(textureHandle);
|
||||||
@@ -706,8 +711,10 @@ int GLInstancingRenderer::registerShape(const float* vertices, int numvertices,
|
|||||||
char* dest= (char*)glMapBuffer( GL_ARRAY_BUFFER,GL_WRITE_ONLY);//GL_WRITE_ONLY
|
char* dest= (char*)glMapBuffer( GL_ARRAY_BUFFER,GL_WRITE_ONLY);//GL_WRITE_ONLY
|
||||||
int vertexStrideInBytes = 9*sizeof(float);
|
int vertexStrideInBytes = 9*sizeof(float);
|
||||||
int sz = numvertices*vertexStrideInBytes;
|
int sz = numvertices*vertexStrideInBytes;
|
||||||
|
#ifdef B3_DEBUG
|
||||||
int totalUsed = vertexStrideInBytes*gfxObj->m_vertexArrayOffset+sz;
|
int totalUsed = vertexStrideInBytes*gfxObj->m_vertexArrayOffset+sz;
|
||||||
b3Assert(totalUsed<this->m_maxShapeCapacityInBytes);
|
b3Assert(totalUsed<this->m_maxShapeCapacityInBytes);
|
||||||
|
#endif//B3_DEBUG
|
||||||
|
|
||||||
memcpy(dest+vertexStrideInBytes*gfxObj->m_vertexArrayOffset,vertices,sz);
|
memcpy(dest+vertexStrideInBytes*gfxObj->m_vertexArrayOffset,vertices,sz);
|
||||||
glUnmapBuffer( GL_ARRAY_BUFFER);
|
glUnmapBuffer( GL_ARRAY_BUFFER);
|
||||||
@@ -796,7 +803,7 @@ void GLInstancingRenderer::InitShaders()
|
|||||||
useShadow_DepthBiasModelViewMatrix = glGetUniformLocation(useShadowMapInstancingShader, "DepthBiasModelViewProjectionMatrix");
|
useShadow_DepthBiasModelViewMatrix = glGetUniformLocation(useShadowMapInstancingShader, "DepthBiasModelViewProjectionMatrix");
|
||||||
useShadow_uniform_texture_diffuse = glGetUniformLocation(useShadowMapInstancingShader, "Diffuse");
|
useShadow_uniform_texture_diffuse = glGetUniformLocation(useShadowMapInstancingShader, "Diffuse");
|
||||||
useShadow_shadowMap = glGetUniformLocation(useShadowMapInstancingShader,"shadowMap");
|
useShadow_shadowMap = glGetUniformLocation(useShadowMapInstancingShader,"shadowMap");
|
||||||
|
useShadow_lightDirIn = glGetUniformLocation(useShadowMapInstancingShader,"lightDirIn");
|
||||||
|
|
||||||
createShadowMapInstancingShader = gltLoadShaderPair(createShadowMapInstancingVertexShader,createShadowMapInstancingFragmentShader);
|
createShadowMapInstancingShader = gltLoadShaderPair(createShadowMapInstancingVertexShader,createShadowMapInstancingFragmentShader);
|
||||||
glLinkProgram(createShadowMapInstancingShader);
|
glLinkProgram(createShadowMapInstancingShader);
|
||||||
@@ -847,26 +854,20 @@ void GLInstancingRenderer::InitShaders()
|
|||||||
|
|
||||||
void GLInstancingRenderer::init()
|
void GLInstancingRenderer::init()
|
||||||
{
|
{
|
||||||
GLint err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
err = glGetError();
|
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthFunc(GL_LESS);
|
glDepthFunc(GL_LESS);
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
// glClearColor(float(0.),float(0.),float(0.4),float(0));
|
// glClearColor(float(0.),float(0.),float(0.4),float(0));
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
B3_PROFILE("texture");
|
B3_PROFILE("texture");
|
||||||
@@ -910,63 +911,32 @@ void GLInstancingRenderer::init()
|
|||||||
|
|
||||||
glGenTextures(1,(GLuint*)&m_data->m_defaultTexturehandle);
|
glGenTextures(1,(GLuint*)&m_data->m_defaultTexturehandle);
|
||||||
glBindTexture(GL_TEXTURE_2D,m_data->m_defaultTexturehandle);
|
glBindTexture(GL_TEXTURE_2D,m_data->m_defaultTexturehandle);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
|
|
||||||
err = glGetError();
|
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
|
|
||||||
err = glGetError();
|
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
|
||||||
err = glGetError();
|
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
|
|
||||||
err = glGetError();
|
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
|
|
||||||
err = glGetError();
|
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
err = glGetError();
|
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256,256,0,GL_RGB,GL_UNSIGNED_BYTE,image);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256,256,0,GL_RGB,GL_UNSIGNED_BYTE,image);
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
delete[] image;
|
delete[] image;
|
||||||
m_textureinitialized=true;
|
m_textureinitialized=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D,m_data->m_defaultTexturehandle);
|
glBindTexture(GL_TEXTURE_2D,m_data->m_defaultTexturehandle);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//glEnable(GL_COLOR_MATERIAL);
|
//glEnable(GL_COLOR_MATERIAL);
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
// glEnable(GL_CULL_FACE);
|
// glEnable(GL_CULL_FACE);
|
||||||
// glCullFace(GL_BACK);
|
// glCullFace(GL_BACK);
|
||||||
@@ -1086,14 +1056,28 @@ void GLInstancingRenderer::resize(int width, int height)
|
|||||||
m_screenHeight = height;
|
m_screenHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLInstancingRenderer::updateCamera()
|
void GLInstancingRenderer::updateCamera(int upAxis)
|
||||||
{
|
{
|
||||||
|
|
||||||
GLint err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
|
int m_forwardAxis(-1);
|
||||||
int m_forwardAxis(2);
|
switch (upAxis)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
m_forwardAxis = 2;
|
||||||
|
m_data->m_cameraUp = b3MakeVector3(0,1,0);
|
||||||
|
gLightPos = b3MakeVector3(-50.f,100,30);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
m_forwardAxis = 1;
|
||||||
|
m_data->m_cameraUp = b3MakeVector3(0,0,1);
|
||||||
|
gLightPos = b3MakeVector3(-50.f,30,100);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
b3Assert(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
float m_frustumZNear=1;
|
float m_frustumZNear=1;
|
||||||
float m_frustumZFar=10000.f;
|
float m_frustumZFar=10000.f;
|
||||||
@@ -1106,8 +1090,7 @@ void GLInstancingRenderer::updateCamera()
|
|||||||
|
|
||||||
b3Quaternion rot(m_data->m_cameraUp,razi);
|
b3Quaternion rot(m_data->m_cameraUp,razi);
|
||||||
|
|
||||||
|
b3Vector3 eyePos = b3MakeVector3(0,0,0);
|
||||||
b3Vector3 eyePos = b3MakeVector3(0,0,0);
|
|
||||||
eyePos[m_forwardAxis] = -m_data->m_cameraDistance;
|
eyePos[m_forwardAxis] = -m_data->m_cameraDistance;
|
||||||
|
|
||||||
b3Vector3 forward = b3MakeVector3(eyePos[0],eyePos[1],eyePos[2]);
|
b3Vector3 forward = b3MakeVector3(eyePos[0],eyePos[1],eyePos[2]);
|
||||||
@@ -1256,19 +1239,15 @@ void GLInstancingRenderer::getMouseDirection(float* dir, int x, int y)
|
|||||||
#include "OpenGLTrueTypeFont/stb_image_write.h"
|
#include "OpenGLTrueTypeFont/stb_image_write.h"
|
||||||
void writeTextureToPng(int textureWidth, int textureHeight, const char* fileName, int numComponents)
|
void writeTextureToPng(int textureWidth, int textureHeight, const char* fileName, int numComponents)
|
||||||
{
|
{
|
||||||
GLuint err;
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glPixelStorei(GL_PACK_ALIGNMENT,4);
|
glPixelStorei(GL_PACK_ALIGNMENT,4);
|
||||||
|
|
||||||
glReadBuffer(GL_NONE);
|
glReadBuffer(GL_NONE);
|
||||||
float* orgPixels = (float*)malloc(textureWidth*textureHeight*numComponents*4);
|
float* orgPixels = (float*)malloc(textureWidth*textureHeight*numComponents*4);
|
||||||
char* pixels = (char*)malloc(textureWidth*textureHeight*numComponents*4);
|
char* pixels = (char*)malloc(textureWidth*textureHeight*numComponents*4);
|
||||||
glReadPixels(0,0,textureWidth, textureHeight, GL_DEPTH_COMPONENT, GL_FLOAT, orgPixels);
|
glReadPixels(0,0,textureWidth, textureHeight, GL_DEPTH_COMPONENT, GL_FLOAT, orgPixels);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
for (int j=0;j<textureHeight;j++)
|
for (int j=0;j<textureHeight;j++)
|
||||||
{
|
{
|
||||||
for (int i=0;i<textureWidth;i++)
|
for (int i=0;i<textureWidth;i++)
|
||||||
@@ -1328,7 +1307,7 @@ void GLInstancingRenderer::renderScene()
|
|||||||
|
|
||||||
if (useShadowMap)
|
if (useShadowMap)
|
||||||
{
|
{
|
||||||
float color[4]={1,1,1,1};
|
|
||||||
renderSceneInternal(B3_CREATE_SHADOWMAP_RENDERMODE);
|
renderSceneInternal(B3_CREATE_SHADOWMAP_RENDERMODE);
|
||||||
// glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
// glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||||
renderSceneInternal(B3_USE_SHADOWMAP_RENDERMODE);
|
renderSceneInternal(B3_USE_SHADOWMAP_RENDERMODE);
|
||||||
@@ -1349,10 +1328,8 @@ void GLInstancingRenderer::drawPoints(const float* positions, const float color[
|
|||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D,0);
|
glBindTexture(GL_TEXTURE_2D,0);
|
||||||
int curOffset = 0;
|
|
||||||
GLint err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);glUseProgram(linesShader);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
glUseProgram(linesShader);
|
|
||||||
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &projectionMatrix[0]);
|
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &projectionMatrix[0]);
|
||||||
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &modelviewMatrix[0]);
|
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &modelviewMatrix[0]);
|
||||||
glUniform4f(lines_colour,color[0],color[1],color[2],color[3]);
|
glUniform4f(lines_colour,color[0],color[1],color[2],color[3]);
|
||||||
@@ -1394,17 +1371,13 @@ void GLInstancingRenderer::drawLines(const float* positions, const float color[4
|
|||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
||||||
|
|
||||||
GLint err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D,0);
|
glBindTexture(GL_TEXTURE_2D,0);
|
||||||
int curOffset = 0;
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);glUseProgram(linesShader);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
glUseProgram(linesShader);
|
|
||||||
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &projectionMatrix[0]);
|
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &projectionMatrix[0]);
|
||||||
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &modelviewMatrix[0]);
|
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &modelviewMatrix[0]);
|
||||||
glUniform4f(lines_colour,color[0],color[1],color[2],color[3]);
|
glUniform4f(lines_colour,color[0],color[1],color[2],color[3]);
|
||||||
@@ -1412,9 +1385,7 @@ void GLInstancingRenderer::drawLines(const float* positions, const float color[4
|
|||||||
// glPointSize(pointDrawSize);
|
// glPointSize(pointDrawSize);
|
||||||
glBindVertexArray(linesVertexArrayObject);
|
glBindVertexArray(linesVertexArrayObject);
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, linesVertexBufferObject);
|
glBindBuffer(GL_ARRAY_BUFFER, linesVertexBufferObject);
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -1422,21 +1393,15 @@ void GLInstancingRenderer::drawLines(const float* positions, const float color[4
|
|||||||
glBufferData(GL_ARRAY_BUFFER, numPoints*pointStrideInBytes, 0,GL_DYNAMIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, numPoints*pointStrideInBytes, 0,GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, 0, numPoints*pointStrideInBytes, positions);
|
glBufferSubData(GL_ARRAY_BUFFER, 0, numPoints*pointStrideInBytes, positions);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err == GL_NO_ERROR);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, linesVertexBufferObject);
|
glBindBuffer(GL_ARRAY_BUFFER, linesVertexBufferObject);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err == GL_NO_ERROR);
|
|
||||||
|
|
||||||
int numFloats = pointStrideInBytes / sizeof(float);
|
int numFloats = pointStrideInBytes / sizeof(float);
|
||||||
glVertexAttribPointer(0, numFloats, GL_FLOAT, GL_FALSE, 0, 0);
|
glVertexAttribPointer(0, numFloats, GL_FLOAT, GL_FALSE, 0, 0);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err == GL_NO_ERROR);
|
|
||||||
|
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, linesIndexVbo);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, linesIndexVbo);
|
||||||
int indexBufferSizeInBytes = numIndices*sizeof(int);
|
int indexBufferSizeInBytes = numIndices*sizeof(int);
|
||||||
@@ -1451,68 +1416,54 @@ void GLInstancingRenderer::drawLines(const float* positions, const float color[4
|
|||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
// for (int i=0;i<numIndices;i++)
|
// for (int i=0;i<numIndices;i++)
|
||||||
// printf("indicec[i]=%d]\n",indices[i]);
|
// printf("indicec[i]=%d]\n",indices[i]);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glPointSize(1);
|
glPointSize(1);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLInstancingRenderer::drawLine(const float from[4], const float to[4], const float color[4], float lineWidth)
|
void GLInstancingRenderer::drawLine(const float from[4], const float to[4], const float color[4], float lineWidth)
|
||||||
{
|
{
|
||||||
GLint err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D,0);
|
glBindTexture(GL_TEXTURE_2D,0);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
int curOffset = 0;
|
|
||||||
|
|
||||||
glUseProgram(linesShader);
|
glUseProgram(linesShader);
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &projectionMatrix[0]);
|
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &projectionMatrix[0]);
|
||||||
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &modelviewMatrix[0]);
|
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &modelviewMatrix[0]);
|
||||||
glUniform4f(lines_colour,color[0],color[1],color[2],color[3]);
|
glUniform4f(lines_colour,color[0],color[1],color[2],color[3]);
|
||||||
|
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
const float vertexPositions[] = {
|
const float vertexPositions[] = {
|
||||||
from[0],from[1],from[2],1,
|
from[0],from[1],from[2],1,
|
||||||
to[0],to[1],to[2],1
|
to[0],to[1],to[2],1
|
||||||
};
|
};
|
||||||
int sz = sizeof(vertexPositions);
|
int sz = sizeof(vertexPositions);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
|
|
||||||
b3Clamp(lineWidth,(float)lineWidthRange[0],(float)lineWidthRange[1]);
|
b3Clamp(lineWidth,(float)lineWidthRange[0],(float)lineWidthRange[1]);
|
||||||
glLineWidth(lineWidth);
|
glLineWidth(lineWidth);
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glBindVertexArray(lineVertexArrayObject);
|
glBindVertexArray(lineVertexArrayObject);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
|
glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -1520,32 +1471,41 @@ void GLInstancingRenderer::drawLine(const float from[4], const float to[4], cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
|
glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
|
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glDrawArrays(GL_LINES, 0, 2);
|
glDrawArrays(GL_LINES, 0, 2);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
glLineWidth(1);
|
glLineWidth(1);
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct PointerCaster
|
||||||
|
{
|
||||||
|
union {
|
||||||
|
int m_baseIndex;
|
||||||
|
GLvoid* m_pointer;
|
||||||
|
};
|
||||||
|
|
||||||
|
PointerCaster()
|
||||||
|
:m_pointer(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -1571,9 +1531,7 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GLint err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
|
|
||||||
float depthProjectionMatrix[4][4];
|
float depthProjectionMatrix[4][4];
|
||||||
GLfloat depthModelViewMatrix[4][4];
|
GLfloat depthModelViewMatrix[4][4];
|
||||||
@@ -1621,21 +1579,19 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
|||||||
// glEnable(GL_CULL_FACE);
|
// glEnable(GL_CULL_FACE);
|
||||||
// glCullFace(GL_BACK); // Cull back-facing triangles -> draw only front-facing triangles
|
// glCullFace(GL_BACK); // Cull back-facing triangles -> draw only front-facing triangles
|
||||||
|
|
||||||
GLint err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
//glCullFace(GL_BACK);
|
//glCullFace(GL_BACK);
|
||||||
|
|
||||||
}
|
}
|
||||||
static b3Vector3 lightPos = b3MakeVector3(-5.f,200,-40);//20,15,10);//-13,6,2);// = b3Vector3(0.5f,2,2);
|
|
||||||
// lightPos.y+=0.1f;
|
|
||||||
b3CreateOrtho(-shadowMapWorldSize,shadowMapWorldSize,-shadowMapWorldSize,shadowMapWorldSize,1,300,depthProjectionMatrix);//-14,14,-14,14,1,200, depthProjectionMatrix);
|
b3CreateOrtho(-shadowMapWorldSize,shadowMapWorldSize,-shadowMapWorldSize,shadowMapWorldSize,1,300,depthProjectionMatrix);//-14,14,-14,14,1,200, depthProjectionMatrix);
|
||||||
float depthViewMatrix[4][4];
|
float depthViewMatrix[4][4];
|
||||||
b3Vector3 center = b3MakeVector3(0,0,0);
|
b3Vector3 center = b3MakeVector3(0,0,0);
|
||||||
b3Vector3 up =b3MakeVector3(0,1,0);
|
b3Vector3 up =b3MakeVector3(0,1,0);
|
||||||
b3CreateLookAt(lightPos,center,up,&depthViewMatrix[0][0]);
|
b3CreateLookAt(gLightPos,center,up,&depthViewMatrix[0][0]);
|
||||||
//b3CreateLookAt(lightPos,m_data->m_cameraTargetPosition,b3Vector3(0,1,0),(float*)depthModelViewMatrix2);
|
//b3CreateLookAt(lightPos,m_data->m_cameraTargetPosition,b3Vector3(0,1,0),(float*)depthModelViewMatrix2);
|
||||||
|
|
||||||
GLfloat depthModelMatrix[4][4];
|
GLfloat depthModelMatrix[4][4];
|
||||||
@@ -1669,12 +1625,10 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
|||||||
|
|
||||||
{
|
{
|
||||||
B3_PROFILE("updateCamera");
|
B3_PROFILE("updateCamera");
|
||||||
updateCamera();
|
// updateCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, 0);
|
// glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
@@ -1684,9 +1638,7 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
|||||||
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
||||||
glFlush();
|
glFlush();
|
||||||
}
|
}
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
|
|
||||||
int totalNumInstances = 0;
|
int totalNumInstances = 0;
|
||||||
|
|
||||||
@@ -1696,7 +1648,7 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int curOffset = 0;
|
int curOffset = 0;
|
||||||
GLuint lastBindTexture = 0;
|
//GLuint lastBindTexture = 0;
|
||||||
|
|
||||||
|
|
||||||
for (int i=0;i<m_graphicsInstances.size();i++)
|
for (int i=0;i<m_graphicsInstances.size();i++)
|
||||||
@@ -1712,14 +1664,14 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
|||||||
else
|
else
|
||||||
curBindTexture = m_data->m_defaultTexturehandle;
|
curBindTexture = m_data->m_defaultTexturehandle;
|
||||||
|
|
||||||
|
//disable lazy evaluation, it just leads to bugs
|
||||||
//if (lastBindTexture != curBindTexture)
|
//if (lastBindTexture != curBindTexture)
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D,curBindTexture);
|
glBindTexture(GL_TEXTURE_2D,curBindTexture);
|
||||||
}
|
}
|
||||||
lastBindTexture = curBindTexture;
|
//lastBindTexture = curBindTexture;
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
// int myOffset = gfxObj->m_instanceOffset*4*sizeof(float);
|
// int myOffset = gfxObj->m_instanceOffset*4*sizeof(float);
|
||||||
|
|
||||||
int POSITION_BUFFER_SIZE = (totalNumInstances*sizeof(float)*4);
|
int POSITION_BUFFER_SIZE = (totalNumInstances*sizeof(float)*4);
|
||||||
@@ -1731,16 +1683,22 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
|||||||
|
|
||||||
|
|
||||||
int vertexStride = 9*sizeof(float);
|
int vertexStride = 9*sizeof(float);
|
||||||
int vertexBase = gfxObj->m_vertexArrayOffset*vertexStride;
|
PointerCaster vertex;
|
||||||
|
vertex.m_baseIndex = gfxObj->m_vertexArrayOffset*vertexStride;
|
||||||
|
|
||||||
|
|
||||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 9*sizeof(float), (GLvoid*)vertexBase);
|
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 9*sizeof(float), vertex.m_pointer);
|
||||||
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*4*sizeof(float)+m_maxShapeCapacityInBytes));
|
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*4*sizeof(float)+m_maxShapeCapacityInBytes));
|
||||||
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*4*sizeof(float)+m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE));
|
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*4*sizeof(float)+m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE));
|
||||||
int uvoffset = 7*sizeof(float)+vertexBase;
|
|
||||||
int normaloffset = 4*sizeof(float)+vertexBase;
|
PointerCaster uv;
|
||||||
|
uv.m_baseIndex = 7*sizeof(float)+vertex.m_baseIndex;
|
||||||
|
|
||||||
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 9*sizeof(float), (GLvoid *)uvoffset);
|
PointerCaster normal;
|
||||||
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 9*sizeof(float), (GLvoid *)normaloffset);
|
normal.m_baseIndex = 4*sizeof(float)+vertex.m_baseIndex;
|
||||||
|
|
||||||
|
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 9*sizeof(float), uv.m_pointer);
|
||||||
|
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 9*sizeof(float), normal.m_pointer);
|
||||||
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*4*sizeof(float)+m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE));
|
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*4*sizeof(float)+m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE));
|
||||||
glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*3*sizeof(float)+m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE+COLOR_BUFFER_SIZE));
|
glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid *)(curOffset*3*sizeof(float)+m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE+COLOR_BUFFER_SIZE));
|
||||||
|
|
||||||
@@ -1765,7 +1723,7 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
|||||||
|
|
||||||
|
|
||||||
int indexCount = gfxObj->m_numIndices;
|
int indexCount = gfxObj->m_numIndices;
|
||||||
int indexOffset = 0;
|
GLvoid* indexOffset = 0;
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gfxObj->m_index_vbo);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gfxObj->m_index_vbo);
|
||||||
{
|
{
|
||||||
@@ -1779,9 +1737,8 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
|||||||
glUniform1f(screenWidthPointSprite,m_screenWidth);
|
glUniform1f(screenWidthPointSprite,m_screenWidth);
|
||||||
|
|
||||||
//glUniform1i(uniform_texture_diffusePointSprite, 0);
|
//glUniform1i(uniform_texture_diffusePointSprite, 0);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
glPointSize(20);
|
||||||
glPointSize(20);
|
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
glEnable(GL_POINT_SPRITE_ARB);
|
glEnable(GL_POINT_SPRITE_ARB);
|
||||||
@@ -1789,7 +1746,7 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||||
glDrawElementsInstanced(GL_POINTS, indexCount, GL_UNSIGNED_INT, (void*)indexOffset, gfxObj->m_numGraphicsInstances);
|
glDrawElementsInstanced(GL_POINTS, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
switch (renderMode)
|
switch (renderMode)
|
||||||
@@ -1801,7 +1758,7 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
|||||||
glUniformMatrix4fv(ProjectionMatrix, 1, false, &projectionMatrix[0]);
|
glUniformMatrix4fv(ProjectionMatrix, 1, false, &projectionMatrix[0]);
|
||||||
glUniformMatrix4fv(ModelViewMatrix, 1, false, &modelviewMatrix[0]);
|
glUniformMatrix4fv(ModelViewMatrix, 1, false, &modelviewMatrix[0]);
|
||||||
glUniform1i(uniform_texture_diffuse, 0);
|
glUniform1i(uniform_texture_diffuse, 0);
|
||||||
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, (void*)indexOffset, gfxObj->m_numGraphicsInstances);
|
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case B3_CREATE_SHADOWMAP_RENDERMODE:
|
case B3_CREATE_SHADOWMAP_RENDERMODE:
|
||||||
@@ -1814,7 +1771,7 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
|||||||
*/
|
*/
|
||||||
glUseProgram(createShadowMapInstancingShader);
|
glUseProgram(createShadowMapInstancingShader);
|
||||||
glUniformMatrix4fv(createShadow_depthMVP, 1, false, &depthMVP[0][0]);
|
glUniformMatrix4fv(createShadow_depthMVP, 1, false, &depthMVP[0][0]);
|
||||||
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, (void*)indexOffset, gfxObj->m_numGraphicsInstances);
|
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1826,11 +1783,14 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
|||||||
float MVP[16];
|
float MVP[16];
|
||||||
b3Matrix4x4Mul16(projectionMatrix,modelviewMatrix,MVP);
|
b3Matrix4x4Mul16(projectionMatrix,modelviewMatrix,MVP);
|
||||||
glUniformMatrix4fv(useShadow_MVP, 1, false, &MVP[0]);
|
glUniformMatrix4fv(useShadow_MVP, 1, false, &MVP[0]);
|
||||||
|
b3Vector3 gLightDir = gLightPos;
|
||||||
|
gLightDir.normalize();
|
||||||
|
glUniform3f(useShadow_lightDirIn,gLightDir[0],gLightDir[1],gLightDir[2]);
|
||||||
glUniformMatrix4fv(useShadow_DepthBiasModelViewMatrix, 1, false, &depthBiasMVP[0][0]);
|
glUniformMatrix4fv(useShadow_DepthBiasModelViewMatrix, 1, false, &depthBiasMVP[0][0]);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_data->m_shadowTexture);
|
glBindTexture(GL_TEXTURE_2D, m_data->m_shadowTexture);
|
||||||
glUniform1i(useShadow_shadowMap,1);
|
glUniform1i(useShadow_shadowMap,1);
|
||||||
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, (void*)indexOffset, gfxObj->m_numGraphicsInstances);
|
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -1859,8 +1819,7 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
{
|
{
|
||||||
B3_PROFILE("glUseProgram(0);");
|
B3_PROFILE("glUseProgram(0);");
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
@@ -1871,9 +1830,7 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public:
|
|||||||
void drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize);
|
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 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 drawPoint(const float* position, const float color[4], float pointSize=1);
|
||||||
void updateCamera();
|
void updateCamera(int upAxis=1);
|
||||||
|
|
||||||
void getCameraPosition(float cameraPos[4]);
|
void getCameraPosition(float cameraPos[4]);
|
||||||
void getCameraPosition(double cameraPos[4])
|
void getCameraPosition(double cameraPos[4])
|
||||||
|
|||||||
@@ -208,8 +208,8 @@ public:
|
|||||||
|
|
||||||
//
|
//
|
||||||
//printf("str = %s\n",unicodeText);
|
//printf("str = %s\n",unicodeText);
|
||||||
int xpos=0;
|
//int xpos=0;
|
||||||
int ypos=0;
|
//int ypos=0;
|
||||||
float dx;
|
float dx;
|
||||||
|
|
||||||
int measureOnly=0;
|
int measureOnly=0;
|
||||||
@@ -232,7 +232,7 @@ public:
|
|||||||
{
|
{
|
||||||
//float width = 0.f;
|
//float width = 0.f;
|
||||||
int pos=0;
|
int pos=0;
|
||||||
float color[]={0.2f,0.2,0.2f,1.f};
|
//float color[]={0.2f,0.2,0.2f,1.f};
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D,m_fontTextureId);
|
glBindTexture(GL_TEXTURE_2D,m_fontTextureId);
|
||||||
float width = r.x;
|
float width = r.x;
|
||||||
@@ -299,7 +299,7 @@ public:
|
|||||||
int pos=0;
|
int pos=0;
|
||||||
while (unicodeText[pos])
|
while (unicodeText[pos])
|
||||||
{
|
{
|
||||||
width += m_currentFont->m_CharWidth[unicodeText[pos]]+extraSpacing;
|
width += m_currentFont->m_CharWidth[(int)unicodeText[pos]]+extraSpacing;
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
Gwen::Point pt;
|
Gwen::Point pt;
|
||||||
@@ -318,4 +318,4 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif //__GWEN_OPENGL3_CORE_RENDERER_H
|
#endif //__GWEN_OPENGL3_CORE_RENDERER_H
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ uniform mat4 ModelViewMatrix;
|
|||||||
uniform mat4 ProjectionMatrix;
|
uniform mat4 ProjectionMatrix;
|
||||||
uniform mat4 DepthBiasModelViewProjectionMatrix;
|
uniform mat4 DepthBiasModelViewProjectionMatrix;
|
||||||
uniform mat4 MVP;
|
uniform mat4 MVP;
|
||||||
|
uniform vec3 lightDirIn;
|
||||||
|
|
||||||
out vec4 ShadowCoord;
|
out vec4 ShadowCoord;
|
||||||
|
|
||||||
@@ -65,13 +66,12 @@ void main(void)
|
|||||||
{
|
{
|
||||||
vec4 q = instance_quaternion;
|
vec4 q = instance_quaternion;
|
||||||
ambient = vec3(0.3,.3,0.3);
|
ambient = vec3(0.3,.3,0.3);
|
||||||
|
|
||||||
|
|
||||||
vec4 worldNormal = (quatRotate3( vertexnormal,q));
|
vec4 worldNormal = (quatRotate3( vertexnormal,q));
|
||||||
vec3 light_pos = vec3(-5.f,100,-40);
|
|
||||||
normal = normalize(worldNormal).xyz;
|
normal = normalize(worldNormal).xyz;
|
||||||
|
|
||||||
lightDir = normalize(light_pos);//gl_LightSource[0].position.xyz));
|
lightDir = lightDirIn;
|
||||||
|
|
||||||
vec4 axis = vec4(1,1,1,0);
|
vec4 axis = vec4(1,1,1,0);
|
||||||
vec4 localcoord = quatRotate3( position.xyz*instance_scale,q);
|
vec4 localcoord = quatRotate3( position.xyz*instance_scale,q);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ static const char* useShadowMapInstancingVertexShader= \
|
|||||||
"uniform mat4 ProjectionMatrix;\n"
|
"uniform mat4 ProjectionMatrix;\n"
|
||||||
"uniform mat4 DepthBiasModelViewProjectionMatrix;\n"
|
"uniform mat4 DepthBiasModelViewProjectionMatrix;\n"
|
||||||
"uniform mat4 MVP;\n"
|
"uniform mat4 MVP;\n"
|
||||||
|
"uniform vec3 lightDirIn;\n"
|
||||||
"out vec4 ShadowCoord;\n"
|
"out vec4 ShadowCoord;\n"
|
||||||
"out Fragment\n"
|
"out Fragment\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
@@ -55,12 +56,11 @@ static const char* useShadowMapInstancingVertexShader= \
|
|||||||
"{\n"
|
"{\n"
|
||||||
" vec4 q = instance_quaternion;\n"
|
" vec4 q = instance_quaternion;\n"
|
||||||
" ambient = vec3(0.3,.3,0.3);\n"
|
" ambient = vec3(0.3,.3,0.3);\n"
|
||||||
" \n"
|
" \n"
|
||||||
" \n"
|
|
||||||
" vec4 worldNormal = (quatRotate3( vertexnormal,q));\n"
|
" vec4 worldNormal = (quatRotate3( vertexnormal,q));\n"
|
||||||
" vec3 light_pos = vec3(-5.f,100,-40);\n"
|
" \n"
|
||||||
" normal = normalize(worldNormal).xyz;\n"
|
" normal = normalize(worldNormal).xyz;\n"
|
||||||
" lightDir = normalize(light_pos);//gl_LightSource[0].position.xyz));\n"
|
" lightDir = lightDirIn;\n"
|
||||||
" \n"
|
" \n"
|
||||||
" vec4 axis = vec4(1,1,1,0);\n"
|
" vec4 axis = vec4(1,1,1,0);\n"
|
||||||
" vec4 localcoord = quatRotate3( position.xyz*instance_scale,q);\n"
|
" vec4 localcoord = quatRotate3( position.xyz*instance_scale,q);\n"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef SHAPE_DATA_H
|
#ifndef SHAPE_DATA_H
|
||||||
#define SHAPE_DATA_H
|
#define SHAPE_DATA_H
|
||||||
|
|
||||||
|
#if USE_BARREL_VERTICES
|
||||||
static float barrel_vertices[] = {
|
static float barrel_vertices[] = {
|
||||||
0.0f,-0.5f,0.0f, 1.0f, 0.0f,-1.0f,0.0f, 0.5f, 0.5f,
|
0.0f,-0.5f,0.0f, 1.0f, 0.0f,-1.0f,0.0f, 0.5f, 0.5f,
|
||||||
0.282362f,-0.5f,-0.205148f, 1.0f, 0.0f,-1.0f,0.0f, 0.5f, 0.5f,
|
0.282362f,-0.5f,-0.205148f, 1.0f, 0.0f,-1.0f,0.0f, 0.5f, 0.5f,
|
||||||
@@ -125,7 +126,7 @@ static int barrel_indices[] = {
|
|||||||
44,47,56,
|
44,47,56,
|
||||||
44,26,47,
|
44,26,47,
|
||||||
};
|
};
|
||||||
|
#endif //USE_BARREL_VERTICES
|
||||||
|
|
||||||
///position xyz, unused w, normal, uv
|
///position xyz, unused w, normal, uv
|
||||||
static const float cube_vertices[] =
|
static const float cube_vertices[] =
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
#include "OpenGLWindow/MacOpenGLWindow.h"
|
#include "OpenGLWindow/MacOpenGLWindow.h"
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include "GL/glew.h"
|
#include "OpenGLWindow/GlewWindows/GL/glew.h"
|
||||||
|
//#include "GL/glew.h"
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "OpenGLWindow/Win32OpenGLWindow.h"
|
#include "OpenGLWindow/Win32OpenGLWindow.h"
|
||||||
#else
|
#else
|
||||||
@@ -19,8 +20,8 @@
|
|||||||
#include "Bullet3Common/b3Vector3.h"
|
#include "Bullet3Common/b3Vector3.h"
|
||||||
#include "Bullet3Common/b3Logging.h"
|
#include "Bullet3Common/b3Logging.h"
|
||||||
|
|
||||||
#include "../btgui/OpenGLTrueTypeFont/fontstash.h"
|
#include "OpenGLTrueTypeFont/fontstash.h"
|
||||||
#include "../btgui/OpenGLWindow/TwFonts.h"
|
#include "OpenGLWindow/TwFonts.h"
|
||||||
#include "OpenGLTrueTypeFont/opengl_fontstashcallbacks.h"
|
#include "OpenGLTrueTypeFont/opengl_fontstashcallbacks.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
@@ -78,13 +79,11 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height)
|
|||||||
|
|
||||||
m_window->setWindowTitle(title);
|
m_window->setWindowTitle(title);
|
||||||
|
|
||||||
GLuint err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
glClearColor(1,1,1,1);
|
glClearColor(1,1,1,1);
|
||||||
m_window->startRendering();
|
m_window->startRendering();
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@@ -92,28 +91,26 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height)
|
|||||||
glewExperimental = GL_TRUE;
|
glewExperimental = GL_TRUE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
err = glewInit();
|
|
||||||
if (err != GLEW_OK)
|
if (glewInit() != GLEW_OK)
|
||||||
exit(1); // or handle the error in a nicer way
|
exit(1); // or handle the error in a nicer way
|
||||||
if (!GLEW_VERSION_2_1) // check that the machine supports the 2.1 API.
|
if (!GLEW_VERSION_2_1) // check that the machine supports the 2.1 API.
|
||||||
exit(1); // or handle the error in a nicer way
|
exit(1); // or handle the error in a nicer way
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
err = glGetError();
|
glGetError();//don't remove this call, it is needed for Ubuntu
|
||||||
err = glGetError();
|
|
||||||
assert(err==GL_NO_ERROR);
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
|
|
||||||
m_primRenderer = new GLPrimitiveRenderer(width,height);
|
m_primRenderer = new GLPrimitiveRenderer(width,height);
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
m_instancingRenderer = new GLInstancingRenderer(128*1024,4*1024*1024);
|
m_instancingRenderer = new GLInstancingRenderer(128*1024,4*1024*1024);
|
||||||
m_instancingRenderer->init();
|
m_instancingRenderer->init();
|
||||||
m_instancingRenderer->resize(width,height);
|
m_instancingRenderer->resize(width,height);
|
||||||
|
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
m_instancingRenderer->InitShaders();
|
m_instancingRenderer->InitShaders();
|
||||||
|
|
||||||
@@ -128,23 +125,19 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height)
|
|||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
GLint err;
|
|
||||||
|
|
||||||
int datasize;
|
|
||||||
|
|
||||||
float sx,sy,dx,dy,lh;
|
|
||||||
GLuint texture;
|
|
||||||
m_data->m_renderCallbacks = new OpenGL2RenderCallbacks(m_primRenderer);
|
m_data->m_renderCallbacks = new OpenGL2RenderCallbacks(m_primRenderer);
|
||||||
m_data->m_fontStash = sth_create(512,512,m_data->m_renderCallbacks);//256,256);//,1024);//512,512);
|
m_data->m_fontStash = sth_create(512,512,m_data->m_renderCallbacks);//256,256);//,1024);//512,512);
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
assert(err==GL_NO_ERROR);
|
|
||||||
|
|
||||||
if (!m_data->m_fontStash)
|
if (!m_data->m_fontStash)
|
||||||
{
|
{
|
||||||
b3Warning("Could not create stash");
|
b3Warning("Could not create stash");
|
||||||
//fprintf(stderr, "Could not create stash.\n");
|
//fprintf(stderr, "Could not create stash.\n");
|
||||||
}
|
}
|
||||||
int droidRegular=0;
|
|
||||||
|
|
||||||
char* data2 = OpenSansData;
|
char* data2 = OpenSansData;
|
||||||
unsigned char* data = (unsigned char*) data2;
|
unsigned char* data = (unsigned char*) data2;
|
||||||
@@ -152,8 +145,7 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height)
|
|||||||
{
|
{
|
||||||
b3Warning("error!\n");
|
b3Warning("error!\n");
|
||||||
}
|
}
|
||||||
err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
assert(err==GL_NO_ERROR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +168,7 @@ void SimpleOpenGL3App::drawText( const char* txt, int posX, int posY)
|
|||||||
|
|
||||||
float dx=0;
|
float dx=0;
|
||||||
|
|
||||||
int measureOnly=0;
|
//int measureOnly=0;
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
@@ -196,12 +188,12 @@ void SimpleOpenGL3App::drawText( const char* txt, int posX, int posY)
|
|||||||
{
|
{
|
||||||
//float width = 0.f;
|
//float width = 0.f;
|
||||||
int pos=0;
|
int pos=0;
|
||||||
float color[]={0.2f,0.2,0.2f,1.f};
|
//float color[]={0.2f,0.2,0.2f,1.f};
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D,m_data->m_fontTextureId);
|
glBindTexture(GL_TEXTURE_2D,m_data->m_fontTextureId);
|
||||||
|
|
||||||
//float width = r.x;
|
//float width = r.x;
|
||||||
float extraSpacing = 0.;
|
//float extraSpacing = 0.;
|
||||||
|
|
||||||
int startX = posX;
|
int startX = posX;
|
||||||
int startY = posY;
|
int startY = posY;
|
||||||
@@ -310,24 +302,75 @@ int SimpleOpenGL3App::registerGraphicsSphereShape(float radius, bool usePointSpr
|
|||||||
return graphicsShapeIndex;
|
return graphicsShapeIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleOpenGL3App::drawGrid(int gridSize, float yOffset)
|
void SimpleOpenGL3App::drawGrid(int gridSize, float upOffset, int upAxis)
|
||||||
{
|
{
|
||||||
|
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);
|
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++)
|
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_instancingRenderer->drawLine(from,to,gridColor);
|
||||||
|
}
|
||||||
|
|
||||||
GLint err = glGetError();
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
{
|
||||||
|
|
||||||
m_instancingRenderer->drawLine(b3MakeVector3(float(i),yOffset,float(-gridSize)),b3MakeVector3(float(i),yOffset,float(gridSize)),gridColor);
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
|
b3Vector3 from=b3MakeVector3(0,0,0);
|
||||||
err = glGetError();
|
from[sideAxis] = float(-gridSize);
|
||||||
b3Assert(err==GL_NO_ERROR);
|
from[upAxis] = upOffset;
|
||||||
|
from[forwardAxis] = float(i);
|
||||||
m_instancingRenderer->drawLine(b3MakeVector3(float(-gridSize),yOffset,float(i)),b3MakeVector3(float(gridSize),yOffset,float(i)),gridColor);
|
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_instancingRenderer->drawLine(from,to,gridColor);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*m_instancingRenderer->drawLines(&vertices[0].x,
|
||||||
|
gridColor,
|
||||||
|
vertices.size(),sizeof(b3Vector3),&indices[0],indices.size(),1);
|
||||||
|
*/
|
||||||
|
|
||||||
m_instancingRenderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(1,0,0),b3MakeVector3(1,0,0),3);
|
m_instancingRenderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(1,0,0),b3MakeVector3(1,0,0),3);
|
||||||
m_instancingRenderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(0,1,0),b3MakeVector3(0,1,0),3);
|
m_instancingRenderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(0,1,0),b3MakeVector3(0,1,0),3);
|
||||||
m_instancingRenderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(0,0,1),b3MakeVector3(0,0,1),3);
|
m_instancingRenderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(0,0,1),b3MakeVector3(0,0,1),3);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ struct SimpleOpenGL3App
|
|||||||
int registerCubeShape(float halfExtentsX=1.f,float halfExtentsY=1.f, float halfExtentsZ = 1.f);
|
int registerCubeShape(float halfExtentsX=1.f,float halfExtentsY=1.f, float halfExtentsZ = 1.f);
|
||||||
int registerGraphicsSphereShape(float radius, bool usePointSprites=true, int largeSphereThreshold=100, int mediumSphereThreshold=10);
|
int registerGraphicsSphereShape(float radius, bool usePointSprites=true, int largeSphereThreshold=100, int mediumSphereThreshold=10);
|
||||||
|
|
||||||
void drawGrid(int gridSize=10, float yOffset=0.001);
|
void drawGrid(int gridSize=10, float upOffset=0.001, int upAxis=1);
|
||||||
void swapBuffer();
|
void swapBuffer();
|
||||||
void drawText( const char* txt, int posX, int posY);
|
void drawText( const char* txt, int posX, int posY);
|
||||||
struct sth_stash* getFontStash();
|
struct sth_stash* getFontStash();
|
||||||
|
|||||||
@@ -530,9 +530,9 @@ if (res==0)
|
|||||||
// " SAMPLES = %d\n",
|
// " SAMPLES = %d\n",
|
||||||
// i, vi -> visualid, samp_buf, samples );
|
// i, vi -> visualid, samp_buf, samples );
|
||||||
|
|
||||||
if ( best_fbc < 0 || samp_buf && samples > best_num_samp )
|
if ( best_fbc < 0 || (samp_buf && (samples > best_num_samp)) )
|
||||||
best_fbc = i, best_num_samp = samples;
|
best_fbc = i, best_num_samp = samples;
|
||||||
if ( worst_fbc < 0 || !samp_buf || samples < worst_num_samp )
|
if ( worst_fbc < 0 || (!samp_buf || (samples < worst_num_samp)) )
|
||||||
worst_fbc = i, worst_num_samp = samples;
|
worst_fbc = i, worst_num_samp = samples;
|
||||||
}
|
}
|
||||||
MyXFree( vi );
|
MyXFree( vi );
|
||||||
@@ -652,9 +652,9 @@ int X11OpenGLWindow::getAsciiCodeFromVirtualKeycode(int keycode)
|
|||||||
case XK_F14: return B3G_F14;
|
case XK_F14: return B3G_F14;
|
||||||
case XK_F15: return B3G_F15;
|
case XK_F15: return B3G_F15;
|
||||||
default:
|
default:
|
||||||
// Make uppercase
|
// Make lowercase
|
||||||
MyXConvertCase( key, &key_lc, &key_uc );
|
MyXConvertCase( key, &key_lc, &key_uc );
|
||||||
key = key_uc;
|
key = key_lc;
|
||||||
// Valid ISO 8859-1 character?
|
// Valid ISO 8859-1 character?
|
||||||
if( (key >= 32 && key <= 126) ||(key >= 160 && key <= 255) )
|
if( (key >= 32 && key <= 126) ||(key >= 160 && key <= 255) )
|
||||||
{
|
{
|
||||||
@@ -698,7 +698,7 @@ void X11OpenGLWindow::pumpMessage()
|
|||||||
|
|
||||||
if (m_data->m_keyboardCallback)
|
if (m_data->m_keyboardCallback)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
unsigned short is_retriggered = 0;
|
unsigned short is_retriggered = 0;
|
||||||
///filter out keyboard repeat
|
///filter out keyboard repeat
|
||||||
//see http://stackoverflow.com/questions/2100654/ignore-auto-repeat-in-x11-applications
|
//see http://stackoverflow.com/questions/2100654/ignore-auto-repeat-in-x11-applications
|
||||||
@@ -718,6 +718,7 @@ void X11OpenGLWindow::pumpMessage()
|
|||||||
is_retriggered = 1;
|
is_retriggered = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
int keycode = getAsciiCodeFromVirtualKeycode( m_data->m_xev.xkey.keycode);
|
int keycode = getAsciiCodeFromVirtualKeycode( m_data->m_xev.xkey.keycode);
|
||||||
int state = 0;
|
int state = 0;
|
||||||
(*m_data->m_keyboardCallback)(keycode,state);
|
(*m_data->m_keyboardCallback)(keycode,state);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
language "C++"
|
language "C++"
|
||||||
|
|
||||||
kind "StaticLib"
|
kind "StaticLib"
|
||||||
targetdir "../../bin"
|
|
||||||
|
|
||||||
initOpenGL()
|
initOpenGL()
|
||||||
initGlew()
|
initGlew()
|
||||||
|
|||||||
Reference in New Issue
Block a user