add another btgui test
This commit is contained in:
19
btgui/OpenGLWindow/GLInstanceRendererInternalData.h
Normal file
19
btgui/OpenGLWindow/GLInstanceRendererInternalData.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef GL_INSTANCE_RENDERER_INTERNAL_DATA_H
|
||||
#define GL_INSTANCE_RENDERER_INTERNAL_DATA_H
|
||||
|
||||
#include "OpenGLInclude.h"
|
||||
#include "BulletCommon/btAlignedObjectArray.h"
|
||||
|
||||
struct GLInstanceRendererInternalData
|
||||
{
|
||||
|
||||
btAlignedObjectArray<GLfloat> m_instance_positions_ptr;
|
||||
btAlignedObjectArray<GLfloat> m_instance_quaternion_ptr;
|
||||
btAlignedObjectArray<GLfloat> m_instance_colors_ptr;
|
||||
btAlignedObjectArray<GLfloat> m_instance_scale_ptr;
|
||||
|
||||
int m_vboSize;
|
||||
GLuint m_vbo;
|
||||
};
|
||||
|
||||
#endif //GL_INSTANCE_RENDERER_INTERNAL_DATA_H
|
||||
1308
btgui/OpenGLWindow/GLInstancingRenderer.cpp
Normal file
1308
btgui/OpenGLWindow/GLInstancingRenderer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
92
btgui/OpenGLWindow/GLInstancingRenderer.h
Normal file
92
btgui/OpenGLWindow/GLInstancingRenderer.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
Copyright (c) 2012 Advanced Micro Devices, Inc.
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
//Originally written by Erwin Coumans
|
||||
|
||||
#ifndef GL_INSTANCING_RENDERER_H
|
||||
#define GL_INSTANCING_RENDERER_H
|
||||
|
||||
#include "BulletCommon/btAlignedObjectArray.h"
|
||||
|
||||
void btDefaultMouseButtonCallback( int button, int state, float x, float y);
|
||||
void btDefaultMouseMoveCallback( float x, float y);
|
||||
void btDefaultKeyboardCallback(int key, int state);
|
||||
void btDefaultWheelCallback( float deltax, float deltay);
|
||||
|
||||
enum
|
||||
{
|
||||
BT_GL_TRIANGLES = 1,
|
||||
BT_GL_POINTS
|
||||
};
|
||||
|
||||
class GLInstancingRenderer
|
||||
{
|
||||
|
||||
btAlignedObjectArray<struct btGraphicsInstance*> m_graphicsInstances;
|
||||
|
||||
int m_maxNumObjectCapacity;
|
||||
int m_maxShapeCapacityInBytes;
|
||||
struct InternalDataRenderer* m_data;
|
||||
|
||||
bool m_textureenabled;
|
||||
bool m_textureinitialized;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
GLInstancingRenderer(int m_maxObjectCapacity, int maxShapeCapacityInBytes = 512*1024);
|
||||
virtual ~GLInstancingRenderer();
|
||||
|
||||
void init();
|
||||
|
||||
void InitShaders();
|
||||
void RenderScene(void);
|
||||
void CleanupShaders();
|
||||
|
||||
///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=BT_GL_TRIANGLES);
|
||||
|
||||
///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);
|
||||
|
||||
void writeTransforms();
|
||||
|
||||
void writeSingleInstanceTransformToCPU(float* position, float* orientation, int srcIndex);
|
||||
|
||||
void writeSingleInstanceTransformToGPU(float* position, float* orientation, int srcIndex);
|
||||
|
||||
void writeSingleInstanceColorToCPU(float* color, int srcIndex);
|
||||
|
||||
void getMouseDirection(float* dir, int mouseX, int mouseY);
|
||||
|
||||
struct GLInstanceRendererInternalData* getInternalData();
|
||||
|
||||
void updateCamera();
|
||||
|
||||
void getCameraPosition(float cameraPos[4]);
|
||||
void setCameraDistance(float dist);
|
||||
float getCameraDistance() const;
|
||||
|
||||
//set the camera 'target'
|
||||
void setCameraTargetPosition(float cameraPos[4]);
|
||||
void getCameraTargetPosition(float cameraPos[4]) const;
|
||||
|
||||
void resize(int width, int height);
|
||||
|
||||
int getMaxShapeCapacity() const
|
||||
{
|
||||
return m_maxShapeCapacityInBytes;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //GL_INSTANCING_RENDERER_H
|
||||
19
btgui/OpenGLWindow/GLPrimInternalData.h
Normal file
19
btgui/OpenGLWindow/GLPrimInternalData.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef PRIM_INTERNAL_DATA
|
||||
#define PRIM_INTERNAL_DATA
|
||||
|
||||
#include "OpenGLInclude.h"
|
||||
|
||||
struct PrimInternalData
|
||||
{
|
||||
GLuint m_shaderProg;
|
||||
GLint m_positionUniform;
|
||||
GLint m_colourAttribute;
|
||||
GLint m_positionAttribute;
|
||||
GLint m_textureAttribute;
|
||||
GLuint m_vertexBuffer;
|
||||
GLuint m_vertexArrayObject;
|
||||
GLuint m_indexBuffer;
|
||||
GLuint m_texturehandle;
|
||||
};
|
||||
|
||||
#endif //PRIM_INTERNAL_DATA
|
||||
342
btgui/OpenGLWindow/GLPrimitiveRenderer.cpp
Normal file
342
btgui/OpenGLWindow/GLPrimitiveRenderer.cpp
Normal file
@@ -0,0 +1,342 @@
|
||||
#include "GLPrimitiveRenderer.h"
|
||||
#include "GLPrimInternalData.h"
|
||||
|
||||
#include "LoadShader.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
static const char* vertexShader= \
|
||||
"#version 150 \n"
|
||||
"\n"
|
||||
"uniform vec2 p;\n"
|
||||
"\n"
|
||||
"in vec4 position;\n"
|
||||
"in vec4 colour;\n"
|
||||
"out vec4 colourV;\n"
|
||||
"\n"
|
||||
"in vec2 texuv;\n"
|
||||
"out vec2 texuvV;\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"void main (void)\n"
|
||||
"{\n"
|
||||
" colourV = colour;\n"
|
||||
" gl_Position = vec4(p.x+position.x, p.y+position.y,0.f,1.f);\n"
|
||||
" texuvV=texuv;\n"
|
||||
"}\n";
|
||||
|
||||
static const char* fragmentShader= \
|
||||
"#version 150\n"
|
||||
"\n"
|
||||
"in vec4 colourV;\n"
|
||||
"out vec4 fragColour;\n"
|
||||
"in vec2 texuvV;\n"
|
||||
"\n"
|
||||
"uniform sampler2D Diffuse;\n"
|
||||
"\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" vec4 texcolorred = texture(Diffuse,texuvV);\n"
|
||||
"// vec4 texcolor = vec4(texcolorred.x,texcolorred.x,texcolorred.x,1);\n"
|
||||
" vec4 texcolor = vec4(1,1,1,texcolorred.x);\n"
|
||||
"\n"
|
||||
" fragColour = colourV*texcolor;\n"
|
||||
"}\n";
|
||||
|
||||
|
||||
static unsigned int s_indexData[6] = {0,1,2,0,2,3};
|
||||
struct vec2
|
||||
{
|
||||
vec2(float x, float y)
|
||||
{
|
||||
p[0] = x;
|
||||
p[1] = y;
|
||||
}
|
||||
float p[2];
|
||||
};
|
||||
|
||||
struct vec4
|
||||
{
|
||||
vec4(float x,float y, float z, float w)
|
||||
{
|
||||
p[0] = x;
|
||||
p[1] = y;
|
||||
p[2] = z;
|
||||
p[3] = w;
|
||||
|
||||
}
|
||||
|
||||
float p[4];
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
vec4 position;
|
||||
vec4 colour;
|
||||
vec2 uv;
|
||||
} Vertex;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
GLPrimitiveRenderer::GLPrimitiveRenderer(int screenWidth, int screenHeight)
|
||||
:m_screenWidth(screenWidth),
|
||||
m_screenHeight(screenHeight)
|
||||
{
|
||||
|
||||
m_data = new PrimInternalData;
|
||||
|
||||
m_data->m_shaderProg = gltLoadShaderPair(vertexShader,fragmentShader);
|
||||
|
||||
m_data->m_positionUniform = glGetUniformLocation(m_data->m_shaderProg, "p");
|
||||
if (m_data->m_positionUniform < 0) {
|
||||
assert(0);
|
||||
}
|
||||
m_data->m_colourAttribute = glGetAttribLocation(m_data->m_shaderProg, "colour");
|
||||
if (m_data->m_colourAttribute < 0) {
|
||||
assert(0);
|
||||
}
|
||||
m_data->m_positionAttribute = glGetAttribLocation(m_data->m_shaderProg, "position");
|
||||
if (m_data->m_positionAttribute < 0) {
|
||||
assert(0);
|
||||
}
|
||||
m_data->m_textureAttribute = glGetAttribLocation(m_data->m_shaderProg,"texuv");
|
||||
if (m_data->m_textureAttribute < 0) {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
loadBufferData();
|
||||
|
||||
}
|
||||
|
||||
void GLPrimitiveRenderer::loadBufferData()
|
||||
{
|
||||
|
||||
Vertex vertexData[4] = {
|
||||
{ vec4(-1, -1, 0.0, 1.0 ), vec4( 1.0, 0.0, 0.0, 1.0 ) ,vec2(0,0)},
|
||||
{ vec4(-1, 1, 0.0, 1.0 ), vec4( 0.0, 1.0, 0.0, 1.0 ) ,vec2(0,1)},
|
||||
{ vec4( 1, 1, 0.0, 1.0 ), vec4( 0.0, 0.0, 1.0, 1.0 ) ,vec2(1,1)},
|
||||
{ vec4( 1, -1, 0.0, 1.0 ), vec4( 1.0, 1.0, 1.0, 1.0 ) ,vec2(1,0)}
|
||||
};
|
||||
|
||||
|
||||
glGenVertexArrays(1, &m_data->m_vertexArrayObject);
|
||||
glBindVertexArray(m_data->m_vertexArrayObject);
|
||||
|
||||
glGenBuffers(1, &m_data->m_vertexBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vertexBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(Vertex), vertexData, GL_STATIC_DRAW);
|
||||
GLuint err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
|
||||
glGenBuffers(1, &m_data->m_indexBuffer);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_indexBuffer);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER,6*sizeof(int), s_indexData,GL_STATIC_DRAW);
|
||||
|
||||
glEnableVertexAttribArray(m_data->m_positionAttribute);
|
||||
glEnableVertexAttribArray(m_data->m_colourAttribute);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glEnableVertexAttribArray(m_data->m_textureAttribute);
|
||||
|
||||
glVertexAttribPointer(m_data->m_positionAttribute, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)0);
|
||||
glVertexAttribPointer(m_data->m_colourAttribute , 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)sizeof(vec4));
|
||||
glVertexAttribPointer(m_data->m_textureAttribute , 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)(sizeof(vec4)+sizeof(vec4)));
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
GLubyte* image=new GLubyte[256*256*3];
|
||||
for(int y=0;y<256;++y)
|
||||
{
|
||||
// const int t=y>>5;
|
||||
GLubyte* pi=image+y*256*3;
|
||||
for(int x=0;x<256;++x)
|
||||
{
|
||||
if (x<y)//x<2||y<2||x>253||y>253)
|
||||
{
|
||||
pi[0]=255;
|
||||
pi[1]=0;
|
||||
pi[2]=0;
|
||||
} else
|
||||
|
||||
{
|
||||
pi[0]=255;
|
||||
pi[1]=255;
|
||||
pi[2]=255;
|
||||
}
|
||||
|
||||
pi+=3;
|
||||
}
|
||||
}
|
||||
|
||||
glGenTextures(1,(GLuint*)&m_data->m_texturehandle);
|
||||
glBindTexture(GL_TEXTURE_2D,m_data->m_texturehandle);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256,256,0,GL_RGB,GL_UNSIGNED_BYTE,image);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
delete[] image;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
GLPrimitiveRenderer::~GLPrimitiveRenderer()
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D,0);
|
||||
glUseProgram(0);
|
||||
glBindTexture(GL_TEXTURE_2D,0);
|
||||
glDeleteProgram(m_data->m_shaderProg);
|
||||
}
|
||||
|
||||
void GLPrimitiveRenderer::drawLine()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GLPrimitiveRenderer::drawRect(float x0, float y0, float x1, float y1, float color[4])
|
||||
{
|
||||
GLint err;
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D,m_data->m_texturehandle);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
drawTexturedRect(x0,y0,x1,y1,color,0,0,1,1);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
}
|
||||
|
||||
void GLPrimitiveRenderer::drawTexturedRect(float x0, float y0, float x1, float y1, float color[4], float u0,float v0, float u1, float v1)//Line()//float from[4], float to[4], float color[4])
|
||||
{
|
||||
GLint err;
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
glUseProgram(m_data->m_shaderProg);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vertexBuffer);
|
||||
glBindVertexArray(m_data->m_vertexArrayObject);
|
||||
|
||||
bool useFiltering = false;
|
||||
if (useFiltering)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
} else
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
Vertex vertexData[4] = {
|
||||
{ vec4(-1.+2.*x0/float(m_screenWidth), 1.-2.*y0/float(m_screenHeight), 0, 0 ), vec4( color[0], color[1], color[2], color[3] ) ,vec2(u0,v0)},
|
||||
{ vec4(-1.+2.*x0/float(m_screenWidth), 1.-2.*y1/float(m_screenHeight), 0, 1 ), vec4( color[0], color[1], color[2], color[3] ) ,vec2(u0,v1)},
|
||||
{ vec4( -1.+2.*x1/float(m_screenWidth), 1.-2.*y1/float(m_screenHeight), 1, 1 ), vec4(color[0], color[1], color[2], color[3]) ,vec2(u1,v1)},
|
||||
{ vec4( -1.+2.*x1/float(m_screenWidth), 1.-2.*y0/float(m_screenHeight), 1, 0 ), vec4( color[0], color[1], color[2], color[3] ) ,vec2(u1,v0)}
|
||||
};
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(Vertex), vertexData, GL_STATIC_DRAW);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
vec2 p( 0.f,0.f);//?b?0.5f * sinf(timeValue), 0.5f * cosf(timeValue) );
|
||||
glUniform2fv(m_data->m_positionUniform, 1, (const GLfloat *)&p);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glEnableVertexAttribArray(m_data->m_positionAttribute);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glEnableVertexAttribArray(m_data->m_colourAttribute);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glEnableVertexAttribArray(m_data->m_textureAttribute);
|
||||
|
||||
glVertexAttribPointer(m_data->m_positionAttribute, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)0);
|
||||
glVertexAttribPointer(m_data->m_colourAttribute , 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)sizeof(vec4));
|
||||
glVertexAttribPointer(m_data->m_textureAttribute , 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)(sizeof(vec4)+sizeof(vec4)));
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_indexBuffer);
|
||||
|
||||
//glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
int indexCount = 6;
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
glBindVertexArray(0);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
//glDisableVertexAttribArray(m_data->m_textureAttribute);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glUseProgram(0);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
}
|
||||
|
||||
void GLPrimitiveRenderer::setScreenSize(int width, int height)
|
||||
{
|
||||
m_screenWidth = width;
|
||||
m_screenHeight = height;
|
||||
|
||||
}
|
||||
32
btgui/OpenGLWindow/GLPrimitiveRenderer.h
Normal file
32
btgui/OpenGLWindow/GLPrimitiveRenderer.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef _GL_PRIMITIVE_RENDERER_H
|
||||
#define _GL_PRIMITIVE_RENDERER_H
|
||||
|
||||
#include "OpenGLInclude.h"
|
||||
|
||||
class GLPrimitiveRenderer
|
||||
{
|
||||
int m_screenWidth;
|
||||
int m_screenHeight;
|
||||
|
||||
struct PrimInternalData* m_data;
|
||||
|
||||
void loadBufferData();
|
||||
|
||||
public:
|
||||
|
||||
GLPrimitiveRenderer(int screenWidth, int screenHeight);
|
||||
virtual ~GLPrimitiveRenderer();
|
||||
|
||||
void drawRect(float x0, float y0, float x1, float y1, float color[4]);
|
||||
void drawTexturedRect(float x0, float y0, float x1, float y1, float color[4], float u0,float v0, float u1, float v1);
|
||||
void drawLine();//float from[4], float to[4], float color[4]);
|
||||
void setScreenSize(int width, int height);
|
||||
|
||||
PrimInternalData* getData()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
};
|
||||
|
||||
#endif//_GL_PRIMITIVE_RENDERER_H
|
||||
|
||||
319
btgui/OpenGLWindow/GwenOpenGL3CoreRenderer.h
Normal file
319
btgui/OpenGLWindow/GwenOpenGL3CoreRenderer.h
Normal file
@@ -0,0 +1,319 @@
|
||||
|
||||
#ifndef __GWEN_OPENGL3_CORE_RENDERER_H
|
||||
#define __GWEN_OPENGL3_CORE_RENDERER_H
|
||||
|
||||
#include "Gwen/Gwen.h"
|
||||
#include "Gwen/BaseRender.h"
|
||||
#include "GLPrimitiveRenderer.h"
|
||||
struct sth_stash;
|
||||
#include "../OpenGLTrueTypeFont/fontstash.h"
|
||||
#include "TwFonts.h"
|
||||
static float extraSpacing = 0.;//6f;
|
||||
#include <assert.h>
|
||||
|
||||
static GLuint BindFont(const CTexFont *_Font)
|
||||
{
|
||||
GLuint TexID = 0;
|
||||
glGenTextures(1, &TexID);
|
||||
glBindTexture(GL_TEXTURE_2D, TexID);
|
||||
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
|
||||
glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
|
||||
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, _Font->m_TexWidth, _Font->m_TexHeight, 0, GL_RED, GL_UNSIGNED_BYTE, _Font->m_TexBytes);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
return TexID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class GwenOpenGL3CoreRenderer : public Gwen::Renderer::Base
|
||||
{
|
||||
GLPrimitiveRenderer* m_primitiveRenderer;
|
||||
float m_currentColor[4];
|
||||
float m_yOffset;
|
||||
sth_stash* m_font;
|
||||
float m_screenWidth;
|
||||
float m_screenHeight;
|
||||
float m_fontScaling;
|
||||
float m_retinaScale;
|
||||
bool m_useTrueTypeFont;
|
||||
const CTexFont* m_currentFont;
|
||||
|
||||
GLuint m_fontTextureId;
|
||||
public:
|
||||
GwenOpenGL3CoreRenderer (GLPrimitiveRenderer* primRender, sth_stash* font,float screenWidth, float screenHeight, float retinaScale)
|
||||
:m_primitiveRenderer(primRender),
|
||||
m_font(font),
|
||||
m_screenWidth(screenWidth),
|
||||
m_screenHeight(screenHeight),
|
||||
m_retinaScale(retinaScale),
|
||||
m_useTrueTypeFont(false)
|
||||
{
|
||||
///only enable true type fonts on Macbook Retina, it looks gorgeous
|
||||
if (retinaScale==2.0f)
|
||||
{
|
||||
m_useTrueTypeFont = true;
|
||||
}
|
||||
m_currentColor[0] = 1;
|
||||
m_currentColor[1] = 1;
|
||||
m_currentColor[2] = 1;
|
||||
m_currentColor[3] = 1;
|
||||
|
||||
m_fontScaling = 16.f*m_retinaScale;
|
||||
|
||||
TwGenerateDefaultFonts();
|
||||
|
||||
m_currentFont = g_DefaultNormalFont;
|
||||
//m_currentFont = g_DefaultNormalFontAA;
|
||||
|
||||
//m_currentFont = g_DefaultLargeFont;
|
||||
m_fontTextureId = BindFont(m_currentFont);
|
||||
|
||||
}
|
||||
|
||||
virtual ~GwenOpenGL3CoreRenderer()
|
||||
{
|
||||
TwDeleteDefaultFonts();
|
||||
}
|
||||
void resize(int width, int height)
|
||||
{
|
||||
m_screenWidth = width;
|
||||
m_screenHeight = height;
|
||||
}
|
||||
|
||||
virtual void Begin()
|
||||
{
|
||||
m_yOffset=0;
|
||||
glEnable(GL_BLEND);
|
||||
GLint err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
//glColor4ub(255,0,0,255);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// saveOpenGLState(width,height);//m_glutScreenWidth,m_glutScreenHeight);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
}
|
||||
virtual void End()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void StartClip()
|
||||
{
|
||||
if (m_useTrueTypeFont)
|
||||
sth_flush_draw(m_font);
|
||||
Gwen::Rect rect = ClipRegion();
|
||||
|
||||
// OpenGL's coords are from the bottom left
|
||||
// so we need to translate them here.
|
||||
{
|
||||
GLint view[4];
|
||||
glGetIntegerv( GL_VIEWPORT, &view[0] );
|
||||
rect.y = view[3]/m_retinaScale - (rect.y + rect.h);
|
||||
}
|
||||
|
||||
glScissor( m_retinaScale * rect.x * Scale(), m_retinaScale * rect.y * Scale(), m_retinaScale * rect.w * Scale(), m_retinaScale * rect.h * Scale() );
|
||||
glEnable( GL_SCISSOR_TEST );
|
||||
//glDisable( GL_SCISSOR_TEST );
|
||||
|
||||
};
|
||||
|
||||
virtual void EndClip()
|
||||
{
|
||||
if (m_useTrueTypeFont)
|
||||
sth_flush_draw(m_font);
|
||||
glDisable( GL_SCISSOR_TEST );
|
||||
};
|
||||
|
||||
virtual void SetDrawColor( Gwen::Color color )
|
||||
{
|
||||
m_currentColor[0] = color.r/256.f;
|
||||
m_currentColor[1] = color.g/256.f;
|
||||
m_currentColor[2] = color.b/256.f;
|
||||
m_currentColor[3] = color.a/256.f;
|
||||
|
||||
}
|
||||
virtual void DrawFilledRect( Gwen::Rect rect )
|
||||
{
|
||||
Translate( rect );
|
||||
|
||||
m_primitiveRenderer->drawRect(rect.x, rect.y+m_yOffset, rect.x+rect.w, rect.y+rect.h+m_yOffset, m_currentColor);
|
||||
// m_yOffset+=rect.h+10;
|
||||
|
||||
}
|
||||
|
||||
void RenderText( Gwen::Font* pFont, Gwen::Point rasterPos, const Gwen::UnicodeString& text )
|
||||
{
|
||||
|
||||
Gwen::String str = Gwen::Utility::UnicodeToString(text);
|
||||
const char* unicodeText = (const char*)str.c_str();
|
||||
|
||||
Gwen::Rect r;
|
||||
r.x = rasterPos.x;
|
||||
r.y = rasterPos.y;
|
||||
r.w = 0;
|
||||
r.h = 0;
|
||||
|
||||
|
||||
//
|
||||
//printf("str = %s\n",unicodeText);
|
||||
int xpos=0;
|
||||
int ypos=0;
|
||||
float dx;
|
||||
|
||||
int measureOnly=0;
|
||||
|
||||
if (m_useTrueTypeFont)
|
||||
{
|
||||
|
||||
float yoffset = 0.f;
|
||||
if (m_retinaScale==2.0f)
|
||||
{
|
||||
yoffset = -12;
|
||||
}
|
||||
Translate(r);
|
||||
sth_draw_text(m_font,
|
||||
1,m_fontScaling,
|
||||
r.x,r.y+yoffset,
|
||||
unicodeText,&dx, m_screenWidth,m_screenHeight,measureOnly,m_retinaScale);
|
||||
|
||||
} else
|
||||
{
|
||||
//float width = 0.f;
|
||||
int pos=0;
|
||||
float color[]={0.2f,0.2,0.2f,1.f};
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D,m_fontTextureId);
|
||||
float width = r.x;
|
||||
while (unicodeText[pos])
|
||||
{
|
||||
int c = unicodeText[pos];
|
||||
r.h = m_currentFont->m_CharHeight;
|
||||
r.w = m_currentFont->m_CharWidth[c]+extraSpacing;
|
||||
Gwen::Rect rect = r;
|
||||
Translate( rect );
|
||||
|
||||
m_primitiveRenderer->drawTexturedRect(rect.x, rect.y+m_yOffset, rect.x+rect.w, rect.y+rect.h+m_yOffset, m_currentColor,m_currentFont->m_CharU0[c],m_currentFont->m_CharV0[c],m_currentFont->m_CharU1[c],m_currentFont->m_CharV1[c]);
|
||||
|
||||
//DrawTexturedRect(0,r,m_currentFont->m_CharU0[c],m_currentFont->m_CharV0[c],m_currentFont->m_CharU1[c],m_currentFont->m_CharV1[c]);
|
||||
// DrawFilledRect(r);
|
||||
|
||||
|
||||
|
||||
width += r.w;
|
||||
r.x = width;
|
||||
pos++;
|
||||
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D,0);
|
||||
}
|
||||
|
||||
}
|
||||
Gwen::Point MeasureText( Gwen::Font* pFont, const Gwen::UnicodeString& text )
|
||||
{
|
||||
Gwen::String str = Gwen::Utility::UnicodeToString(text);
|
||||
const char* unicodeText = (const char*)str.c_str();
|
||||
|
||||
// printf("str = %s\n",unicodeText);
|
||||
int xpos=0;
|
||||
int ypos=0;
|
||||
|
||||
|
||||
int measureOnly=1;
|
||||
float dx=0;
|
||||
if (m_useTrueTypeFont)
|
||||
{
|
||||
sth_draw_text(m_font,
|
||||
1,m_fontScaling,
|
||||
xpos,ypos,
|
||||
unicodeText,&dx, m_screenWidth,m_screenHeight,measureOnly);
|
||||
|
||||
Gwen::Point pt;
|
||||
|
||||
if (m_retinaScale==2.0f)
|
||||
{
|
||||
pt.x = dx*Scale()/2.f;
|
||||
pt.y = m_fontScaling/2*Scale()+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
pt.x = dx*Scale();
|
||||
pt.y = m_fontScaling*Scale()+1;
|
||||
}
|
||||
return pt;
|
||||
}
|
||||
else
|
||||
{
|
||||
float width = 0.f;
|
||||
int pos=0;
|
||||
while (unicodeText[pos])
|
||||
{
|
||||
width += m_currentFont->m_CharWidth[unicodeText[pos]]+extraSpacing;
|
||||
pos++;
|
||||
}
|
||||
Gwen::Point pt;
|
||||
int fontHeight = m_currentFont->m_CharHeight;
|
||||
|
||||
|
||||
pt.x = width*Scale();
|
||||
pt.y = (fontHeight+2) * Scale();
|
||||
|
||||
return pt;
|
||||
}
|
||||
|
||||
return Gwen::Renderer::Base::MeasureText(pFont,text);
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
#endif //__GWEN_OPENGL3_CORE_RENDERER_H
|
||||
101
btgui/OpenGLWindow/LoadShader.cpp
Normal file
101
btgui/OpenGLWindow/LoadShader.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
#include "LoadShader.h"
|
||||
#include "OpenGLInclude.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Load the shader from the source text
|
||||
void gltLoadShaderSrc(const char *szShaderSrc, GLuint shader)
|
||||
{
|
||||
GLchar *fsStringPtr[1];
|
||||
|
||||
fsStringPtr[0] = (GLchar *)szShaderSrc;
|
||||
glShaderSource(shader, 1, (const GLchar **)fsStringPtr, NULL);
|
||||
}
|
||||
|
||||
|
||||
GLuint gltLoadShaderPair(const char *szVertexProg, const char *szFragmentProg)
|
||||
{
|
||||
// Temporary Shader objects
|
||||
GLuint hVertexShader;
|
||||
GLuint hFragmentShader;
|
||||
GLuint hReturn = 0;
|
||||
GLint testVal;
|
||||
|
||||
// Create shader objects
|
||||
hVertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||
hFragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
gltLoadShaderSrc(szVertexProg, hVertexShader);
|
||||
gltLoadShaderSrc(szFragmentProg, hFragmentShader);
|
||||
|
||||
// Compile them
|
||||
glCompileShader(hVertexShader);
|
||||
GLuint err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glCompileShader(hFragmentShader);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
// Check for errors
|
||||
glGetShaderiv(hVertexShader, GL_COMPILE_STATUS, &testVal);
|
||||
if(testVal == GL_FALSE)
|
||||
{
|
||||
char temp[256] = "";
|
||||
glGetShaderInfoLog( hVertexShader, 256, NULL, temp);
|
||||
fprintf( stderr, "Compile failed:\n%s\n", temp);
|
||||
assert(0);
|
||||
return 0;
|
||||
glDeleteShader(hVertexShader);
|
||||
glDeleteShader(hFragmentShader);
|
||||
return (GLuint)NULL;
|
||||
}
|
||||
|
||||
glGetShaderiv(hFragmentShader, GL_COMPILE_STATUS, &testVal);
|
||||
if(testVal == GL_FALSE)
|
||||
{
|
||||
char temp[256] = "";
|
||||
glGetShaderInfoLog( hFragmentShader, 256, NULL, temp);
|
||||
fprintf( stderr, "Compile failed:\n%s\n", temp);
|
||||
assert(0);
|
||||
exit(0);
|
||||
glDeleteShader(hVertexShader);
|
||||
glDeleteShader(hFragmentShader);
|
||||
return (GLuint)NULL;
|
||||
}
|
||||
|
||||
// Link them - assuming it works...
|
||||
hReturn = glCreateProgram();
|
||||
glAttachShader(hReturn, hVertexShader);
|
||||
glAttachShader(hReturn, hFragmentShader);
|
||||
|
||||
glLinkProgram(hReturn);
|
||||
|
||||
// These are no longer needed
|
||||
glDeleteShader(hVertexShader);
|
||||
glDeleteShader(hFragmentShader);
|
||||
|
||||
// Make sure link worked too
|
||||
glGetProgramiv(hReturn, GL_LINK_STATUS, &testVal);
|
||||
if(testVal == GL_FALSE)
|
||||
{
|
||||
GLsizei maxLen = 4096;
|
||||
GLchar infoLog[4096];
|
||||
GLsizei actualLen;
|
||||
|
||||
glGetProgramInfoLog( hReturn,
|
||||
maxLen,
|
||||
&actualLen,
|
||||
infoLog);
|
||||
|
||||
printf("Warning/Error in GLSL shader:\n");
|
||||
printf("%s\n",infoLog);
|
||||
glDeleteProgram(hReturn);
|
||||
return (GLuint)NULL;
|
||||
}
|
||||
|
||||
return hReturn;
|
||||
}
|
||||
|
||||
|
||||
18
btgui/OpenGLWindow/LoadShader.h
Normal file
18
btgui/OpenGLWindow/LoadShader.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef _LOAD_SHADER_H
|
||||
#define _LOAD_SHADER_H
|
||||
|
||||
#include "OpenGLInclude.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif//__cplusplus
|
||||
|
||||
GLuint gltLoadShaderPair(const char *szVertexProg, const char *szFragmentProg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif//__cplusplus
|
||||
|
||||
#endif//_LOAD_SHADER_H
|
||||
|
||||
|
||||
86
btgui/OpenGLWindow/MacOpenGLWindow.h
Normal file
86
btgui/OpenGLWindow/MacOpenGLWindow.h
Normal file
@@ -0,0 +1,86 @@
|
||||
#ifndef MAC_OPENGL_WINDOW_H
|
||||
#define MAC_OPENGL_WINDOW_H
|
||||
|
||||
#include "btgWindowInterface.h"
|
||||
|
||||
#define btgDefaultOpenGLWindow MacOpenGLWindow
|
||||
|
||||
class MacOpenGLWindow : public btgWindowInterface
|
||||
{
|
||||
struct MacOpenGLWindowInternalData* m_internalData;
|
||||
float m_mouseX;
|
||||
float m_mouseY;
|
||||
|
||||
|
||||
btMouseButtonCallback m_mouseButtonCallback;
|
||||
btMouseMoveCallback m_mouseMoveCallback;
|
||||
btWheelCallback m_wheelCallback;
|
||||
btKeyboardCallback m_keyboardCallback;
|
||||
btRenderCallback m_renderCallback;
|
||||
|
||||
float m_retinaScaleFactor;
|
||||
public:
|
||||
|
||||
MacOpenGLWindow();
|
||||
virtual ~MacOpenGLWindow();
|
||||
|
||||
void init(int width, int height, const char* windowTitle);
|
||||
|
||||
void closeWindow();
|
||||
|
||||
void startRendering();
|
||||
|
||||
void endRendering();//swap buffers
|
||||
|
||||
virtual bool requestedExit() const;
|
||||
|
||||
virtual void setRequestExit();
|
||||
|
||||
void getMouseCoordinates(int& x, int& y);
|
||||
|
||||
void runMainLoop();
|
||||
|
||||
void setMouseButtonCallback(btMouseButtonCallback mouseCallback)
|
||||
{
|
||||
m_mouseButtonCallback = mouseCallback;
|
||||
}
|
||||
|
||||
void setMouseMoveCallback(btMouseMoveCallback mouseCallback)
|
||||
{
|
||||
m_mouseMoveCallback = mouseCallback;
|
||||
}
|
||||
|
||||
void setResizeCallback(btResizeCallback resizeCallback);
|
||||
|
||||
void setKeyboardCallback( btKeyboardCallback keyboardCallback)
|
||||
{
|
||||
m_keyboardCallback = keyboardCallback;
|
||||
}
|
||||
|
||||
void setWheelCallback (btWheelCallback wheelCallback)
|
||||
{
|
||||
m_wheelCallback = wheelCallback;
|
||||
}
|
||||
|
||||
float getRetinaScale() const
|
||||
{
|
||||
return m_retinaScaleFactor;
|
||||
}
|
||||
|
||||
virtual void createWindow(const btgWindowConstructionInfo& ci);
|
||||
|
||||
virtual float getTimeInSeconds();
|
||||
|
||||
|
||||
|
||||
virtual void setRenderCallback( btRenderCallback renderCallback);
|
||||
|
||||
virtual void setWindowTitle(const char* title);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
978
btgui/OpenGLWindow/MacOpenGLWindow.mm
Normal file
978
btgui/OpenGLWindow/MacOpenGLWindow.mm
Normal file
@@ -0,0 +1,978 @@
|
||||
#include "MacOpenGLWindow.h"
|
||||
|
||||
#define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#include <OpenGL/gl3.h>
|
||||
#include <OpenGL/gl3ext.h>
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
|
||||
/* report GL errors, if any, to stderr */
|
||||
static void checkError(const char *functionName)
|
||||
{
|
||||
GLenum error;
|
||||
while (( error = glGetError() ) != GL_NO_ERROR)
|
||||
{
|
||||
fprintf (stderr, "GL error 0x%X detected in %s\n", error, functionName);
|
||||
}
|
||||
}
|
||||
|
||||
void dumpInfo(void)
|
||||
{
|
||||
printf ("Vendor: %s\n", glGetString (GL_VENDOR));
|
||||
printf ("Renderer: %s\n", glGetString (GL_RENDERER));
|
||||
printf ("Version: %s\n", glGetString (GL_VERSION));
|
||||
printf ("GLSL: %s\n", glGetString (GL_SHADING_LANGUAGE_VERSION));
|
||||
checkError ("dumpInfo");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -------------------- View ------------------------
|
||||
|
||||
@interface TestView : NSView
|
||||
{
|
||||
NSOpenGLContext* m_context;
|
||||
int m_lastWidth;
|
||||
int m_lastHeight;
|
||||
btResizeCallback m_resizeCallback;
|
||||
|
||||
}
|
||||
-(void)drawRect:(NSRect)rect;
|
||||
-(void) MakeContext:(int) openglVersion;
|
||||
-(void) MakeCurrent;
|
||||
-(float) GetWindowWidth;
|
||||
-(float) GetWindowHeight;
|
||||
-(void) setResizeCallback:(btResizeCallback) callback;
|
||||
@end
|
||||
|
||||
float loop;
|
||||
|
||||
#define Pi 3.1415
|
||||
|
||||
@implementation TestView
|
||||
|
||||
-(float) GetWindowWidth
|
||||
{
|
||||
return m_lastWidth;
|
||||
}
|
||||
-(float) GetWindowHeight
|
||||
{
|
||||
return m_lastHeight;
|
||||
}
|
||||
|
||||
-(void)setResizeCallback:(btResizeCallback)callback
|
||||
{
|
||||
m_resizeCallback = callback;
|
||||
}
|
||||
-(void)drawRect:(NSRect)rect
|
||||
{
|
||||
if (([self frame].size.width != m_lastWidth) || ([self frame].size.height != m_lastHeight))
|
||||
{
|
||||
m_lastWidth = [self frame].size.width;
|
||||
m_lastHeight = [self frame].size.height;
|
||||
|
||||
// Only needed on resize:
|
||||
[m_context clearDrawable];
|
||||
|
||||
// reshape([self frame].size.width, [self frame].size.height);
|
||||
float width = [self frame].size.width;
|
||||
float height = [self frame].size.height;
|
||||
|
||||
|
||||
// Get view dimensions in pixels
|
||||
// glViewport(0,0,10,10);
|
||||
if (m_resizeCallback)
|
||||
{
|
||||
(*m_resizeCallback)(width,height);
|
||||
}
|
||||
|
||||
NSRect backingBounds = [self convertRectToBacking:[self bounds]];
|
||||
GLsizei backingPixelWidth = (GLsizei)(backingBounds.size.width),
|
||||
backingPixelHeight = (GLsizei)(backingBounds.size.height);
|
||||
|
||||
// Set viewport
|
||||
glViewport(0, 0, backingPixelWidth, backingPixelHeight);
|
||||
|
||||
// glViewport(0,0,(GLsizei)width,(GLsizei)height);
|
||||
|
||||
}
|
||||
|
||||
[m_context setView: self];
|
||||
[m_context makeCurrentContext];
|
||||
|
||||
// Draw
|
||||
//display();
|
||||
|
||||
[m_context flushBuffer];
|
||||
[NSOpenGLContext clearCurrentContext];
|
||||
|
||||
loop = loop + 0.1;
|
||||
}
|
||||
|
||||
-(void) MakeContext :(int) openglVersion
|
||||
{
|
||||
// NSWindow *w;
|
||||
NSOpenGLPixelFormat *fmt;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (openglVersion==3)
|
||||
{
|
||||
NSOpenGLPixelFormatAttribute attrs[] =
|
||||
{
|
||||
NSOpenGLPFAOpenGLProfile,
|
||||
NSOpenGLProfileVersion3_2Core,
|
||||
NSOpenGLPFADoubleBuffer,
|
||||
NSOpenGLPFADepthSize, 32,
|
||||
NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)8,
|
||||
(NSOpenGLPixelFormatAttribute)0
|
||||
};
|
||||
|
||||
// Init GL context
|
||||
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes: (NSOpenGLPixelFormatAttribute*)attrs];
|
||||
} else
|
||||
{
|
||||
NSOpenGLPixelFormatAttribute attrs[] =
|
||||
{
|
||||
NSOpenGLPFADoubleBuffer,
|
||||
NSOpenGLPFADepthSize, 32,
|
||||
NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)8,
|
||||
(NSOpenGLPixelFormatAttribute)0
|
||||
};
|
||||
// Init GL context
|
||||
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes: (NSOpenGLPixelFormatAttribute*)attrs];
|
||||
|
||||
}
|
||||
m_context = [[NSOpenGLContext alloc] initWithFormat: fmt shareContext: nil];
|
||||
[fmt release];
|
||||
[m_context makeCurrentContext];
|
||||
|
||||
checkError("makeCurrentContext");
|
||||
}
|
||||
|
||||
-(void) MakeCurrent
|
||||
{
|
||||
[m_context makeCurrentContext];
|
||||
}
|
||||
-(void)windowWillClose:(NSNotification *)note
|
||||
{
|
||||
[[NSApplication sharedApplication] terminate:self];
|
||||
}
|
||||
@end
|
||||
|
||||
struct MacOpenGLWindowInternalData
|
||||
{
|
||||
MacOpenGLWindowInternalData()
|
||||
{
|
||||
m_myApp = 0;
|
||||
m_myview = 0;
|
||||
m_pool = 0;
|
||||
m_window = 0;
|
||||
m_width = -1;
|
||||
m_height = -1;
|
||||
m_exitRequested = false;
|
||||
}
|
||||
NSApplication* m_myApp;
|
||||
TestView* m_myview;
|
||||
NSAutoreleasePool* m_pool;
|
||||
NSWindow* m_window;
|
||||
int m_width;
|
||||
int m_height;
|
||||
bool m_exitRequested;
|
||||
|
||||
};
|
||||
|
||||
MacOpenGLWindow::MacOpenGLWindow()
|
||||
:m_internalData(0),
|
||||
m_mouseX(0),
|
||||
m_mouseY(0),
|
||||
m_mouseMoveCallback(0),
|
||||
m_mouseButtonCallback(0),
|
||||
m_wheelCallback(0),
|
||||
m_keyboardCallback(0),
|
||||
m_retinaScaleFactor(1)
|
||||
{
|
||||
}
|
||||
|
||||
MacOpenGLWindow::~MacOpenGLWindow()
|
||||
{
|
||||
if (m_internalData)
|
||||
closeWindow();
|
||||
}
|
||||
|
||||
|
||||
float MacOpenGLWindow::getTimeInSeconds()
|
||||
{
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
|
||||
void MacOpenGLWindow::setRenderCallback( btRenderCallback renderCallback)
|
||||
{
|
||||
m_renderCallback = renderCallback;
|
||||
}
|
||||
|
||||
void MacOpenGLWindow::setWindowTitle(const char* windowTitle)
|
||||
{
|
||||
[m_internalData->m_window setTitle:[NSString stringWithCString:windowTitle encoding:NSISOLatin1StringEncoding]] ;
|
||||
}
|
||||
|
||||
void MacOpenGLWindow::createWindow(const btgWindowConstructionInfo& ci)
|
||||
{
|
||||
if (m_internalData)
|
||||
closeWindow();
|
||||
|
||||
int width = ci.m_width;
|
||||
int height = ci.m_height;
|
||||
const char* windowTitle = ci.m_title;
|
||||
|
||||
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
m_internalData = new MacOpenGLWindowInternalData;
|
||||
m_internalData->m_width = width;
|
||||
m_internalData->m_height = height;
|
||||
|
||||
m_internalData->m_pool = [NSAutoreleasePool new];
|
||||
m_internalData->m_myApp = [NSApplication sharedApplication];
|
||||
//myApp = [MyApp sharedApplication];
|
||||
//home();
|
||||
|
||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||
|
||||
id menubar = [[NSMenu new] autorelease];
|
||||
id appMenuItem = [[NSMenuItem new] autorelease];
|
||||
[menubar addItem:appMenuItem];
|
||||
[NSApp setMainMenu:menubar];
|
||||
|
||||
id appMenu = [[NSMenu new] autorelease];
|
||||
id appName = [[NSProcessInfo processInfo] processName];
|
||||
id quitTitle = [@"Quit " stringByAppendingString:appName];
|
||||
id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:quitTitle
|
||||
action:@selector(terminate:) keyEquivalent:@"q"] autorelease];
|
||||
|
||||
[appMenu addItem:quitMenuItem];
|
||||
[appMenuItem setSubmenu:appMenu];
|
||||
|
||||
NSMenuItem *fileMenuItem = [[NSMenuItem new] autorelease];
|
||||
NSMenu *fileMenu = [[NSMenu alloc] initWithTitle:@"File"];
|
||||
[fileMenuItem setSubmenu: fileMenu]; // was setMenu:
|
||||
|
||||
NSMenuItem *newMenu = [[NSMenuItem alloc] initWithTitle:@"New" action:NULL keyEquivalent:@""];
|
||||
NSMenuItem *openMenu = [[NSMenuItem alloc] initWithTitle:@"Open" action:NULL keyEquivalent:@""];
|
||||
NSMenuItem *saveMenu = [[NSMenuItem alloc] initWithTitle:@"Save" action:NULL keyEquivalent:@""];
|
||||
|
||||
[fileMenu addItem: newMenu];
|
||||
[fileMenu addItem: openMenu];
|
||||
[fileMenu addItem: saveMenu];
|
||||
[menubar addItem: fileMenuItem];
|
||||
|
||||
|
||||
// add Edit menu
|
||||
NSMenuItem *editMenuItem = [[NSMenuItem new] autorelease];
|
||||
NSMenu *menu = [[NSMenu allocWithZone:[NSMenu menuZone]]initWithTitle:@"Edit"];
|
||||
[editMenuItem setSubmenu: menu];
|
||||
|
||||
NSMenuItem *copyItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]]initWithTitle:@"Copy" action:@selector(copy:) keyEquivalent:@"c"];
|
||||
|
||||
[menu addItem:copyItem];
|
||||
[menubar addItem:editMenuItem];
|
||||
|
||||
// [mainMenu setSubmenu:menu forItem:menuItem];
|
||||
|
||||
|
||||
//NSMenuItem *fileMenuItem = [[NSMenuItem alloc] initWithTitle: @"File"];
|
||||
/*[fileMenuItem setSubmenu: fileMenu]; // was setMenu:
|
||||
[fileMenuItem release];
|
||||
*/
|
||||
|
||||
/*NSMenu *newMenu;
|
||||
NSMenuItem *newItem;
|
||||
|
||||
// Add the submenu
|
||||
newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]]
|
||||
initWithTitle:@"Flashy" action:NULL keyEquivalent:@""];
|
||||
newMenu = [[NSMenu allocWithZone:[NSMenu menuZone]]
|
||||
initWithTitle:@"Flashy"];
|
||||
[newItem setSubmenu:newMenu];
|
||||
[newMenu release];
|
||||
[[NSApp mainMenu] addItem:newItem];
|
||||
[newItem release];
|
||||
*/
|
||||
|
||||
NSRect frame = NSMakeRect(0., 0., width, height);
|
||||
|
||||
m_internalData->m_window = [NSWindow alloc];
|
||||
[m_internalData->m_window initWithContentRect:frame
|
||||
styleMask:NSTitledWindowMask |NSResizableWindowMask| NSClosableWindowMask | NSMiniaturizableWindowMask
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:false];
|
||||
|
||||
|
||||
[m_internalData->m_window setTitle:[NSString stringWithCString:windowTitle encoding:NSISOLatin1StringEncoding]] ;
|
||||
|
||||
m_internalData->m_myview = [TestView alloc];
|
||||
|
||||
[m_internalData->m_myview setResizeCallback:0];
|
||||
|
||||
[m_internalData->m_myview initWithFrame: frame];
|
||||
|
||||
// OpenGL init!
|
||||
[m_internalData->m_myview MakeContext : ci.m_openglVersion];
|
||||
|
||||
// https://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//apple_ref/doc/uid/TP40012302-CH10-SW1
|
||||
//support HighResolutionOSX for Retina Macbook
|
||||
[m_internalData->m_myview setWantsBestResolutionOpenGLSurface:YES];
|
||||
|
||||
NSSize sz;
|
||||
sz.width = 1;
|
||||
sz.height = 1;
|
||||
|
||||
// float newBackingScaleFactor = [m_internalData->m_window backingScaleFactor];
|
||||
|
||||
dumpInfo();
|
||||
|
||||
|
||||
|
||||
|
||||
[m_internalData->m_window setContentView: m_internalData->m_myview];
|
||||
|
||||
GLuint n = 1;
|
||||
GLuint vbo[3]={-1,-1,-1};
|
||||
|
||||
glGenBuffers(n, vbo);
|
||||
checkError("glGenBuffers");
|
||||
|
||||
|
||||
[m_internalData->m_window setDelegate:(id) m_internalData->m_myview];
|
||||
glGenBuffers(n, vbo);
|
||||
checkError("glGenBuffers");
|
||||
|
||||
[m_internalData->m_window makeKeyAndOrderFront: nil];
|
||||
|
||||
[m_internalData->m_myview MakeCurrent];
|
||||
|
||||
glGenBuffers(n, vbo);
|
||||
checkError("glGenBuffers");
|
||||
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
glGenBuffers(n, vbo);
|
||||
checkError("glGenBuffers");
|
||||
|
||||
|
||||
//[m_internalData->m_window setLevel:NSMainMenuWindowLevel];
|
||||
|
||||
// [NSEvent addGlobalMonitorForEventsMatchingMask:NSMouseMovedMask];
|
||||
|
||||
[NSEvent addGlobalMonitorForEventsMatchingMask:NSMouseMovedMask handler:^(NSEvent *event)
|
||||
{
|
||||
//[window setFrameOrigin:[NSEvent mouseLocation]];
|
||||
// NSPoint eventLocation = [m_internalData->m_window mouseLocationOutsideOfEventStream];
|
||||
|
||||
// NSPoint eventLocation = [event locationInWindow];
|
||||
//NSPoint center = [m_internalData->m_myview convertPoint:eventLocation fromView:nil];
|
||||
// m_mouseX = center.x;
|
||||
// m_mouseY = [m_internalData->m_myview GetWindowHeight] - center.y;
|
||||
|
||||
|
||||
// printf("mouse coord = %f, %f\n",m_mouseX,m_mouseY);
|
||||
if (m_mouseMoveCallback)
|
||||
(*m_mouseMoveCallback)(m_mouseX,m_mouseY);
|
||||
|
||||
}];
|
||||
|
||||
//see http://stackoverflow.com/questions/8238473/cant-get-nsmousemoved-events-from-nexteventmatchingmask-with-an-nsopenglview
|
||||
ProcessSerialNumber psn;
|
||||
GetCurrentProcess(&psn);
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
SetFrontProcess(&psn);
|
||||
|
||||
m_retinaScaleFactor = [m_internalData->m_myview convertSizeToBacking:sz].width;
|
||||
|
||||
[m_internalData->m_myApp finishLaunching];
|
||||
[pool release];
|
||||
|
||||
}
|
||||
|
||||
void MacOpenGLWindow::runMainLoop()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
// FILE* dump = fopen ("/Users/erwincoumans/yes.txt","wb");
|
||||
// fclose(dump);
|
||||
|
||||
|
||||
|
||||
|
||||
[pool release];
|
||||
|
||||
}
|
||||
|
||||
void MacOpenGLWindow::closeWindow()
|
||||
{
|
||||
|
||||
delete m_internalData;
|
||||
m_internalData = 0;
|
||||
|
||||
}
|
||||
extern float m_azi;
|
||||
extern float m_ele;
|
||||
extern float m_cameraDistance;
|
||||
|
||||
|
||||
/*
|
||||
* Summary:
|
||||
* Virtual keycodes
|
||||
*
|
||||
* Discussion:
|
||||
* These constants are the virtual keycodes defined originally in
|
||||
* Inside Mac Volume V, pg. V-191. They identify physical keys on a
|
||||
* keyboard. Those constants with "ANSI" in the name are labeled
|
||||
* according to the key position on an ANSI-standard US keyboard.
|
||||
* For example, kVK_ANSI_A indicates the virtual keycode for the key
|
||||
* with the letter 'A' in the US keyboard layout. Other keyboard
|
||||
* layouts may have the 'A' key label on a different physical key;
|
||||
* in this case, pressing 'A' will generate a different virtual
|
||||
* keycode.
|
||||
*/
|
||||
enum {
|
||||
kVK_ANSI_A = 0x00,
|
||||
kVK_ANSI_S = 0x01,
|
||||
kVK_ANSI_D = 0x02,
|
||||
kVK_ANSI_F = 0x03,
|
||||
kVK_ANSI_H = 0x04,
|
||||
kVK_ANSI_G = 0x05,
|
||||
kVK_ANSI_Z = 0x06,
|
||||
kVK_ANSI_X = 0x07,
|
||||
kVK_ANSI_C = 0x08,
|
||||
kVK_ANSI_V = 0x09,
|
||||
kVK_ANSI_B = 0x0B,
|
||||
kVK_ANSI_Q = 0x0C,
|
||||
kVK_ANSI_W = 0x0D,
|
||||
kVK_ANSI_E = 0x0E,
|
||||
kVK_ANSI_R = 0x0F,
|
||||
kVK_ANSI_Y = 0x10,
|
||||
kVK_ANSI_T = 0x11,
|
||||
kVK_ANSI_1 = 0x12,
|
||||
kVK_ANSI_2 = 0x13,
|
||||
kVK_ANSI_3 = 0x14,
|
||||
kVK_ANSI_4 = 0x15,
|
||||
kVK_ANSI_6 = 0x16,
|
||||
kVK_ANSI_5 = 0x17,
|
||||
kVK_ANSI_Equal = 0x18,
|
||||
kVK_ANSI_9 = 0x19,
|
||||
kVK_ANSI_7 = 0x1A,
|
||||
kVK_ANSI_Minus = 0x1B,
|
||||
kVK_ANSI_8 = 0x1C,
|
||||
kVK_ANSI_0 = 0x1D,
|
||||
kVK_ANSI_RightBracket = 0x1E,
|
||||
kVK_ANSI_O = 0x1F,
|
||||
kVK_ANSI_U = 0x20,
|
||||
kVK_ANSI_LeftBracket = 0x21,
|
||||
kVK_ANSI_I = 0x22,
|
||||
kVK_ANSI_P = 0x23,
|
||||
kVK_ANSI_L = 0x25,
|
||||
kVK_ANSI_J = 0x26,
|
||||
kVK_ANSI_Quote = 0x27,
|
||||
kVK_ANSI_K = 0x28,
|
||||
kVK_ANSI_Semicolon = 0x29,
|
||||
kVK_ANSI_Backslash = 0x2A,
|
||||
kVK_ANSI_Comma = 0x2B,
|
||||
kVK_ANSI_Slash = 0x2C,
|
||||
kVK_ANSI_N = 0x2D,
|
||||
kVK_ANSI_M = 0x2E,
|
||||
kVK_ANSI_Period = 0x2F,
|
||||
kVK_ANSI_Grave = 0x32,
|
||||
kVK_ANSI_KeypadDecimal = 0x41,
|
||||
kVK_ANSI_KeypadMultiply = 0x43,
|
||||
kVK_ANSI_KeypadPlus = 0x45,
|
||||
kVK_ANSI_KeypadClear = 0x47,
|
||||
kVK_ANSI_KeypadDivide = 0x4B,
|
||||
kVK_ANSI_KeypadEnter = 0x4C,
|
||||
kVK_ANSI_KeypadMinus = 0x4E,
|
||||
kVK_ANSI_KeypadEquals = 0x51,
|
||||
kVK_ANSI_Keypad0 = 0x52,
|
||||
kVK_ANSI_Keypad1 = 0x53,
|
||||
kVK_ANSI_Keypad2 = 0x54,
|
||||
kVK_ANSI_Keypad3 = 0x55,
|
||||
kVK_ANSI_Keypad4 = 0x56,
|
||||
kVK_ANSI_Keypad5 = 0x57,
|
||||
kVK_ANSI_Keypad6 = 0x58,
|
||||
kVK_ANSI_Keypad7 = 0x59,
|
||||
kVK_ANSI_Keypad8 = 0x5B,
|
||||
kVK_ANSI_Keypad9 = 0x5C
|
||||
};
|
||||
|
||||
/* keycodes for keys that are independent of keyboard layout*/
|
||||
enum {
|
||||
kVK_Return = 0x24,
|
||||
kVK_Tab = 0x30,
|
||||
kVK_Space = 0x31,
|
||||
kVK_Delete = 0x33,
|
||||
kVK_Escape = 0x35,
|
||||
kVK_Command = 0x37,
|
||||
kVK_Shift = 0x38,
|
||||
kVK_CapsLock = 0x39,
|
||||
kVK_Option = 0x3A,
|
||||
kVK_Control = 0x3B,
|
||||
kVK_RightShift = 0x3C,
|
||||
kVK_RightOption = 0x3D,
|
||||
kVK_RightControl = 0x3E,
|
||||
kVK_Function = 0x3F,
|
||||
kVK_F17 = 0x40,
|
||||
kVK_VolumeUp = 0x48,
|
||||
kVK_VolumeDown = 0x49,
|
||||
kVK_Mute = 0x4A,
|
||||
kVK_F18 = 0x4F,
|
||||
kVK_F19 = 0x50,
|
||||
kVK_F20 = 0x5A,
|
||||
kVK_F5 = 0x60,
|
||||
kVK_F6 = 0x61,
|
||||
kVK_F7 = 0x62,
|
||||
kVK_F3 = 0x63,
|
||||
kVK_F8 = 0x64,
|
||||
kVK_F9 = 0x65,
|
||||
kVK_F11 = 0x67,
|
||||
kVK_F13 = 0x69,
|
||||
kVK_F16 = 0x6A,
|
||||
kVK_F14 = 0x6B,
|
||||
kVK_F10 = 0x6D,
|
||||
kVK_F12 = 0x6F,
|
||||
kVK_F15 = 0x71,
|
||||
kVK_Help = 0x72,
|
||||
kVK_Home = 0x73,
|
||||
kVK_PageUp = 0x74,
|
||||
kVK_ForwardDelete = 0x75,
|
||||
kVK_F4 = 0x76,
|
||||
kVK_End = 0x77,
|
||||
kVK_F2 = 0x78,
|
||||
kVK_PageDown = 0x79,
|
||||
kVK_F1 = 0x7A,
|
||||
kVK_LeftArrow = 0x7B,
|
||||
kVK_RightArrow = 0x7C,
|
||||
kVK_DownArrow = 0x7D,
|
||||
kVK_UpArrow = 0x7E
|
||||
};
|
||||
|
||||
/* ISO keyboards only*/
|
||||
enum {
|
||||
kVK_ISO_Section = 0x0A
|
||||
};
|
||||
|
||||
/* JIS keyboards only*/
|
||||
enum {
|
||||
kVK_JIS_Yen = 0x5D,
|
||||
kVK_JIS_Underscore = 0x5E,
|
||||
kVK_JIS_KeypadComma = 0x5F,
|
||||
kVK_JIS_Eisu = 0x66,
|
||||
kVK_JIS_Kana = 0x68
|
||||
};
|
||||
|
||||
int getAsciiCodeFromVirtualKeycode(int virtualKeyCode)
|
||||
{
|
||||
int keycode = 0xffffffff;
|
||||
|
||||
switch (virtualKeyCode)
|
||||
{
|
||||
|
||||
case kVK_ANSI_A : {keycode = 'A'; break;}
|
||||
case kVK_ANSI_B : {keycode = 'B'; break;}
|
||||
case kVK_ANSI_C : {keycode = 'C'; break;}
|
||||
case kVK_ANSI_D : {keycode = 'D';break;}
|
||||
case kVK_ANSI_E : {keycode = 'E'; break;}
|
||||
case kVK_ANSI_F : {keycode = 'F'; break;}
|
||||
case kVK_ANSI_G : {keycode = 'G'; break;}
|
||||
case kVK_ANSI_H : {keycode = 'H'; break;}
|
||||
case kVK_ANSI_I : {keycode = 'I'; break;}
|
||||
case kVK_ANSI_J : {keycode = 'J'; break;}
|
||||
case kVK_ANSI_K : {keycode = 'K'; break;}
|
||||
case kVK_ANSI_L : {keycode = 'L'; break;}
|
||||
case kVK_ANSI_M : {keycode = 'M'; break;}
|
||||
case kVK_ANSI_N : {keycode = 'N'; break;}
|
||||
case kVK_ANSI_O : {keycode = 'O'; break;}
|
||||
case kVK_ANSI_P : {keycode = 'P'; break;}
|
||||
case kVK_ANSI_Q : {keycode = 'Q'; break;}
|
||||
case kVK_ANSI_R : {keycode = 'R'; break;}
|
||||
case kVK_ANSI_S : {keycode = 'S';break;}
|
||||
case kVK_ANSI_T : {keycode = 'T'; break;}
|
||||
case kVK_ANSI_U : {keycode = 'U'; break;}
|
||||
case kVK_ANSI_V : {keycode = 'V'; break;}
|
||||
case kVK_ANSI_W : {keycode = 'W'; break;}
|
||||
case kVK_ANSI_X : {keycode = 'X'; break;}
|
||||
case kVK_ANSI_Y : {keycode = 'Y'; break;}
|
||||
case kVK_ANSI_Z : {keycode = 'Z'; break;}
|
||||
|
||||
case kVK_ANSI_1 : {keycode = '1'; break;}
|
||||
case kVK_ANSI_2 : {keycode = '2'; break;}
|
||||
case kVK_ANSI_3 : {keycode = '3'; break;}
|
||||
case kVK_ANSI_4 : {keycode = '4'; break;}
|
||||
case kVK_ANSI_5 : {keycode = '5'; break;}
|
||||
case kVK_ANSI_6 : {keycode = '6'; break;}
|
||||
case kVK_ANSI_7 : {keycode = '7'; break;}
|
||||
case kVK_ANSI_8 : {keycode = '8'; break;}
|
||||
case kVK_ANSI_9 : {keycode = '9'; break;}
|
||||
case kVK_ANSI_0 : {keycode = '0'; break;}
|
||||
case kVK_ANSI_Equal : {keycode = '='; break;}
|
||||
case kVK_ANSI_Minus : {keycode = '-'; break;}
|
||||
|
||||
case kVK_Tab: {keycode = 9; break;}
|
||||
case kVK_Space: {keycode=' '; break;}
|
||||
case kVK_Escape: {keycode=27; break;}
|
||||
case kVK_Delete: {keycode=8; break;}
|
||||
case kVK_ForwardDelete: {keycode=BTG_INSERT; break;}
|
||||
|
||||
|
||||
case kVK_F1: {keycode = BTG_F1; break;}
|
||||
case kVK_F2: {keycode = BTG_F2; break;}
|
||||
case kVK_F3: {keycode = BTG_F3; break;}
|
||||
case kVK_F4: {keycode = BTG_F4; break;}
|
||||
case kVK_F5: {keycode = BTG_F5; break;}
|
||||
case kVK_F6: {keycode = BTG_F6; break;}
|
||||
case kVK_F7: {keycode = BTG_F7; break;}
|
||||
case kVK_F8: {keycode = BTG_F8; break;}
|
||||
case kVK_F9: {keycode = BTG_F9; break;}
|
||||
case kVK_F10: {keycode = BTG_F10; break;}
|
||||
case kVK_F11: {keycode = BTG_F11; break;}
|
||||
case kVK_F12: {keycode = BTG_F12; break;}
|
||||
case kVK_F13: {keycode = BTG_F13; break;}
|
||||
case kVK_F14: {keycode = BTG_F14; break;}
|
||||
case kVK_F15: {keycode = BTG_F15; break;}
|
||||
|
||||
case kVK_LeftArrow: {keycode = BTG_LEFT_ARROW;break;}
|
||||
case kVK_RightArrow: {keycode = BTG_RIGHT_ARROW;break;}
|
||||
case kVK_UpArrow: {keycode = BTG_UP_ARROW;break;}
|
||||
case kVK_DownArrow: {keycode = BTG_DOWN_ARROW;break;}
|
||||
|
||||
case kVK_PageUp :{keycode = BTG_PAGE_UP;break;}
|
||||
case kVK_PageDown :{keycode = BTG_PAGE_DOWN;break;}
|
||||
case kVK_End :{keycode = BTG_END;break;}
|
||||
case kVK_Home :{keycode = BTG_HOME;break;}
|
||||
|
||||
case kVK_ANSI_RightBracket : {keycode = ']'; break;}
|
||||
case kVK_ANSI_LeftBracket : {keycode = '['; break;}
|
||||
case kVK_ANSI_Quote : {keycode = '\''; break;}
|
||||
case kVK_ANSI_Semicolon : {keycode = ';'; break;}
|
||||
case kVK_ANSI_Backslash : {keycode = '\\'; break;}
|
||||
case kVK_ANSI_Comma : {keycode = ','; break;}
|
||||
case kVK_ANSI_Slash : {keycode = '/'; break;}
|
||||
case kVK_ANSI_Period : {keycode = '.'; break;}
|
||||
case kVK_ANSI_Grave : {keycode = '`'; break;}
|
||||
case kVK_ANSI_KeypadDecimal : {keycode = '.'; break;}
|
||||
case kVK_ANSI_KeypadMultiply : {keycode = '*'; break;}
|
||||
case kVK_ANSI_KeypadPlus : {keycode = '+'; break;}
|
||||
case kVK_ANSI_KeypadClear : {keycode = '?'; break;}
|
||||
case kVK_ANSI_KeypadDivide : {keycode = '/'; break;}
|
||||
case kVK_ANSI_KeypadEnter : {keycode = 13; break;}
|
||||
case kVK_ANSI_KeypadMinus : {keycode = '-'; break;}
|
||||
case kVK_ANSI_KeypadEquals : {keycode = '='; break;}
|
||||
case kVK_ANSI_Keypad0 : {keycode = '0'; break;}
|
||||
case kVK_ANSI_Keypad1 : {keycode = '1'; break;}
|
||||
case kVK_ANSI_Keypad2 : {keycode = '2'; break;}
|
||||
case kVK_ANSI_Keypad3 : {keycode = '3'; break;}
|
||||
case kVK_ANSI_Keypad4 : {keycode = '4'; break;}
|
||||
case kVK_ANSI_Keypad5 : {keycode = '5'; break;}
|
||||
case kVK_ANSI_Keypad6 : {keycode = '6'; break;}
|
||||
case kVK_ANSI_Keypad7 : {keycode = '7'; break;}
|
||||
case kVK_ANSI_Keypad8 : {keycode = '8'; break;}
|
||||
case kVK_ANSI_Keypad9 : {keycode = '9'; break;}
|
||||
|
||||
default:
|
||||
{
|
||||
|
||||
printf("unknown keycode\n");
|
||||
}
|
||||
}
|
||||
return keycode;
|
||||
}
|
||||
|
||||
|
||||
void MacOpenGLWindow::startRendering()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
GLint err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
NSEvent *event = nil;
|
||||
bool handledEvent = false;
|
||||
|
||||
do
|
||||
{
|
||||
[pool release];
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
event = [m_internalData->m_myApp
|
||||
nextEventMatchingMask:NSAnyEventMask
|
||||
untilDate:[NSDate distantPast]
|
||||
inMode:NSDefaultRunLoopMode
|
||||
// inMode:NSEventTrackingRunLoopMode
|
||||
dequeue:YES];
|
||||
|
||||
//NSShiftKeyMask = 1 << 17,
|
||||
//NSControlKeyMask
|
||||
|
||||
if ([event modifierFlags] & NSAlternateKeyMask)
|
||||
{
|
||||
printf("!");
|
||||
}
|
||||
|
||||
if ([event type] == NSKeyUp)
|
||||
{
|
||||
handledEvent = true;
|
||||
|
||||
uint32 virtualKeycode = [event keyCode];
|
||||
|
||||
int keycode = getAsciiCodeFromVirtualKeycode(virtualKeycode);
|
||||
printf("keycode = %d\n", keycode);
|
||||
|
||||
if (m_keyboardCallback)
|
||||
{
|
||||
int state = 0;
|
||||
m_keyboardCallback(keycode,state);
|
||||
}
|
||||
}
|
||||
if ([event type] == NSKeyDown)
|
||||
{
|
||||
handledEvent = true;
|
||||
|
||||
if (![event isARepeat])
|
||||
{
|
||||
uint32 virtualKeycode = [event keyCode];
|
||||
|
||||
int keycode = getAsciiCodeFromVirtualKeycode(virtualKeycode);
|
||||
printf("keycode = %d\n", keycode);
|
||||
|
||||
if (m_keyboardCallback)
|
||||
{
|
||||
int state = 1;
|
||||
m_keyboardCallback(keycode,state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ([event type]== NSLeftMouseUp)
|
||||
{
|
||||
// printf("right mouse!");
|
||||
|
||||
NSPoint eventLocation = [event locationInWindow];
|
||||
NSPoint center = [m_internalData->m_myview convertPoint:eventLocation fromView:nil];
|
||||
m_mouseX = center.x;
|
||||
m_mouseY = [m_internalData->m_myview GetWindowHeight] - center.y;
|
||||
|
||||
|
||||
// printf("mouse coord = %f, %f\n",mouseX,mouseY);
|
||||
if (m_mouseButtonCallback)
|
||||
{
|
||||
(*m_mouseButtonCallback)(0,0,m_mouseX,m_mouseY);
|
||||
handledEvent = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ([event type]== NSLeftMouseDown)
|
||||
{
|
||||
// printf("right mouse!");
|
||||
|
||||
NSPoint eventLocation = [event locationInWindow];
|
||||
NSPoint center = [m_internalData->m_myview convertPoint:eventLocation fromView:nil];
|
||||
m_mouseX = center.x;
|
||||
m_mouseY = [m_internalData->m_myview GetWindowHeight] - center.y;
|
||||
|
||||
// printf("mouse coord = %f, %f\n",mouseX,mouseY);
|
||||
if (m_mouseButtonCallback)
|
||||
{
|
||||
handledEvent = true;
|
||||
(*m_mouseButtonCallback)(0,1,m_mouseX,m_mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ([event type]== NSRightMouseDown)
|
||||
{
|
||||
// printf("right mouse!");
|
||||
// float mouseX,mouseY;
|
||||
|
||||
NSPoint eventLocation = [event locationInWindow];
|
||||
NSPoint center = [m_internalData->m_myview convertPoint:eventLocation fromView:nil];
|
||||
m_mouseX = center.x;
|
||||
m_mouseY = [m_internalData->m_myview GetWindowHeight] - center.y;
|
||||
|
||||
// printf("mouse coord = %f, %f\n",mouseX,mouseY);
|
||||
if (m_mouseButtonCallback)
|
||||
{
|
||||
handledEvent = true;
|
||||
(*m_mouseButtonCallback)(2,1,m_mouseX,m_mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ([event type]== NSRightMouseUp)
|
||||
{
|
||||
// printf("right mouse!");
|
||||
// float mouseX,mouseY;
|
||||
|
||||
NSPoint eventLocation = [event locationInWindow];
|
||||
NSPoint center = [m_internalData->m_myview convertPoint:eventLocation fromView:nil];
|
||||
m_mouseX = center.x;
|
||||
m_mouseY = [m_internalData->m_myview GetWindowHeight] - center.y;
|
||||
|
||||
// printf("mouse coord = %f, %f\n",mouseX,mouseY);
|
||||
if (m_mouseButtonCallback)
|
||||
(*m_mouseButtonCallback)(2,0,m_mouseX,m_mouseY);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ([event type] == NSMouseMoved)
|
||||
{
|
||||
|
||||
NSPoint eventLocation = [event locationInWindow];
|
||||
NSPoint center = [m_internalData->m_myview convertPoint:eventLocation fromView:nil];
|
||||
m_mouseX = center.x;
|
||||
m_mouseY = [m_internalData->m_myview GetWindowHeight] - center.y;
|
||||
|
||||
|
||||
// printf("mouse coord = %f, %f\n",m_mouseX,m_mouseY);
|
||||
if (m_mouseMoveCallback)
|
||||
{
|
||||
handledEvent = true;
|
||||
(*m_mouseMoveCallback)(m_mouseX,m_mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
if ([event type] == NSLeftMouseDragged)
|
||||
{
|
||||
CGMouseDelta dx1, dy1;
|
||||
CGGetLastMouseDelta (&dx1, &dy1);
|
||||
|
||||
NSPoint eventLocation = [event locationInWindow];
|
||||
NSPoint center = [m_internalData->m_myview convertPoint:eventLocation fromView:nil];
|
||||
m_mouseX = center.x;
|
||||
m_mouseY = [m_internalData->m_myview GetWindowHeight] - center.y;
|
||||
|
||||
if (m_mouseMoveCallback)
|
||||
{
|
||||
handledEvent = true;
|
||||
(*m_mouseMoveCallback)(m_mouseX,m_mouseY);
|
||||
}
|
||||
|
||||
// printf("mouse coord = %f, %f\n",m_mouseX,m_mouseY);
|
||||
}
|
||||
|
||||
if ([event type] == NSScrollWheel)
|
||||
{
|
||||
float dy, dx;
|
||||
dy = [ event deltaY ];
|
||||
dx = [ event deltaX ];
|
||||
|
||||
if (m_wheelCallback)
|
||||
{
|
||||
handledEvent = true;
|
||||
(*m_wheelCallback)(dx,dy);
|
||||
}
|
||||
// m_cameraDistance -= dy*0.1;
|
||||
// m_azi -= dx*0.1;
|
||||
|
||||
}
|
||||
|
||||
//if (!handledEvent)
|
||||
[m_internalData->m_myApp sendEvent:event];
|
||||
|
||||
[m_internalData->m_myApp updateWindows];
|
||||
} while (event);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
[m_internalData->m_myview MakeCurrent];
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
glClearColor(1,1,1,1);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //clear buffers
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
//glCullFace(GL_BACK);
|
||||
//glFrontFace(GL_CCW);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
float aspect;
|
||||
//btVector3 extents;
|
||||
|
||||
if (m_internalData->m_width > m_internalData->m_height)
|
||||
{
|
||||
aspect = (float)m_internalData->m_width / (float)m_internalData->m_height;
|
||||
//extents.setValue(aspect * 1.0f, 1.0f,0);
|
||||
} else
|
||||
{
|
||||
aspect = (float)m_internalData->m_height / (float)m_internalData->m_width;
|
||||
//extents.setValue(1.0f, aspect*1.f,0);
|
||||
}
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
[pool release];
|
||||
|
||||
}
|
||||
|
||||
void MacOpenGLWindow::endRendering()
|
||||
{
|
||||
[m_internalData->m_myview MakeCurrent];
|
||||
glSwapAPPLE();
|
||||
}
|
||||
|
||||
bool MacOpenGLWindow::requestedExit() const
|
||||
{
|
||||
return m_internalData->m_exitRequested;
|
||||
}
|
||||
|
||||
void MacOpenGLWindow::setRequestExit()
|
||||
{
|
||||
m_internalData->m_exitRequested = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void MacOpenGLWindow::getMouseCoordinates(int& x, int& y)
|
||||
{
|
||||
|
||||
NSPoint pt = [m_internalData->m_window mouseLocationOutsideOfEventStream];
|
||||
m_mouseX = pt.x;
|
||||
m_mouseY = pt.y;
|
||||
|
||||
x = m_mouseX;
|
||||
//our convention is x,y is upper left hand side
|
||||
y = [m_internalData->m_myview GetWindowHeight]-m_mouseY;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void MacOpenGLWindow::setResizeCallback(btResizeCallback resizeCallback)
|
||||
{
|
||||
[m_internalData->m_myview setResizeCallback:resizeCallback];
|
||||
}
|
||||
|
||||
|
||||
51
btgui/OpenGLWindow/OpenGLInclude.h
Normal file
51
btgui/OpenGLWindow/OpenGLInclude.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright (c) 2012 Advanced Micro Devices, Inc.
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
//Originally written by Erwin Coumans
|
||||
|
||||
|
||||
#ifndef __OPENGL_INCLUDE_H
|
||||
#define __OPENGL_INCLUDE_H
|
||||
|
||||
|
||||
//think different
|
||||
#if defined(__APPLE__) && !defined (VMDMESA)
|
||||
#include <OpenGL/OpenGL.h>
|
||||
//#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glu.h>
|
||||
//#import <Cocoa/Cocoa.h>
|
||||
#include <OpenGL/gl3.h>
|
||||
#else
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include <windows.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#endif //_WINDOWS
|
||||
#endif //APPLE
|
||||
|
||||
|
||||
|
||||
///on Linux only glDrawElementsInstancedARB is defined?!?
|
||||
#ifdef __linux
|
||||
#define glDrawElementsInstanced glDrawElementsInstancedARB
|
||||
|
||||
#endif //__linux
|
||||
|
||||
#endif //__OPENGL_INCLUDE_H
|
||||
|
||||
4802
btgui/OpenGLWindow/ShapeData.h
Normal file
4802
btgui/OpenGLWindow/ShapeData.h
Normal file
File diff suppressed because it is too large
Load Diff
4916
btgui/OpenGLWindow/TwFonts.cpp
Normal file
4916
btgui/OpenGLWindow/TwFonts.cpp
Normal file
File diff suppressed because it is too large
Load Diff
67
btgui/OpenGLWindow/TwFonts.h
Normal file
67
btgui/OpenGLWindow/TwFonts.h
Normal file
@@ -0,0 +1,67 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// @file TwFonts.h
|
||||
// @brief Bitmaps fonts
|
||||
// @author Philippe Decaudin - http://www.antisphere.com
|
||||
// @license This file is part of the AntTweakBar library.
|
||||
// For conditions of distribution and use, see License.txt
|
||||
//
|
||||
// note: Private header
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
#if !defined ANT_TW_FONTS_INCLUDED
|
||||
#define ANT_TW_FONTS_INCLUDED
|
||||
|
||||
//#include <AntTweakBar.h>
|
||||
|
||||
/*
|
||||
A source bitmap includes 224 characters starting from ascii char 32 (i.e. space) to ascii char 255:
|
||||
|
||||
!"#$%&'()*+,-./0123456789:;<=>?
|
||||
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
|
||||
`abcdefghijklmnopqrstuvwxyz{|}~
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
First column of a source bitmap is a delimiter with color=zero at the end of each line of characters.
|
||||
Last row of a line of characters is a delimiter with color=zero at the last pixel of each character.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
struct CTexFont
|
||||
{
|
||||
unsigned char * m_TexBytes;
|
||||
int m_TexWidth; // power of 2
|
||||
int m_TexHeight; // power of 2
|
||||
float m_CharU0[256];
|
||||
float m_CharV0[256];
|
||||
float m_CharU1[256];
|
||||
float m_CharV1[256];
|
||||
int m_CharWidth[256];
|
||||
int m_CharHeight;
|
||||
int m_NbCharRead;
|
||||
|
||||
CTexFont();
|
||||
~CTexFont();
|
||||
};
|
||||
|
||||
|
||||
CTexFont *TwGenerateFont(const unsigned char *_Bitmap, int _BmWidth, int _BmHeight);
|
||||
|
||||
|
||||
extern CTexFont *g_DefaultSmallFont;
|
||||
extern CTexFont *g_DefaultNormalFont;
|
||||
extern CTexFont *g_DefaultNormalFontAA;
|
||||
extern CTexFont *g_DefaultLargeFont;
|
||||
extern CTexFont *g_DefaultFixed1Font;
|
||||
|
||||
void TwGenerateDefaultFonts();
|
||||
void TwDeleteDefaultFonts();
|
||||
|
||||
|
||||
#endif // !defined ANT_TW_FONTS_INCLUDED
|
||||
65
btgui/OpenGLWindow/Win32InternalWindowData.h
Normal file
65
btgui/OpenGLWindow/Win32InternalWindowData.h
Normal file
@@ -0,0 +1,65 @@
|
||||
|
||||
#ifndef WIN32_INTERNAL_WINDOW_DATA_H
|
||||
#define WIN32_INTERNAL_WINDOW_DATA_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
struct InternalData2
|
||||
{
|
||||
HWND m_hWnd;;
|
||||
int m_fullWindowWidth;//includes borders etc
|
||||
int m_fullWindowHeight;
|
||||
|
||||
int m_openglViewportWidth;//just the 3d viewport/client area
|
||||
int m_openglViewportHeight;
|
||||
|
||||
HDC m_hDC;
|
||||
HGLRC m_hRC;
|
||||
bool m_OpenGLInitialized;
|
||||
int m_oldScreenWidth;
|
||||
int m_oldHeight;
|
||||
int m_oldBitsPerPel;
|
||||
bool m_quit;
|
||||
int m_mouseLButton;
|
||||
int m_mouseRButton;
|
||||
int m_mouseMButton;
|
||||
int m_mouseXpos;
|
||||
int m_mouseYpos;
|
||||
|
||||
btWheelCallback m_wheelCallback;
|
||||
btMouseMoveCallback m_mouseMoveCallback;
|
||||
btMouseButtonCallback m_mouseButtonCallback;
|
||||
btResizeCallback m_resizeCallback;
|
||||
btKeyboardCallback m_keyboardCallback;
|
||||
|
||||
|
||||
|
||||
InternalData2()
|
||||
{
|
||||
m_hWnd = 0;
|
||||
m_mouseLButton=0;
|
||||
m_mouseRButton=0;
|
||||
m_mouseMButton=0;
|
||||
|
||||
m_fullWindowWidth = 0;
|
||||
m_fullWindowHeight= 0;
|
||||
m_openglViewportHeight=0;
|
||||
m_openglViewportWidth=0;
|
||||
m_hDC = 0;
|
||||
m_hRC = 0;
|
||||
m_OpenGLInitialized = false;
|
||||
m_oldScreenWidth = 0;
|
||||
m_oldHeight = 0;
|
||||
m_oldBitsPerPel = 0;
|
||||
m_quit = false;
|
||||
|
||||
m_keyboardCallback = 0;
|
||||
m_mouseMoveCallback = 0;
|
||||
m_mouseButtonCallback = 0;
|
||||
m_resizeCallback = 0;
|
||||
m_wheelCallback = 0;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
#endif //WIN32_INTERNAL_WINDOW_DATA_H
|
||||
139
btgui/OpenGLWindow/Win32OpenGLWindow.cpp
Normal file
139
btgui/OpenGLWindow/Win32OpenGLWindow.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
Copyright (c) 2012 Advanced Micro Devices, Inc.
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
//Originally written by Erwin Coumans
|
||||
|
||||
|
||||
#include "Win32OpenGLWindow.h"
|
||||
|
||||
#include "OpenGLInclude.h"
|
||||
|
||||
#include "BulletCommon/btVector3.h"
|
||||
|
||||
#include "Win32InternalWindowData.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static void printGLString(const char *name, GLenum s) {
|
||||
const char *v = (const char *) glGetString(s);
|
||||
printf("GL %s = %s\n", name, v);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Win32OpenGLWindow::enableOpenGL()
|
||||
{
|
||||
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
int format;
|
||||
|
||||
// get the device context (DC)
|
||||
m_data->m_hDC = GetDC( m_data->m_hWnd );
|
||||
|
||||
// set the pixel format for the DC
|
||||
ZeroMemory( &pfd, sizeof( pfd ) );
|
||||
pfd.nSize = sizeof( pfd );
|
||||
pfd.nVersion = 1;
|
||||
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.iLayerType = PFD_MAIN_PLANE;
|
||||
format = ChoosePixelFormat( m_data->m_hDC, &pfd );
|
||||
SetPixelFormat( m_data->m_hDC, format, &pfd );
|
||||
|
||||
// create and enable the render context (RC)
|
||||
m_data->m_hRC = wglCreateContext( m_data->m_hDC );
|
||||
wglMakeCurrent( m_data->m_hDC, m_data->m_hRC );
|
||||
|
||||
printGLString("Version", GL_VERSION);
|
||||
printGLString("Vendor", GL_VENDOR);
|
||||
printGLString("Renderer", GL_RENDERER);
|
||||
printGLString("Extensions", GL_EXTENSIONS);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Win32OpenGLWindow::disableOpenGL()
|
||||
{
|
||||
wglMakeCurrent( NULL, NULL );
|
||||
wglDeleteContext( m_data->m_hRC );
|
||||
// ReleaseDC( m_data->m_hWnd, m_data->m_hDC );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Win32OpenGLWindow::createWindow(const btgWindowConstructionInfo& ci)
|
||||
{
|
||||
Win32Window::createWindow(ci);
|
||||
|
||||
//VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, this);
|
||||
enableOpenGL();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Win32OpenGLWindow::Win32OpenGLWindow()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
Win32OpenGLWindow::~Win32OpenGLWindow()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Win32OpenGLWindow::closeWindow()
|
||||
{
|
||||
disableOpenGL();
|
||||
|
||||
Win32Window::closeWindow();
|
||||
}
|
||||
|
||||
|
||||
void Win32OpenGLWindow::startRendering()
|
||||
{
|
||||
pumpMessage();
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //clear buffers
|
||||
|
||||
//glCullFace(GL_BACK);
|
||||
//glFrontFace(GL_CCW);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Win32OpenGLWindow::renderAllObjects()
|
||||
{
|
||||
}
|
||||
|
||||
void Win32OpenGLWindow::endRendering()
|
||||
{
|
||||
SwapBuffers( m_data->m_hDC );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
58
btgui/OpenGLWindow/Win32OpenGLWindow.h
Normal file
58
btgui/OpenGLWindow/Win32OpenGLWindow.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Copyright (c) 2012 Advanced Micro Devices, Inc.
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
//Originally written by Erwin Coumans
|
||||
|
||||
|
||||
#ifndef _WIN32_OPENGL_RENDER_MANAGER_H
|
||||
#define _WIN32_OPENGL_RENDER_MANAGER_H
|
||||
|
||||
|
||||
|
||||
#include "Win32Window.h"
|
||||
|
||||
#define btgDefaultOpenGLWindow Win32OpenGLWindow
|
||||
|
||||
class Win32OpenGLWindow : public Win32Window
|
||||
{
|
||||
bool m_OpenGLInitialized;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
void enableOpenGL();
|
||||
|
||||
void disableOpenGL();
|
||||
|
||||
public:
|
||||
|
||||
Win32OpenGLWindow();
|
||||
|
||||
virtual ~Win32OpenGLWindow();
|
||||
|
||||
virtual void createWindow(const btgWindowConstructionInfo& ci);
|
||||
|
||||
virtual void closeWindow();
|
||||
|
||||
virtual void startRendering();
|
||||
|
||||
virtual void renderAllObjects();
|
||||
|
||||
virtual void endRendering();
|
||||
|
||||
virtual float getRetinaScale() const {return 1.f;}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //_WIN32_OPENGL_RENDER_MANAGER_H
|
||||
675
btgui/OpenGLWindow/Win32Window.cpp
Normal file
675
btgui/OpenGLWindow/Win32Window.cpp
Normal file
@@ -0,0 +1,675 @@
|
||||
/*
|
||||
Copyright (c) 2012 Advanced Micro Devices, Inc.
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
//Originally written by Erwin Coumans
|
||||
|
||||
|
||||
#include "Win32Window.h"
|
||||
|
||||
#include "OpenGLInclude.h"
|
||||
#include "BulletCommon/btVector3.h"
|
||||
#include <wchar.h>
|
||||
static InternalData2* sData = 0;
|
||||
|
||||
#include "Win32InternalWindowData.h"
|
||||
|
||||
|
||||
|
||||
|
||||
void Win32Window::pumpMessage()
|
||||
{
|
||||
MSG msg;
|
||||
// check for messages
|
||||
//'if' instead of 'while' can make mainloop smoother.
|
||||
//@todo: use separate threads for input and rendering
|
||||
while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
|
||||
{
|
||||
|
||||
// handle or dispatch messages
|
||||
if ( msg.message == WM_QUIT )
|
||||
{
|
||||
m_data->m_quit = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
TranslateMessage( &msg );
|
||||
DispatchMessage( &msg );
|
||||
}
|
||||
|
||||
// gDemoApplication->displayCallback();
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
int getAsciiCodeFromVirtualKeycode(int virtualKeyCode)
|
||||
{
|
||||
int keycode = 0xffffffff;
|
||||
switch (virtualKeyCode)
|
||||
{
|
||||
case VK_F1: {keycode = BTG_F1; break;}
|
||||
case VK_F2: {keycode = BTG_F2; break;}
|
||||
case VK_F3: {keycode = BTG_F3; break;}
|
||||
case VK_F4: {keycode = BTG_F4; break;}
|
||||
case VK_F5: {keycode = BTG_F5; break;}
|
||||
case VK_F6: {keycode = BTG_F6; break;}
|
||||
case VK_F7: {keycode = BTG_F7; break;}
|
||||
case VK_F8: {keycode = BTG_F8; break;}
|
||||
case VK_F9: {keycode = BTG_F9; break;}
|
||||
case VK_F10: {keycode= BTG_F10; break;}
|
||||
|
||||
case VK_SPACE: {keycode= ' '; break;}
|
||||
|
||||
case VK_NEXT: {keycode= BTG_PAGE_DOWN; break;}
|
||||
case VK_PRIOR: {keycode= BTG_PAGE_UP; break;}
|
||||
|
||||
case VK_INSERT: {keycode= BTG_INSERT; break;}
|
||||
case VK_DELETE: {keycode= BTG_DELETE; break;}
|
||||
|
||||
case VK_END:{keycode= BTG_END; break;}
|
||||
case VK_HOME:{keycode= BTG_HOME; break;}
|
||||
case VK_LEFT:{keycode= BTG_LEFT_ARROW; break;}
|
||||
case VK_UP:{keycode= BTG_UP_ARROW; break;}
|
||||
case VK_RIGHT:{keycode= BTG_RIGHT_ARROW; break;}
|
||||
case VK_DOWN:{keycode= BTG_DOWN_ARROW; break;}
|
||||
default:
|
||||
{
|
||||
keycode = MapVirtualKey( virtualKeyCode, MAPVK_VK_TO_CHAR ) & 0x0000FFFF;
|
||||
}
|
||||
};
|
||||
|
||||
return keycode;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
//printf("msg = %d\n", message);
|
||||
switch (message)
|
||||
{
|
||||
|
||||
case WM_PAINT:
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
BeginPaint(hWnd, &ps);
|
||||
EndPaint(hWnd, &ps);
|
||||
}
|
||||
return 1;
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
return 1;
|
||||
|
||||
case WM_CLOSE:
|
||||
if (sData)
|
||||
sData->m_quit = true;
|
||||
//PostQuitMessage(0);
|
||||
return 1;
|
||||
|
||||
case WM_DESTROY:
|
||||
if (sData)
|
||||
sData->m_quit = true;
|
||||
//PostQuitMessage(0);
|
||||
return 1;
|
||||
|
||||
case WM_SYSKEYUP:
|
||||
case WM_KEYUP:
|
||||
{
|
||||
|
||||
int keycode = getAsciiCodeFromVirtualKeycode(wParam);
|
||||
|
||||
|
||||
if (sData && sData->m_keyboardCallback )
|
||||
{
|
||||
int state=0;
|
||||
(*sData->m_keyboardCallback)(keycode,state);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
case WM_SYSKEYDOWN:
|
||||
case WM_KEYDOWN:
|
||||
{
|
||||
int keycode = getAsciiCodeFromVirtualKeycode(wParam);
|
||||
|
||||
if (sData && sData->m_keyboardCallback && ((HIWORD(lParam) & KF_REPEAT) == 0))
|
||||
{
|
||||
int state = 1;
|
||||
(*sData->m_keyboardCallback)(keycode,state);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_MBUTTONUP:
|
||||
{
|
||||
int xPos = LOWORD(lParam);
|
||||
int yPos = HIWORD(lParam);
|
||||
if (sData)
|
||||
{
|
||||
sData->m_mouseMButton=0;
|
||||
sData->m_mouseXpos = xPos;
|
||||
sData->m_mouseYpos = yPos;
|
||||
if (sData && sData->m_mouseButtonCallback)
|
||||
(*sData->m_mouseButtonCallback)(1,0,xPos,yPos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_MBUTTONDOWN:
|
||||
{
|
||||
int xPos = LOWORD(lParam);
|
||||
int yPos = HIWORD(lParam);
|
||||
if (sData)
|
||||
{
|
||||
sData->m_mouseMButton=1;
|
||||
sData->m_mouseXpos = xPos;
|
||||
sData->m_mouseYpos = yPos;
|
||||
if (sData && sData->m_mouseButtonCallback)
|
||||
(*sData->m_mouseButtonCallback)(1,1,xPos,yPos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_LBUTTONUP:
|
||||
{
|
||||
int xPos = LOWORD(lParam);
|
||||
int yPos = HIWORD(lParam);
|
||||
if (sData)
|
||||
{
|
||||
sData->m_mouseLButton=0;
|
||||
sData->m_mouseXpos = xPos;
|
||||
sData->m_mouseYpos = yPos;
|
||||
|
||||
if (sData && sData->m_mouseButtonCallback)
|
||||
(*sData->m_mouseButtonCallback)(0,0,xPos,yPos);
|
||||
|
||||
}
|
||||
// gDemoApplication->mouseFunc(0,1,xPos,yPos);
|
||||
break;
|
||||
}
|
||||
case WM_LBUTTONDOWN:
|
||||
{
|
||||
int xPos = LOWORD(lParam);
|
||||
int yPos = HIWORD(lParam);
|
||||
if (sData)
|
||||
{
|
||||
sData->m_mouseLButton=1;
|
||||
sData->m_mouseXpos = xPos;
|
||||
sData->m_mouseYpos = yPos;
|
||||
|
||||
if (sData && sData->m_mouseButtonCallback)
|
||||
(*sData->m_mouseButtonCallback)(0,1,xPos,yPos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x020e://WM_MOUSEWHEEL_LEFT_RIGHT
|
||||
{
|
||||
|
||||
int zDelta = (short)HIWORD(wParam);
|
||||
int xPos = LOWORD(lParam);
|
||||
int yPos = HIWORD(lParam);
|
||||
//m_cameraDistance -= zDelta*0.01;
|
||||
if (sData && sData->m_wheelCallback)
|
||||
(*sData->m_wheelCallback)(-float(zDelta)*0.05f,0);
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
case 0x020A://WM_MOUSEWHEEL:
|
||||
{
|
||||
|
||||
int zDelta = (short)HIWORD(wParam);
|
||||
int xPos = LOWORD(lParam);
|
||||
int yPos = HIWORD(lParam);
|
||||
//m_cameraDistance -= zDelta*0.01;
|
||||
if (sData && sData->m_wheelCallback)
|
||||
(*sData->m_wheelCallback)(0,float(zDelta)*0.05f);
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_MOUSEMOVE:
|
||||
{
|
||||
int xPos = LOWORD(lParam);
|
||||
int yPos = HIWORD(lParam);
|
||||
sData->m_mouseXpos = xPos;
|
||||
sData->m_mouseYpos = yPos;
|
||||
|
||||
if (sData && sData->m_mouseMoveCallback)
|
||||
(*sData->m_mouseMoveCallback)(xPos,yPos);
|
||||
|
||||
break;
|
||||
}
|
||||
case WM_RBUTTONUP:
|
||||
{
|
||||
int xPos = LOWORD(lParam);
|
||||
int yPos = HIWORD(lParam);
|
||||
sData->m_mouseRButton = 1;
|
||||
|
||||
if (sData && sData->m_mouseButtonCallback)
|
||||
(*sData->m_mouseButtonCallback)(2,0,sData->m_mouseXpos,sData->m_mouseYpos);
|
||||
|
||||
//gDemoApplication->mouseFunc(2,1,xPos,yPos);
|
||||
break;
|
||||
}
|
||||
case WM_RBUTTONDOWN:
|
||||
{
|
||||
int xPos = LOWORD(lParam);
|
||||
int yPos = HIWORD(lParam);
|
||||
sData->m_mouseRButton = 0;
|
||||
if (sData && sData->m_mouseButtonCallback)
|
||||
(*sData->m_mouseButtonCallback)(2,1,sData->m_mouseXpos,sData->m_mouseYpos);
|
||||
|
||||
break;
|
||||
}
|
||||
case WM_QUIT:
|
||||
{
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
case WM_SIZE: // Size Action Has Taken Place
|
||||
|
||||
RECT clientRect;
|
||||
GetClientRect(hWnd,&clientRect);
|
||||
|
||||
switch (wParam) // Evaluate Size Action
|
||||
{
|
||||
|
||||
case SIZE_MINIMIZED: // Was Window Minimized?
|
||||
return 0; // Return
|
||||
|
||||
case SIZE_MAXIMIZED: // Was Window Maximized?
|
||||
case SIZE_RESTORED: // Was Window Restored?
|
||||
RECT wr;
|
||||
GetWindowRect(hWnd,&wr);
|
||||
|
||||
sData->m_fullWindowWidth = wr.right-wr.left;
|
||||
sData->m_fullWindowHeight = wr.bottom-wr.top;//LOWORD (lParam) HIWORD (lParam);
|
||||
sData->m_openglViewportWidth = clientRect.right;
|
||||
sData->m_openglViewportHeight = clientRect.bottom;
|
||||
glViewport(0, 0, sData->m_openglViewportWidth, sData->m_openglViewportHeight);
|
||||
|
||||
if (sData->m_resizeCallback)
|
||||
(*sData->m_resizeCallback)(sData->m_openglViewportWidth,sData->m_openglViewportHeight);
|
||||
//if (sOpenGLInitialized)
|
||||
//{
|
||||
// //gDemoApplication->reshape(sWidth,sHeight);
|
||||
//}
|
||||
return 0; // Return
|
||||
}
|
||||
break;
|
||||
|
||||
default:{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Win32Window::setWindowTitle(const char* titleChar)
|
||||
{
|
||||
|
||||
wchar_t windowTitle[1024];
|
||||
swprintf(windowTitle, 1024, L"%hs", titleChar);
|
||||
|
||||
DWORD dwResult;
|
||||
|
||||
#ifdef _WIN64
|
||||
SetWindowTextW(m_data->m_hWnd, windowTitle);
|
||||
#else
|
||||
SendMessageTimeoutW(m_data->m_hWnd, WM_SETTEXT, 0,
|
||||
reinterpret_cast<LPARAM>(windowTitle),
|
||||
SMTO_ABORTIFHUNG, 2000, &dwResult);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Win32Window::createWindow(const btgWindowConstructionInfo& ci)
|
||||
{
|
||||
int oglViewportWidth = ci.m_width;
|
||||
int oglViewportHeight = ci.m_height;
|
||||
bool fullscreen = ci.m_fullscreen;
|
||||
int colorBitsPerPixel = ci.m_colorBitsPerPixel;
|
||||
void* windowHandle = ci.m_windowHandle;
|
||||
|
||||
// get handle to exe file
|
||||
HINSTANCE hInstance = GetModuleHandle(0);
|
||||
|
||||
|
||||
// create the window if we need to and we do not use the null device
|
||||
if (!windowHandle)
|
||||
{
|
||||
#ifdef UNICODE
|
||||
const wchar_t * ClassName = L"DeviceWin32";
|
||||
const wchar_t* emptyString= L"";
|
||||
#else
|
||||
const char* ClassName = "DeviceWin32";
|
||||
const char* emptyString = "";
|
||||
#endif
|
||||
// Register Class
|
||||
WNDCLASSEX wcex;
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wcex.lpfnWndProc = WndProc;
|
||||
wcex.cbClsExtra = 0;
|
||||
wcex.cbWndExtra = 0;
|
||||
wcex.hInstance = hInstance;
|
||||
wcex.hIcon = LoadIcon( NULL, IDI_APPLICATION ); //(HICON)LoadImage(hInstance, "bullet_ico.ico", IMAGE_ICON, 0,0, LR_LOADTRANSPARENT);//LR_LOADFROMFILE);
|
||||
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||||
wcex.lpszMenuName = 0;
|
||||
wcex.lpszClassName = ClassName;
|
||||
wcex.hIconSm = 0;
|
||||
|
||||
// if there is an icon, load it
|
||||
// wcex.hIcon = (HICON)LoadImage(hInstance, "bullet.ico", IMAGE_ICON, 0,0, LR_LOADFROMFILE);
|
||||
|
||||
RegisterClassEx(&wcex);
|
||||
|
||||
// calculate client size
|
||||
|
||||
RECT clientSize;
|
||||
clientSize.top = 0;
|
||||
clientSize.left = 0;
|
||||
clientSize.right = oglViewportWidth;
|
||||
clientSize.bottom = oglViewportHeight;
|
||||
|
||||
DWORD style = WS_POPUP;
|
||||
|
||||
if (!fullscreen)
|
||||
style = WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SIZEBOX;
|
||||
|
||||
AdjustWindowRect(&clientSize, style, false);
|
||||
|
||||
m_data->m_fullWindowWidth = clientSize.right - clientSize.left;
|
||||
m_data->m_fullWindowHeight = clientSize.bottom - clientSize.top;
|
||||
|
||||
int windowLeft = (GetSystemMetrics(SM_CXSCREEN) - m_data->m_fullWindowWidth) / 2;
|
||||
int windowTop = (GetSystemMetrics(SM_CYSCREEN) - m_data->m_fullWindowHeight) / 2;
|
||||
|
||||
if (fullscreen)
|
||||
{
|
||||
windowLeft = 0;
|
||||
windowTop = 0;
|
||||
}
|
||||
|
||||
// create window
|
||||
|
||||
m_data->m_hWnd = CreateWindow( ClassName, emptyString, style, windowLeft, windowTop,
|
||||
m_data->m_fullWindowWidth, m_data->m_fullWindowHeight,NULL, NULL, hInstance, NULL);
|
||||
|
||||
|
||||
RECT clientRect;
|
||||
GetClientRect(m_data->m_hWnd,&clientRect);
|
||||
|
||||
|
||||
|
||||
ShowWindow(m_data->m_hWnd, SW_SHOW);
|
||||
UpdateWindow(m_data->m_hWnd);
|
||||
|
||||
MoveWindow(m_data->m_hWnd, windowLeft, windowTop, m_data->m_fullWindowWidth, m_data->m_fullWindowHeight, TRUE);
|
||||
|
||||
GetClientRect(m_data->m_hWnd,&clientRect);
|
||||
int w = clientRect.right-clientRect.left;
|
||||
int h = clientRect.bottom-clientRect.top;
|
||||
// printf("actual client OpenGL viewport width / height = %d, %d\n",w,h);
|
||||
m_data->m_openglViewportHeight = h;
|
||||
m_data->m_openglViewportWidth = w;
|
||||
|
||||
}
|
||||
else if (windowHandle)
|
||||
{
|
||||
// attach external window
|
||||
m_data->m_hWnd = static_cast<HWND>(windowHandle);
|
||||
RECT r;
|
||||
GetWindowRect(m_data->m_hWnd, &r);
|
||||
m_data->m_fullWindowWidth = r.right - r.left;
|
||||
m_data->m_fullWindowHeight= r.bottom - r.top;
|
||||
|
||||
|
||||
//sFullScreen = false;
|
||||
//sExternalWindow = true;
|
||||
}
|
||||
|
||||
|
||||
if (fullscreen)
|
||||
{
|
||||
DEVMODE dm;
|
||||
memset(&dm, 0, sizeof(dm));
|
||||
dm.dmSize = sizeof(dm);
|
||||
// use default values from current setting
|
||||
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
|
||||
m_data->m_oldScreenWidth = dm.dmPelsWidth;
|
||||
m_data->m_oldHeight = dm.dmPelsHeight;
|
||||
m_data->m_oldBitsPerPel = dm.dmBitsPerPel;
|
||||
|
||||
dm.dmPelsWidth = oglViewportWidth;
|
||||
dm.dmPelsHeight = oglViewportHeight;
|
||||
if (colorBitsPerPixel)
|
||||
{
|
||||
dm.dmBitsPerPel = colorBitsPerPixel;
|
||||
}
|
||||
dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
|
||||
|
||||
LONG res = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
|
||||
if (res != DISP_CHANGE_SUCCESSFUL)
|
||||
{ // try again without forcing display frequency
|
||||
dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
||||
res = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Win32Window::switchFullScreen(bool fullscreen,int width,int height,int colorBitsPerPixel)
|
||||
{
|
||||
|
||||
LONG res;
|
||||
DEVMODE dm;
|
||||
memset(&dm, 0, sizeof(dm));
|
||||
dm.dmSize = sizeof(dm);
|
||||
// use default values from current setting
|
||||
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
|
||||
|
||||
dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
|
||||
|
||||
if (fullscreen && !m_data->m_oldScreenWidth)
|
||||
{
|
||||
m_data->m_oldScreenWidth = dm.dmPelsWidth;
|
||||
m_data->m_oldHeight = dm.dmPelsHeight;
|
||||
m_data->m_oldBitsPerPel = dm.dmBitsPerPel;
|
||||
|
||||
if (width && height)
|
||||
{
|
||||
dm.dmPelsWidth = width;
|
||||
dm.dmPelsHeight = height;
|
||||
} else
|
||||
{
|
||||
dm.dmPelsWidth = m_data->m_fullWindowWidth;
|
||||
dm.dmPelsHeight = m_data->m_fullWindowHeight;
|
||||
}
|
||||
if (colorBitsPerPixel)
|
||||
{
|
||||
dm.dmBitsPerPel = colorBitsPerPixel;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (m_data->m_oldScreenWidth)
|
||||
{
|
||||
dm.dmPelsWidth = m_data->m_oldScreenWidth;
|
||||
dm.dmPelsHeight= m_data->m_oldHeight;
|
||||
dm.dmBitsPerPel = m_data->m_oldBitsPerPel;
|
||||
}
|
||||
}
|
||||
|
||||
if (fullscreen)
|
||||
{
|
||||
|
||||
res = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
|
||||
if (!res)
|
||||
{
|
||||
dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
||||
res = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
|
||||
}
|
||||
|
||||
DWORD style = WS_POPUP;
|
||||
SetWindowLong(m_data->m_hWnd, GWL_STYLE, style);
|
||||
|
||||
MoveWindow(m_data->m_hWnd, 0, 0, m_data->m_fullWindowWidth, m_data->m_fullWindowHeight, TRUE);
|
||||
|
||||
SetWindowPos(m_data->m_hWnd, NULL,0,0, (int)width, (int)height,
|
||||
SWP_FRAMECHANGED |SWP_SHOWWINDOW);//|SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOOWNERZORDER | SWP_NOREPOSITION | SWP_NOZORDER);
|
||||
|
||||
|
||||
} else
|
||||
{
|
||||
res = ChangeDisplaySettings(&dm, 0);
|
||||
|
||||
DWORD style = WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SIZEBOX;
|
||||
SetWindowLong(m_data->m_hWnd, GWL_STYLE, style);
|
||||
|
||||
SetWindowPos(m_data->m_hWnd, NULL,0,0, (int)width, (int)height,
|
||||
SWP_FRAMECHANGED |SWP_SHOWWINDOW);
|
||||
//|SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOOWNERZORDER | SWP_NOREPOSITION | SWP_NOZORDER);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Win32Window::Win32Window()
|
||||
{
|
||||
m_data = new InternalData2();
|
||||
sData = m_data;
|
||||
|
||||
}
|
||||
|
||||
Win32Window::~Win32Window()
|
||||
{
|
||||
setKeyboardCallback(0);
|
||||
setMouseMoveCallback(0);
|
||||
setMouseButtonCallback(0);
|
||||
setWheelCallback(0);
|
||||
setResizeCallback(0);
|
||||
|
||||
sData = 0;
|
||||
delete m_data;
|
||||
|
||||
}
|
||||
|
||||
void Win32Window::setRenderCallback( btRenderCallback renderCallback)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Win32Window::closeWindow()
|
||||
{
|
||||
setKeyboardCallback(0);
|
||||
setMouseMoveCallback(0);
|
||||
setMouseButtonCallback(0);
|
||||
setWheelCallback(0);
|
||||
setResizeCallback(0);
|
||||
setRenderCallback(0);
|
||||
|
||||
|
||||
DestroyWindow(this->m_data->m_hWnd);
|
||||
}
|
||||
|
||||
void Win32Window::getMouseCoordinates(int& x, int& y)
|
||||
{
|
||||
x = m_data->m_mouseXpos;
|
||||
y = m_data->m_mouseYpos;
|
||||
|
||||
}
|
||||
|
||||
void Win32Window::runMainLoop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Win32Window::startRendering()
|
||||
{
|
||||
pumpMessage();
|
||||
|
||||
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //clear buffers
|
||||
|
||||
//glCullFace(GL_BACK);
|
||||
//glFrontFace(GL_CCW);
|
||||
// glEnable(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Win32Window::renderAllObjects()
|
||||
{
|
||||
}
|
||||
|
||||
void Win32Window::endRendering()
|
||||
{
|
||||
SwapBuffers( m_data->m_hDC );
|
||||
}
|
||||
|
||||
float Win32Window::getTimeInSeconds()
|
||||
{
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
void Win32Window::setDebugMessage(int x,int y,const char* message)
|
||||
{
|
||||
}
|
||||
|
||||
void Win32Window::setRequestExit()
|
||||
{
|
||||
m_data->m_quit = true;
|
||||
}
|
||||
bool Win32Window::requestedExit() const
|
||||
{
|
||||
return m_data->m_quit;
|
||||
}
|
||||
|
||||
void Win32Window::setWheelCallback(btWheelCallback wheelCallback)
|
||||
{
|
||||
m_data->m_wheelCallback = wheelCallback;
|
||||
}
|
||||
|
||||
void Win32Window::setMouseMoveCallback(btMouseMoveCallback mouseCallback)
|
||||
{
|
||||
m_data->m_mouseMoveCallback = mouseCallback;
|
||||
}
|
||||
|
||||
void Win32Window::setMouseButtonCallback(btMouseButtonCallback mouseCallback)
|
||||
{
|
||||
m_data->m_mouseButtonCallback = mouseCallback;
|
||||
}
|
||||
|
||||
void Win32Window::setResizeCallback(btResizeCallback resizeCallback)
|
||||
{
|
||||
m_data->m_resizeCallback = resizeCallback;
|
||||
if (m_data->m_resizeCallback)
|
||||
(*m_data->m_resizeCallback)(m_data->m_openglViewportWidth,m_data->m_openglViewportHeight);
|
||||
}
|
||||
|
||||
void Win32Window::setKeyboardCallback( btKeyboardCallback keyboardCallback)
|
||||
{
|
||||
m_data->m_keyboardCallback = keyboardCallback;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
78
btgui/OpenGLWindow/Win32Window.h
Normal file
78
btgui/OpenGLWindow/Win32Window.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
Copyright (c) 2012 Advanced Micro Devices, Inc.
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
//Originally written by Erwin Coumans
|
||||
|
||||
|
||||
#ifndef _WIN32_WINDOW_H
|
||||
#define _WIN32_WINDOW_H
|
||||
|
||||
|
||||
|
||||
struct InternalData2;
|
||||
|
||||
#include "btgWindowInterface.h"
|
||||
|
||||
class Win32Window : public btgWindowInterface
|
||||
{
|
||||
protected:
|
||||
|
||||
struct InternalData2* m_data;
|
||||
|
||||
|
||||
void pumpMessage();
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
Win32Window();
|
||||
|
||||
virtual ~Win32Window();
|
||||
|
||||
virtual void createWindow(const btgWindowConstructionInfo& ci);
|
||||
|
||||
virtual void switchFullScreen(bool fullscreen,int width=0,int height=0,int colorBitsPerPixel=0);
|
||||
|
||||
virtual void closeWindow();
|
||||
|
||||
virtual void runMainLoop();
|
||||
|
||||
virtual void startRendering();
|
||||
|
||||
virtual void renderAllObjects();
|
||||
|
||||
virtual void endRendering();
|
||||
|
||||
virtual float getTimeInSeconds();
|
||||
|
||||
virtual void setDebugMessage(int x,int y,const char* message);
|
||||
|
||||
virtual bool requestedExit() const;
|
||||
|
||||
virtual void setRequestExit();
|
||||
|
||||
virtual void getMouseCoordinates(int& x, int& y);
|
||||
|
||||
virtual void setMouseMoveCallback(btMouseMoveCallback mouseCallback);
|
||||
virtual void setMouseButtonCallback(btMouseButtonCallback mouseCallback);
|
||||
virtual void setResizeCallback(btResizeCallback resizeCallback);
|
||||
virtual void setWheelCallback(btWheelCallback wheelCallback);
|
||||
virtual void setKeyboardCallback( btKeyboardCallback keyboardCallback);
|
||||
|
||||
virtual void setRenderCallback( btRenderCallback renderCallback);
|
||||
|
||||
virtual void setWindowTitle(const char* title);
|
||||
};
|
||||
|
||||
#endif //_WIN32_WINDOW_H
|
||||
415
btgui/OpenGLWindow/X11OpenGLWindow.cpp
Normal file
415
btgui/OpenGLWindow/X11OpenGLWindow.cpp
Normal file
@@ -0,0 +1,415 @@
|
||||
#include "X11OpenGLWindow.h"
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<X11/X.h>
|
||||
#include<X11/Xlib.h>
|
||||
#include<GL/gl.h>
|
||||
#include<GL/glx.h>
|
||||
#include<GL/glu.h>
|
||||
|
||||
|
||||
GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };
|
||||
|
||||
|
||||
struct InternalData2
|
||||
{
|
||||
Display* m_dpy;
|
||||
Window m_root;
|
||||
XVisualInfo* m_vi;
|
||||
Colormap m_cmap;
|
||||
XSetWindowAttributes m_swa;
|
||||
Window m_win;
|
||||
GLXContext m_glc;
|
||||
XWindowAttributes m_gwa;
|
||||
XEvent m_xev;
|
||||
|
||||
btWheelCallback m_wheelCallback;
|
||||
btMouseMoveCallback m_mouseMoveCallback;
|
||||
btMouseButtonCallback m_mouseButtonCallback;
|
||||
btResizeCallback m_resizeCallback;
|
||||
btKeyboardCallback m_keyboardCallback;
|
||||
|
||||
InternalData2()
|
||||
:m_dpy(0),
|
||||
m_vi(0),
|
||||
m_wheelCallback(0),
|
||||
m_mouseMoveCallback(0),
|
||||
m_mouseButtonCallback(0),
|
||||
m_resizeCallback(0),
|
||||
m_keyboardCallback(0)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
X11OpenGLWindow::X11OpenGLWindow()
|
||||
:m_OpenGLInitialized(false)
|
||||
{
|
||||
m_data = new InternalData2;
|
||||
}
|
||||
|
||||
X11OpenGLWindow::~X11OpenGLWindow()
|
||||
{
|
||||
if (m_OpenGLInitialized)
|
||||
{
|
||||
disableOpenGL();
|
||||
}
|
||||
|
||||
delete m_data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void X11OpenGLWindow::enableOpenGL()
|
||||
{
|
||||
|
||||
m_data->m_glc = glXCreateContext(m_data->m_dpy, m_data->m_vi, NULL, GL_TRUE);
|
||||
glXMakeCurrent(m_data->m_dpy, m_data->m_win, m_data->m_glc);
|
||||
|
||||
const GLubyte* ven = glGetString(GL_VENDOR);
|
||||
printf("GL_VENDOR=%s\n", ven);
|
||||
const GLubyte* ren = glGetString(GL_RENDERER);
|
||||
printf("GL_RENDERER=%s\n",ren);
|
||||
const GLubyte* ver = glGetString(GL_VERSION);
|
||||
printf("GL_VERSION=%s\n", ver);
|
||||
const GLubyte* sl = glGetString(GL_SHADING_LANGUAGE_VERSION);
|
||||
printf("GL_SHADING_LANGUAGE_VERSION=%s\n", sl);
|
||||
// const GLubyte* ext = glGetString(GL_EXTENSIONS);
|
||||
// printf("GL_EXTENSIONS=%s\n", ext);
|
||||
}
|
||||
|
||||
void X11OpenGLWindow::disableOpenGL()
|
||||
{
|
||||
glXMakeCurrent(m_data->m_dpy, None, NULL);
|
||||
glXDestroyContext(m_data->m_dpy, m_data->m_glc);
|
||||
}
|
||||
|
||||
|
||||
void X11OpenGLWindow::createWindow(const btgWindowConstructionInfo& ci)
|
||||
{
|
||||
m_data->m_dpy = XOpenDisplay(NULL);
|
||||
|
||||
if(m_data->m_dpy == NULL) {
|
||||
printf("\n\tcannot connect to X server\n\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
m_data->m_root = DefaultRootWindow(m_data->m_dpy);
|
||||
|
||||
m_data->m_vi = glXChooseVisual(m_data->m_dpy, 0, att);
|
||||
|
||||
if(m_data->m_vi == NULL) {
|
||||
printf("\n\tno appropriate visual found\n\n");
|
||||
exit(0);
|
||||
}
|
||||
else {
|
||||
printf("\n\tvisual %p selected\n", (void *)m_data->m_vi->visualid); /* %p creates hexadecimal output like in glxinfo */
|
||||
}
|
||||
|
||||
|
||||
m_data->m_cmap = XCreateColormap(m_data->m_dpy, m_data->m_root, m_data->m_vi->visual, AllocNone);
|
||||
|
||||
m_data->m_swa.colormap = m_data->m_cmap;
|
||||
m_data->m_swa.event_mask = ExposureMask | KeyPressMask |ButtonPressMask | ButtonReleaseMask |PointerMotionMask|StructureNotifyMask;
|
||||
|
||||
m_data->m_win = XCreateWindow(m_data->m_dpy, m_data->m_root, 0, 0, ci.m_width, ci.m_height, 0, m_data->m_vi->depth, InputOutput, m_data->m_vi->visual, CWColormap | CWEventMask, &m_data->m_swa);
|
||||
|
||||
XMapWindow(m_data->m_dpy, m_data->m_win);
|
||||
XStoreName(m_data->m_dpy, m_data->m_win, "VERY SIMPLE APPLICATION");
|
||||
|
||||
enableOpenGL();
|
||||
}
|
||||
|
||||
void X11OpenGLWindow::closeWindow()
|
||||
{
|
||||
disableOpenGL();
|
||||
|
||||
XDestroyWindow(m_data->m_dpy, m_data->m_win);
|
||||
XCloseDisplay(m_data->m_dpy);
|
||||
}
|
||||
|
||||
int X11OpenGLWindow::getAsciiCodeFromVirtualKeycode(int keycode)
|
||||
{
|
||||
KeySym key, key_lc, key_uc;
|
||||
|
||||
key = XKeycodeToKeysym( m_data->m_dpy, keycode, 0 );
|
||||
switch( key )
|
||||
{
|
||||
case XK_Escape: return BTG_ESCAPE;
|
||||
|
||||
case XK_F1: return BTG_F1;
|
||||
case XK_F2: return BTG_F2;
|
||||
case XK_F3: return BTG_F3;
|
||||
case XK_F4: return BTG_F4;
|
||||
case XK_F5: return BTG_F5;
|
||||
case XK_F6: return BTG_F6;
|
||||
case XK_F7: return BTG_F7;
|
||||
case XK_F8: return BTG_F8;
|
||||
case XK_F9: return BTG_F9;
|
||||
case XK_F10: return BTG_F10;
|
||||
case XK_F11: return BTG_F11;
|
||||
case XK_F12: return BTG_F12;
|
||||
case XK_F13: return BTG_F13;
|
||||
case XK_F14: return BTG_F14;
|
||||
case XK_F15: return BTG_F15;
|
||||
default:
|
||||
// Make uppercase
|
||||
XConvertCase( key, &key_lc, &key_uc );
|
||||
key = key_uc;
|
||||
// Valid ISO 8859-1 character?
|
||||
if( (key >= 32 && key <= 126) ||(key >= 160 && key <= 255) )
|
||||
{
|
||||
return (int) key;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void X11OpenGLWindow::pumpMessage()
|
||||
{
|
||||
|
||||
int buttonState = 1;
|
||||
|
||||
// Process all pending events
|
||||
while( XPending( m_data->m_dpy ) )
|
||||
{
|
||||
XNextEvent(m_data->m_dpy, &m_data->m_xev);
|
||||
// printf("#");
|
||||
// fflush(stdout);
|
||||
switch( m_data->m_xev.type )
|
||||
{
|
||||
case KeyPress:
|
||||
{
|
||||
if (m_data->m_keyboardCallback)
|
||||
{
|
||||
int keycode = getAsciiCodeFromVirtualKeycode(m_data->m_xev.xkey.keycode);
|
||||
int state = 1;
|
||||
(*m_data->m_keyboardCallback)(keycode,state);
|
||||
// printf("keycode %d",keycode);
|
||||
// fflush(stdout);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case KeyRelease:
|
||||
{
|
||||
// printf(",");
|
||||
// fflush(stdout);
|
||||
|
||||
if (m_data->m_keyboardCallback)
|
||||
{
|
||||
|
||||
unsigned short is_retriggered = 0;
|
||||
///filter out keyboard repeat
|
||||
//see http://stackoverflow.com/questions/2100654/ignore-auto-repeat-in-x11-applications
|
||||
if (XEventsQueued(m_data->m_dpy, QueuedAfterReading))
|
||||
{
|
||||
XEvent nev;
|
||||
XPeekEvent(m_data->m_dpy, &nev);
|
||||
|
||||
if (nev.type == KeyPress && nev.xkey.time == m_data->m_xev.xkey.time &&
|
||||
nev.xkey.keycode == m_data->m_xev.xkey.keycode)
|
||||
{
|
||||
fprintf (stdout, "key #%ld was retriggered.\n",
|
||||
(long) XLookupKeysym (&nev.xkey, 0));
|
||||
|
||||
// delete retriggered KeyPress event
|
||||
XNextEvent (m_data->m_dpy, & m_data->m_xev);
|
||||
is_retriggered = 1;
|
||||
}
|
||||
}
|
||||
int keycode = getAsciiCodeFromVirtualKeycode( m_data->m_xev.xkey.keycode);
|
||||
int state = 0;
|
||||
(*m_data->m_keyboardCallback)(keycode,state);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ButtonRelease:
|
||||
buttonState = 0;
|
||||
//continue with ButtonPress code
|
||||
case ButtonPress:
|
||||
{
|
||||
// printf("!");
|
||||
// fflush(stdout);
|
||||
|
||||
int button=-1;
|
||||
|
||||
switch (m_data->m_xev.xbutton.button)
|
||||
{
|
||||
case Button1:
|
||||
{
|
||||
button=0;
|
||||
break;
|
||||
}
|
||||
case Button2:
|
||||
{
|
||||
button=1;
|
||||
break;
|
||||
}
|
||||
case Button3:
|
||||
{
|
||||
button=2;
|
||||
break;
|
||||
}
|
||||
case Button4:
|
||||
{
|
||||
if (m_data->m_wheelCallback)
|
||||
{
|
||||
(*m_data->m_wheelCallback)(0,10);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Button5:
|
||||
{
|
||||
if (m_data->m_wheelCallback)
|
||||
{
|
||||
(*m_data->m_wheelCallback)(0,-10);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
int xpos = m_data->m_xev.xmotion.x;
|
||||
int ypos = m_data->m_xev.xmotion.y;
|
||||
|
||||
if (button>=0 && m_data->m_mouseButtonCallback)
|
||||
{
|
||||
// printf("xpos = %d, ypos = %d\n",xpos,ypos);
|
||||
|
||||
(*m_data->m_mouseButtonCallback)(button,buttonState,xpos,ypos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MotionNotify:
|
||||
{
|
||||
// printf("!");
|
||||
// fflush(0);
|
||||
if (m_data->m_mouseMoveCallback)
|
||||
{
|
||||
int xpos = m_data->m_xev.xmotion.x;
|
||||
int ypos = m_data->m_xev.xmotion.y;
|
||||
(*m_data->m_mouseMoveCallback)(xpos,ypos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ConfigureNotify:
|
||||
{
|
||||
// printf("@");
|
||||
// fflush(0);
|
||||
if (m_data->m_resizeCallback)
|
||||
{
|
||||
(*m_data->m_resizeCallback)(m_data->m_xev.xconfigure.width,m_data->m_xev.xconfigure.height);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ClientMessage:
|
||||
{
|
||||
// printf("?");
|
||||
// fflush(stdout);
|
||||
break;
|
||||
}
|
||||
case Expose:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case DestroyNotify:
|
||||
{
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
//XRRUpdateConfiguration( &event );
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void X11OpenGLWindow::startRendering()
|
||||
{
|
||||
pumpMessage();
|
||||
|
||||
XGetWindowAttributes(m_data->m_dpy, m_data->m_win, &m_data->m_gwa);
|
||||
glViewport(0, 0, m_data->m_gwa.width, m_data->m_gwa.height);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //clear buffers
|
||||
|
||||
//glCullFace(GL_BACK);
|
||||
//glFrontFace(GL_CCW);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
void X11OpenGLWindow::renderAllObjects()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void X11OpenGLWindow::endRendering()
|
||||
{
|
||||
glXSwapBuffers(m_data->m_dpy, m_data->m_win);
|
||||
}
|
||||
|
||||
void X11OpenGLWindow::runMainLoop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float X11OpenGLWindow::getTimeInSeconds()
|
||||
{
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
bool X11OpenGLWindow::requestedExit() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void X11OpenGLWindow::setRequestExit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void X11OpenGLWindow::setRenderCallback( btRenderCallback renderCallback)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void X11OpenGLWindow::setWindowTitle(const char* title)
|
||||
{
|
||||
XStoreName(m_data->m_dpy, m_data->m_win, title);
|
||||
}
|
||||
|
||||
|
||||
void X11OpenGLWindow::setWheelCallback(btWheelCallback wheelCallback)
|
||||
{
|
||||
m_data->m_wheelCallback = wheelCallback;
|
||||
}
|
||||
|
||||
void X11OpenGLWindow::setMouseMoveCallback(btMouseMoveCallback mouseCallback)
|
||||
{
|
||||
m_data->m_mouseMoveCallback = mouseCallback;
|
||||
}
|
||||
|
||||
void X11OpenGLWindow::setMouseButtonCallback(btMouseButtonCallback mouseCallback)
|
||||
{
|
||||
m_data->m_mouseButtonCallback = mouseCallback;
|
||||
}
|
||||
|
||||
void X11OpenGLWindow::setResizeCallback(btResizeCallback resizeCallback)
|
||||
{
|
||||
m_data->m_resizeCallback = resizeCallback;
|
||||
}
|
||||
|
||||
void X11OpenGLWindow::setKeyboardCallback( btKeyboardCallback keyboardCallback)
|
||||
{
|
||||
m_data->m_keyboardCallback = keyboardCallback;
|
||||
|
||||
}
|
||||
64
btgui/OpenGLWindow/X11OpenGLWindow.h
Normal file
64
btgui/OpenGLWindow/X11OpenGLWindow.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef X11_OPENGL_WINDOW_H
|
||||
#define X11_OPENGL_WINDOW_H
|
||||
|
||||
#define btgDefaultOpenGLWindow X11OpenGLWindow
|
||||
|
||||
#include "btgWindowInterface.h"
|
||||
|
||||
class X11OpenGLWindow : public btgWindowInterface
|
||||
{
|
||||
|
||||
struct InternalData2* m_data;
|
||||
bool m_OpenGLInitialized;
|
||||
|
||||
protected:
|
||||
|
||||
void enableOpenGL();
|
||||
|
||||
void disableOpenGL();
|
||||
|
||||
void pumpMessage();
|
||||
|
||||
int getAsciiCodeFromVirtualKeycode(int orgCode);
|
||||
|
||||
public:
|
||||
|
||||
X11OpenGLWindow();
|
||||
|
||||
virtual ~X11OpenGLWindow();
|
||||
|
||||
virtual void createWindow(const btgWindowConstructionInfo& ci);
|
||||
|
||||
virtual void closeWindow();
|
||||
|
||||
virtual void startRendering();
|
||||
|
||||
virtual void renderAllObjects();
|
||||
|
||||
virtual void endRendering();
|
||||
|
||||
virtual float getRetinaScale() const {return 1.f;}
|
||||
|
||||
|
||||
virtual void runMainLoop();
|
||||
virtual float getTimeInSeconds();
|
||||
|
||||
virtual bool requestedExit() const;
|
||||
virtual void setRequestExit() ;
|
||||
|
||||
|
||||
virtual void setMouseMoveCallback(btMouseMoveCallback mouseCallback);
|
||||
virtual void setMouseButtonCallback(btMouseButtonCallback mouseCallback);
|
||||
virtual void setResizeCallback(btResizeCallback resizeCallback);
|
||||
virtual void setWheelCallback(btWheelCallback wheelCallback);
|
||||
virtual void setKeyboardCallback( btKeyboardCallback keyboardCallback);
|
||||
|
||||
virtual void setRenderCallback( btRenderCallback renderCallback);
|
||||
|
||||
virtual void setWindowTitle(const char* title);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
108
btgui/OpenGLWindow/btgWindowInterface.h
Normal file
108
btgui/OpenGLWindow/btgWindowInterface.h
Normal file
@@ -0,0 +1,108 @@
|
||||
#ifndef BTG_WINDOW_INTERFACE_H
|
||||
#define BTG_WINDOW_INTERFACE_H
|
||||
|
||||
|
||||
typedef void (*btWheelCallback)(float deltax, float deltay);
|
||||
typedef void (*btResizeCallback)( float width, float height);
|
||||
typedef void (*btMouseMoveCallback)( float x, float y);
|
||||
typedef void (*btMouseButtonCallback)(int button, int state, float x, float y);
|
||||
typedef void (*btKeyboardCallback)(int keycode, int state);
|
||||
typedef void (*btRenderCallback) ();
|
||||
|
||||
enum {
|
||||
BTG_ESCAPE = 27,
|
||||
BTG_F1 = 0xff00,
|
||||
BTG_F2,
|
||||
BTG_F3,
|
||||
BTG_F4,
|
||||
BTG_F5,
|
||||
BTG_F6,
|
||||
BTG_F7,
|
||||
BTG_F8,
|
||||
BTG_F9,
|
||||
BTG_F10,
|
||||
BTG_F11,
|
||||
BTG_F12,
|
||||
BTG_F13,
|
||||
BTG_F14,
|
||||
BTG_F15,
|
||||
BTG_LEFT_ARROW,
|
||||
BTG_RIGHT_ARROW,
|
||||
BTG_UP_ARROW,
|
||||
BTG_DOWN_ARROW,
|
||||
BTG_PAGE_UP,
|
||||
BTG_PAGE_DOWN,
|
||||
BTG_END,
|
||||
BTG_HOME,
|
||||
BTG_INSERT,
|
||||
BTG_DELETE
|
||||
};
|
||||
|
||||
struct btgWindowConstructionInfo
|
||||
{
|
||||
int m_width;
|
||||
int m_height;
|
||||
bool m_fullscreen;
|
||||
int m_colorBitsPerPixel;
|
||||
void* m_windowHandle;
|
||||
const char* m_title;
|
||||
int m_openglVersion;
|
||||
|
||||
btgWindowConstructionInfo(int width=1024, int height=768)
|
||||
:m_width(width),
|
||||
m_height(height),
|
||||
m_fullscreen(false),
|
||||
m_colorBitsPerPixel(32),
|
||||
m_windowHandle(0),
|
||||
m_title("title"),
|
||||
m_openglVersion(3)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class btgWindowInterface
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~btgWindowInterface()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void createDefaultWindow(int width, int height, const char* title)
|
||||
{
|
||||
btgWindowConstructionInfo ci(width,height);
|
||||
ci.m_title = title;
|
||||
createWindow(ci);
|
||||
}
|
||||
|
||||
virtual void createWindow(const btgWindowConstructionInfo& ci)=0;
|
||||
|
||||
virtual void closeWindow()=0;
|
||||
|
||||
virtual void runMainLoop()=0;
|
||||
virtual float getTimeInSeconds()=0;
|
||||
|
||||
virtual bool requestedExit() const = 0;
|
||||
virtual void setRequestExit() = 0;
|
||||
|
||||
virtual void startRendering()=0;
|
||||
|
||||
virtual void endRendering()=0;
|
||||
|
||||
|
||||
virtual void setMouseMoveCallback(btMouseMoveCallback mouseCallback)=0;
|
||||
virtual void setMouseButtonCallback(btMouseButtonCallback mouseCallback)=0;
|
||||
virtual void setResizeCallback(btResizeCallback resizeCallback)=0;
|
||||
virtual void setWheelCallback(btWheelCallback wheelCallback)=0;
|
||||
virtual void setKeyboardCallback( btKeyboardCallback keyboardCallback)=0;
|
||||
|
||||
virtual void setRenderCallback( btRenderCallback renderCallback) = 0;
|
||||
|
||||
virtual void setWindowTitle(const char* title)=0;
|
||||
|
||||
virtual float getRetinaScale() const =0;
|
||||
|
||||
};
|
||||
|
||||
#endif //BTG_WINDOW_INTERFACE_H
|
||||
375
btgui/OpenGLWindow/gwenWindow.cpp
Normal file
375
btgui/OpenGLWindow/gwenWindow.cpp
Normal file
@@ -0,0 +1,375 @@
|
||||
|
||||
#include "gwenWindow.h"
|
||||
|
||||
|
||||
#include "Gwen/Platform.h"
|
||||
#include "Gwen/Controls/TreeControl.h"
|
||||
#include "Gwen/Controls/RadioButtonController.h"
|
||||
#include "Gwen/Controls/VerticalSlider.h"
|
||||
#include "Gwen/Controls/HorizontalSlider.h"
|
||||
#include "Gwen/Controls/GroupBox.h"
|
||||
#include "Gwen/Controls/CheckBox.h"
|
||||
#include "Gwen/Controls/MenuStrip.h"
|
||||
|
||||
|
||||
#include "Gwen/Gwen.h"
|
||||
#include "Gwen/Align.h"
|
||||
#include "Gwen/Utility.h"
|
||||
#include "Gwen/Controls/WindowControl.h"
|
||||
#include "Gwen/Controls/TabControl.h"
|
||||
#include "Gwen/Controls/ListBox.h"
|
||||
|
||||
#include "BulletCommon/btQuickprof.h"
|
||||
#include "GwenOpenGL3CoreRenderer.h"
|
||||
#include "GLPrimitiveRenderer.h"
|
||||
|
||||
GLPrimitiveRenderer* primRenderer=0;
|
||||
GwenOpenGL3CoreRenderer* pRenderer = 0;
|
||||
//Gwen::Renderer::OpenGL_DebugFont * pRenderer =0;
|
||||
Gwen::Skin::Simple skin;
|
||||
Gwen::Controls::Canvas* pCanvas =0;
|
||||
class MyProfileWindow* profWindow = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
/*struct MyHander :public Gwen::Event::Handler
|
||||
{
|
||||
|
||||
MyHander (Application* app)
|
||||
:m_app(app)
|
||||
{
|
||||
}
|
||||
|
||||
void onButtonA( Gwen::Controls::Base* pControl )
|
||||
{
|
||||
OpenTissue::glut::toggleIdle();
|
||||
}
|
||||
|
||||
void SliderMoved(Gwen::Controls::Base* pControl )
|
||||
{
|
||||
Gwen::Controls::Slider* pSlider = (Gwen::Controls::Slider*)pControl;
|
||||
this->m_app->scaleYoungModulus(pSlider->GetValue());
|
||||
// printf("Slider Value: %.2f", pSlider->GetValue() );
|
||||
}
|
||||
|
||||
|
||||
void OnCheckChangedStiffnessWarping (Gwen::Controls::Base* pControl)
|
||||
{
|
||||
Gwen::Controls::CheckBox* labeled = (Gwen::Controls::CheckBox* )pControl;
|
||||
bool checked = labeled->IsChecked();
|
||||
m_app->m_stiffness_warp_on = checked;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
class MyProfileWindow : public Gwen::Controls::WindowControl
|
||||
{
|
||||
|
||||
// Gwen::Controls::TabControl* m_TabControl;
|
||||
//Gwen::Controls::ListBox* m_TextOutput;
|
||||
unsigned int m_iFrames;
|
||||
float m_fLastSecond;
|
||||
|
||||
Gwen::Controls::TreeNode* m_node;
|
||||
Gwen::Controls::TreeControl* m_ctrl;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void onButtonA( Gwen::Controls::Base* pControl )
|
||||
{
|
||||
// OpenTissue::glut::toggleIdle();
|
||||
}
|
||||
|
||||
void SliderMoved(Gwen::Controls::Base* pControl )
|
||||
{
|
||||
Gwen::Controls::Slider* pSlider = (Gwen::Controls::Slider*)pControl;
|
||||
//this->m_app->scaleYoungModulus(pSlider->GetValue());
|
||||
// printf("Slider Value: %.2f", pSlider->GetValue() );
|
||||
}
|
||||
|
||||
|
||||
void OnCheckChangedStiffnessWarping (Gwen::Controls::Base* pControl)
|
||||
{
|
||||
Gwen::Controls::CheckBox* labeled = (Gwen::Controls::CheckBox* )pControl;
|
||||
bool checked = labeled->IsChecked();
|
||||
//m_app->m_stiffness_warp_on = checked;
|
||||
}
|
||||
public:
|
||||
|
||||
void MenuItemSelect(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
if (Hidden())
|
||||
{
|
||||
SetHidden(false);
|
||||
} else
|
||||
{
|
||||
SetHidden(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MyProfileWindow ( Gwen::Controls::Base* pParent)
|
||||
: Gwen::Controls::WindowControl( pParent )
|
||||
{
|
||||
SetTitle( L"FEM Settings" );
|
||||
|
||||
SetSize( 450, 150 );
|
||||
this->SetPos(10,40);
|
||||
|
||||
// this->Dock( Gwen::Pos::Bottom);
|
||||
|
||||
|
||||
|
||||
{
|
||||
m_ctrl = new Gwen::Controls::TreeControl( this );
|
||||
m_node = m_ctrl->AddNode( L"Total Parent Time" );
|
||||
|
||||
|
||||
//Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
//pNode->AddNode( L"Node Two Inside" );
|
||||
//pNode->AddNode( L"Eyes" );
|
||||
//pNode->AddNode( L"Brown" )->AddNode( L"Node Two Inside" )->AddNode( L"Eyes" )->AddNode( L"Brown" );
|
||||
//Gwen::Controls::TreeNode* node = ctrl->AddNode( L"Node Three" );
|
||||
|
||||
|
||||
|
||||
//m_ctrl->Dock(Gwen::Pos::Bottom);
|
||||
|
||||
m_ctrl->ExpandAll();
|
||||
m_ctrl->SetBounds( this->GetInnerBounds().x,this->GetInnerBounds().y,this->GetInnerBounds().w,this->GetInnerBounds().h);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
float dumpRecursive(CProfileIterator* profileIterator, Gwen::Controls::TreeNode* parentNode)
|
||||
{
|
||||
profileIterator->First();
|
||||
if (profileIterator->Is_Done())
|
||||
return 0.f;
|
||||
|
||||
float accumulated_time=0,parent_time = profileIterator->Is_Root() ? CProfileManager::Get_Time_Since_Reset() : profileIterator->Get_Current_Parent_Total_Time();
|
||||
int i;
|
||||
int frames_since_reset = CProfileManager::Get_Frame_Count_Since_Reset();
|
||||
|
||||
//printf("Profiling: %s (total running time: %.3f ms) ---\n", profileIterator->Get_Current_Parent_Name(), parent_time );
|
||||
float totalTime = 0.f;
|
||||
|
||||
|
||||
int numChildren = 0;
|
||||
Gwen::UnicodeString txt;
|
||||
std::vector<Gwen::Controls::TreeNode*> nodes;
|
||||
|
||||
for (i = 0; !profileIterator->Is_Done(); i++,profileIterator->Next())
|
||||
{
|
||||
numChildren++;
|
||||
float current_total_time = profileIterator->Get_Current_Total_Time();
|
||||
accumulated_time += current_total_time;
|
||||
double fraction = parent_time > SIMD_EPSILON ? (current_total_time / parent_time) * 100 : 0.f;
|
||||
|
||||
Gwen::String name(profileIterator->Get_Current_Name());
|
||||
#ifdef _WIN32
|
||||
Gwen::UnicodeString uname = Gwen::Utility::StringToUnicode(name);
|
||||
|
||||
txt = Gwen::Utility::Format(L"%s (%.2f %%) :: %.3f ms / frame (%d calls)",uname.c_str(), fraction,(current_total_time / (double)frames_since_reset),profileIterator->Get_Current_Total_Calls());
|
||||
|
||||
#else
|
||||
txt = Gwen::Utility::Format(L"%s (%.2f %%) :: %.3f ms / frame (%d calls)",name.c_str(), fraction,(current_total_time / (double)frames_since_reset),profileIterator->Get_Current_Total_Calls());
|
||||
|
||||
#endif
|
||||
|
||||
Gwen::Controls::TreeNode* childNode = (Gwen::Controls::TreeNode*)profileIterator->Get_Current_UserPointer();
|
||||
if (!childNode)
|
||||
{
|
||||
childNode = parentNode->AddNode(L"");
|
||||
profileIterator->Set_Current_UserPointer(childNode);
|
||||
}
|
||||
childNode->SetText(txt);
|
||||
nodes.push_back(childNode);
|
||||
|
||||
totalTime += current_total_time;
|
||||
//recurse into children
|
||||
}
|
||||
|
||||
for (i=0;i<numChildren;i++)
|
||||
{
|
||||
profileIterator->Enter_Child(i);
|
||||
Gwen::Controls::TreeNode* curNode = nodes[i];
|
||||
|
||||
dumpRecursive(profileIterator, curNode);
|
||||
|
||||
profileIterator->Enter_Parent();
|
||||
}
|
||||
return accumulated_time;
|
||||
|
||||
}
|
||||
|
||||
void UpdateText(CProfileIterator* profileIterator, bool idle)
|
||||
{
|
||||
|
||||
static bool update=true;
|
||||
|
||||
m_ctrl->SetBounds(0,0,this->GetInnerBounds().w,this->GetInnerBounds().h);
|
||||
|
||||
// if (!update)
|
||||
// return;
|
||||
update=false;
|
||||
|
||||
|
||||
static int test = 1;
|
||||
test++;
|
||||
|
||||
static double time_since_reset = 0.f;
|
||||
if (!idle)
|
||||
{
|
||||
time_since_reset = CProfileManager::Get_Time_Since_Reset();
|
||||
}
|
||||
|
||||
//Gwen::UnicodeString txt = Gwen::Utility::Format( L"FEM Settings %i fps", test );
|
||||
{
|
||||
//recompute profiling data, and store profile strings
|
||||
|
||||
char blockTime[128];
|
||||
|
||||
double totalTime = 0;
|
||||
|
||||
int frames_since_reset = CProfileManager::Get_Frame_Count_Since_Reset();
|
||||
|
||||
profileIterator->First();
|
||||
|
||||
double parent_time = profileIterator->Is_Root() ? time_since_reset : profileIterator->Get_Current_Parent_Total_Time();
|
||||
|
||||
|
||||
Gwen::Controls::TreeNode* curParent = m_node;
|
||||
|
||||
double accumulated_time = dumpRecursive(profileIterator,m_node);
|
||||
|
||||
const char* name = profileIterator->Get_Current_Parent_Name();
|
||||
#ifdef _WIN32
|
||||
Gwen::UnicodeString uname = Gwen::Utility::StringToUnicode(name);
|
||||
Gwen::UnicodeString txt = Gwen::Utility::Format( L"Profiling: %s total time: %.3f ms, unaccounted %.3f %% :: %.3f ms", uname.c_str(), parent_time ,
|
||||
parent_time > SIMD_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
|
||||
#else
|
||||
Gwen::UnicodeString txt = Gwen::Utility::Format( L"Profiling: %s total time: %.3f ms, unaccounted %.3f %% :: %.3f ms", name, parent_time ,
|
||||
parent_time > SIMD_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
|
||||
#endif
|
||||
//sprintf(blockTime,"--- Profiling: %s (total running time: %.3f ms) ---", profileIterator->Get_Current_Parent_Name(), parent_time );
|
||||
//displayProfileString(xOffset,yStart,blockTime);
|
||||
m_node->SetText(txt);
|
||||
|
||||
|
||||
//printf("%s (%.3f %%) :: %.3f ms\n", "Unaccounted:",);
|
||||
|
||||
|
||||
}
|
||||
|
||||
static bool once1 = true;
|
||||
if (once1)
|
||||
{
|
||||
once1 = false;
|
||||
m_ctrl->ExpandAll();
|
||||
}
|
||||
|
||||
}
|
||||
void PrintText( const Gwen::UnicodeString& str )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Render( Gwen::Skin::Base* skin )
|
||||
{
|
||||
m_iFrames++;
|
||||
|
||||
if ( m_fLastSecond < Gwen::Platform::GetTimeInSeconds() )
|
||||
{
|
||||
SetTitle( Gwen::Utility::Format( L"Profiler %i fps", m_iFrames ) );
|
||||
|
||||
m_fLastSecond = Gwen::Platform::GetTimeInSeconds() + 1.0f;
|
||||
m_iFrames = 0;
|
||||
}
|
||||
|
||||
Gwen::Controls::WindowControl::Render( skin );
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
struct MyTestMenuBar : public Gwen::Controls::MenuStrip
|
||||
{
|
||||
MyProfileWindow* m_profileWindow;
|
||||
|
||||
|
||||
MyTestMenuBar(Gwen::Controls::Base* pParent, MyProfileWindow* profileWindow)
|
||||
:Gwen::Controls::MenuStrip(pParent),
|
||||
m_profileWindow(profileWindow)
|
||||
{
|
||||
// Gwen::Controls::MenuStrip* menu = new Gwen::Controls::MenuStrip( pParent );
|
||||
{
|
||||
Gwen::Controls::MenuItem* pRoot = AddItem( L"File" );
|
||||
|
||||
pRoot = AddItem( L"View" );
|
||||
// Gwen::Event::Handler* handler = GWEN_MCALL(&MyTestMenuBar::MenuItemSelect );
|
||||
pRoot->GetMenu()->AddItem( L"Profiler",m_profileWindow,(Gwen::Event::Handler::Function)&MyProfileWindow::MenuItemSelect);
|
||||
|
||||
/* pRoot->GetMenu()->AddItem( L"New", L"test16.png", GWEN_MCALL( ThisClass::MenuItemSelect ) );
|
||||
pRoot->GetMenu()->AddItem( L"Load", L"test16.png", GWEN_MCALL( ThisClass::MenuItemSelect ) );
|
||||
pRoot->GetMenu()->AddItem( L"Save", GWEN_MCALL( ThisClass::MenuItemSelect ) );
|
||||
pRoot->GetMenu()->AddItem( L"Save As..", GWEN_MCALL( ThisClass::MenuItemSelect ) );
|
||||
pRoot->GetMenu()->AddItem( L"Quit", GWEN_MCALL( ThisClass::MenuItemSelect ) );
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void setupGUI(int width, int height, sth_stash* font, float retinaScale,GLPrimitiveRenderer* primRender)
|
||||
{
|
||||
primRenderer = primRender;
|
||||
pRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,width,height, retinaScale);
|
||||
if (primRenderer)
|
||||
primRenderer->setScreenSize(width,height);
|
||||
|
||||
// pRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
||||
skin.SetRender( pRenderer );
|
||||
|
||||
pCanvas = new Gwen::Controls::Canvas( &skin );
|
||||
pCanvas->SetSize( width,height);
|
||||
pCanvas->SetDrawBackground( false);
|
||||
pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );
|
||||
// pCanvas->SetScale(.5);
|
||||
//MyWindow* window = new MyWindow(pCanvas);
|
||||
profWindow = new MyProfileWindow(pCanvas);
|
||||
|
||||
MyTestMenuBar* menubar = new MyTestMenuBar(pCanvas, profWindow);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void resizeGUI(int width, int height)
|
||||
{
|
||||
pCanvas->SetSize(width,height);
|
||||
pRenderer->resize(width,height);
|
||||
primRenderer->setScreenSize(width,height);
|
||||
}
|
||||
|
||||
void processProfileData(CProfileIterator* iterator, bool idle)
|
||||
{
|
||||
if (profWindow)
|
||||
{
|
||||
|
||||
profWindow->UpdateText(iterator, idle);
|
||||
}
|
||||
|
||||
}
|
||||
24
btgui/OpenGLWindow/gwenWindow.h
Normal file
24
btgui/OpenGLWindow/gwenWindow.h
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
#ifndef MY_GWEN_WINDOW_H
|
||||
#define MY_GWEN_WINDOW_H
|
||||
|
||||
|
||||
#include "Gwen/Gwen.h"
|
||||
#include "Gwen/Controls/Button.h"
|
||||
#include "Gwen/Skins/Simple.h"
|
||||
#include "Gwen/Renderers/OpenGL_DebugFont.h"
|
||||
|
||||
struct sth_stash;
|
||||
|
||||
extern class GwenOpenGL3CoreRenderer* pRenderer;
|
||||
//extern Gwen::Renderer::OpenGL_DebugFont * pRenderer;
|
||||
extern Gwen::Skin::Simple skin;
|
||||
extern Gwen::Controls::Canvas* pCanvas;
|
||||
|
||||
class GLPrimitiveRenderer;
|
||||
|
||||
void setupGUI(int width, int height, sth_stash* font, float retinaScale,GLPrimitiveRenderer* primRender);
|
||||
void processProfileData(class CProfileIterator* iterator, bool idle);
|
||||
void resizeGUI(int width, int height);
|
||||
|
||||
#endif //MY_GWEN_WINDOW_H
|
||||
516
btgui/OpenGLWindow/main.cpp
Normal file
516
btgui/OpenGLWindow/main.cpp
Normal file
@@ -0,0 +1,516 @@
|
||||
/*
|
||||
Copyright (c) 2012 Advanced Micro Devices, Inc.
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
//Originally written by Erwin Coumans
|
||||
|
||||
//
|
||||
//#include "vld.h"
|
||||
#ifndef __APPLE__
|
||||
#include <GL/glew.h>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
#include "GLInstancingRenderer.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include "MacOpenGLWindow.h"
|
||||
#elif _WIN32
|
||||
#include "Win32OpenGLWindow.h"
|
||||
#elif __linux
|
||||
#include "X11OpenGLWindow.h"
|
||||
#endif
|
||||
|
||||
#include "GLPrimitiveRenderer.h"
|
||||
|
||||
extern char OpenSansData[];
|
||||
|
||||
#include "renderscene.h"
|
||||
|
||||
|
||||
#include "BulletCommon/btQuickprof.h"
|
||||
#include "BulletCommon/btQuaternion.h"
|
||||
|
||||
#include "BulletCommon/CommandLineArgs.h"
|
||||
|
||||
#include "../OpenGLTrueTypeFont/fontstash.h"
|
||||
#include "../OpenGLTrueTypeFont/opengl_fontstashcallbacks.h"
|
||||
|
||||
bool printStats = false;
|
||||
bool pauseSimulation = false;
|
||||
bool shootObject = false;
|
||||
|
||||
|
||||
bool useInterop = false;
|
||||
|
||||
extern int NUM_OBJECTS_X;
|
||||
extern int NUM_OBJECTS_Y;
|
||||
extern int NUM_OBJECTS_Z;
|
||||
extern bool keepStaticObjects;
|
||||
extern float X_GAP;
|
||||
extern float Y_GAP;
|
||||
extern float Z_GAP;
|
||||
|
||||
const char* fileName="../../bin/1000 stack.bullet";
|
||||
void Usage()
|
||||
{
|
||||
printf("\nprogram.exe [--pause_simulation=<0 or 1>] [--load_bulletfile=test.bullet] [--enable_interop=<0 or 1>] [--enable_gpusap=<0 or 1>] [--enable_convexheightfield=<0 or 1>] [--enable_static=<0 or 1>] [--x_dim=<int>] [--y_dim=<num>] [--z_dim=<int>] [--x_gap=<float>] [--y_gap=<float>] [--z_gap=<float>]\n");
|
||||
};
|
||||
|
||||
|
||||
#include "gwenWindow.h"
|
||||
|
||||
|
||||
void MyMouseButtonCallback(int button, int state, float x, float y)
|
||||
{
|
||||
//btDefaultMouseCallback(button,state,x,y);
|
||||
|
||||
if (pCanvas)
|
||||
{
|
||||
bool handled = pCanvas->InputMouseMoved(x,y,x, y);
|
||||
|
||||
if (button>=0)
|
||||
{
|
||||
handled = pCanvas->InputMouseButton(button,state);
|
||||
if (handled)
|
||||
{
|
||||
if (!state)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int g_OpenGLWidth = 1024;//650;
|
||||
int g_OpenGLHeight =800;
|
||||
|
||||
void MyResizeCallback(float width, float height)
|
||||
{
|
||||
g_OpenGLWidth = width;
|
||||
g_OpenGLHeight = height;
|
||||
if (pCanvas)
|
||||
{
|
||||
pCanvas->SetSize(width,height);
|
||||
resizeGUI(width,height);
|
||||
}
|
||||
}
|
||||
|
||||
void MyMouseMoveCallback( float x, float y)
|
||||
{
|
||||
//btDefaultMouseCallback(button,state,x,y);
|
||||
|
||||
static int m_lastmousepos[2] = {0,0};
|
||||
static bool isInitialized = false;
|
||||
if (pCanvas)
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
isInitialized = true;
|
||||
m_lastmousepos[0] = x+1;
|
||||
m_lastmousepos[1] = y+1;
|
||||
}
|
||||
bool handled = pCanvas->InputMouseMoved(x,y,m_lastmousepos[0],m_lastmousepos[1]);
|
||||
}
|
||||
}
|
||||
|
||||
int droidRegular;//, droidItalic, droidBold, droidJapanese, dejavu;
|
||||
|
||||
sth_stash* initFont(GLPrimitiveRenderer* primRender)
|
||||
{
|
||||
GLint err;
|
||||
|
||||
struct sth_stash* stash = 0;
|
||||
int datasize;
|
||||
|
||||
float sx,sy,dx,dy,lh;
|
||||
GLuint texture;
|
||||
OpenGL2RenderCallbacks* renderCallbacks = new OpenGL2RenderCallbacks(primRender);
|
||||
stash = sth_create(512,512,renderCallbacks);//256,256);//,1024);//512,512);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
if (!stash)
|
||||
{
|
||||
fprintf(stderr, "Could not create stash.\n");
|
||||
return 0;
|
||||
}
|
||||
#ifdef LOAD_FONT_FROM_FILE
|
||||
unsigned char* data;
|
||||
const char* fontPaths[]={
|
||||
"./",
|
||||
"../../bin/",
|
||||
"../bin/",
|
||||
"bin/"
|
||||
};
|
||||
|
||||
int numPaths=sizeof(fontPaths)/sizeof(char*);
|
||||
|
||||
// Load the first truetype font from memory (just because we can).
|
||||
|
||||
FILE* fp = 0;
|
||||
const char* fontPath ="./";
|
||||
char fullFontFileName[1024];
|
||||
|
||||
for (int i=0;i<numPaths;i++)
|
||||
{
|
||||
|
||||
fontPath = fontPaths[i];
|
||||
//sprintf(fullFontFileName,"%s%s",fontPath,"OpenSans.ttf");//"DroidSerif-Regular.ttf");
|
||||
sprintf(fullFontFileName,"%s%s",fontPath,"DroidSerif-Regular.ttf");//OpenSans.ttf");//"DroidSerif-Regular.ttf");
|
||||
fp = fopen(fullFontFileName, "rb");
|
||||
if (fp)
|
||||
break;
|
||||
}
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
assert(fp);
|
||||
if (fp)
|
||||
{
|
||||
fseek(fp, 0, SEEK_END);
|
||||
datasize = (int)ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
data = (unsigned char*)malloc(datasize);
|
||||
if (data == NULL)
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
fread(data, 1, datasize, fp);
|
||||
fclose(fp);
|
||||
fp = 0;
|
||||
}
|
||||
if (!(droidRegular = sth_add_font_from_memory(stash, data)))
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
// Load the remaining truetype fonts directly.
|
||||
sprintf(fullFontFileName,"%s%s",fontPath,"DroidSerif-Italic.ttf");
|
||||
|
||||
if (!(droidItalic = sth_add_font(stash,fullFontFileName)))
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
sprintf(fullFontFileName,"%s%s",fontPath,"DroidSerif-Bold.ttf");
|
||||
|
||||
if (!(droidBold = sth_add_font(stash,fullFontFileName)))
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
sprintf(fullFontFileName,"%s%s",fontPath,"DroidSansJapanese.ttf");
|
||||
if (!(droidJapanese = sth_add_font(stash,fullFontFileName)))
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
#else//LOAD_FONT_FROM_FILE
|
||||
char* data2 = OpenSansData;
|
||||
unsigned char* data = (unsigned char*) data2;
|
||||
if (!(droidRegular = sth_add_font_from_memory(stash, data)))
|
||||
{
|
||||
printf("error!\n");
|
||||
}
|
||||
#endif//LOAD_FONT_FROM_FILE
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
return stash;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
CommandLineArgs args(argc,argv);
|
||||
|
||||
if (args.CheckCmdLineFlag("help"))
|
||||
{
|
||||
Usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
args.GetCmdLineArgument("enable_interop", useInterop);
|
||||
printf("useInterop=%d\n",useInterop);
|
||||
|
||||
|
||||
|
||||
args.GetCmdLineArgument("pause_simulation", pauseSimulation);
|
||||
printf("pause_simulation=%d\n",pauseSimulation);
|
||||
args.GetCmdLineArgument("x_dim", NUM_OBJECTS_X);
|
||||
args.GetCmdLineArgument("y_dim", NUM_OBJECTS_Y);
|
||||
args.GetCmdLineArgument("z_dim", NUM_OBJECTS_Z);
|
||||
|
||||
args.GetCmdLineArgument("x_gap", X_GAP);
|
||||
args.GetCmdLineArgument("y_gap", Y_GAP);
|
||||
args.GetCmdLineArgument("z_gap", Z_GAP);
|
||||
printf("x_dim=%d, y_dim=%d, z_dim=%d\n",NUM_OBJECTS_X,NUM_OBJECTS_Y,NUM_OBJECTS_Z);
|
||||
printf("x_gap=%f, y_gap=%f, z_gap=%f\n",X_GAP,Y_GAP,Z_GAP);
|
||||
|
||||
args.GetCmdLineArgument("enable_static", keepStaticObjects);
|
||||
printf("enable_static=%d\n",keepStaticObjects);
|
||||
|
||||
|
||||
char* tmpfile = 0;
|
||||
args.GetCmdLineArgument("load_bulletfile", tmpfile );
|
||||
if (tmpfile)
|
||||
fileName = tmpfile;
|
||||
|
||||
printf("load_bulletfile=%s\n",fileName);
|
||||
|
||||
|
||||
printf("\n");
|
||||
btgDefaultOpenGLWindow* window = new btgDefaultOpenGLWindow();
|
||||
btgWindowConstructionInfo wci;
|
||||
wci.m_width = g_OpenGLWidth;
|
||||
wci.m_height = g_OpenGLHeight;
|
||||
|
||||
window->createWindow(wci);
|
||||
window->setWindowTitle("render test");
|
||||
|
||||
|
||||
|
||||
float retinaScale = 1;
|
||||
|
||||
#ifndef __APPLE__
|
||||
GLenum err = glewInit();
|
||||
#else
|
||||
retinaScale = window->getRetinaScale();
|
||||
#endif
|
||||
|
||||
window->runMainLoop();
|
||||
window->startRendering();
|
||||
window->endRendering();
|
||||
|
||||
int maxObjectCapacity=128*1024;
|
||||
GLInstancingRenderer render(maxObjectCapacity);
|
||||
|
||||
GLPrimitiveRenderer* primRenderer = new GLPrimitiveRenderer(g_OpenGLWidth,g_OpenGLHeight);
|
||||
|
||||
sth_stash* stash = initFont(primRenderer);
|
||||
|
||||
render.InitShaders();
|
||||
|
||||
|
||||
createSceneProgrammatically(render);
|
||||
|
||||
|
||||
render.writeTransforms();
|
||||
|
||||
window->runMainLoop();
|
||||
|
||||
window->setMouseButtonCallback(MyMouseButtonCallback);
|
||||
window->setMouseMoveCallback(MyMouseMoveCallback);
|
||||
window->setResizeCallback(MyResizeCallback);
|
||||
window->setKeyboardCallback(btDefaultKeyboardCallback);
|
||||
window->setWheelCallback(btDefaultWheelCallback);
|
||||
|
||||
|
||||
//GLPrimitiveRenderer* pprender = new GLPrimitiveRenderer(g_OpenGLWidth,g_OpenGLHeight);
|
||||
|
||||
glUseProgram(0);
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
|
||||
if (pCanvas)
|
||||
{
|
||||
pCanvas->SetSize(g_OpenGLWidth,g_OpenGLHeight);
|
||||
}
|
||||
setupGUI(g_OpenGLWidth,g_OpenGLHeight,stash,retinaScale,primRenderer);
|
||||
class CProfileIterator* m_profileIterator;
|
||||
m_profileIterator = CProfileManager::Get_Iterator();
|
||||
|
||||
glClearColor(1,1,1,1);
|
||||
while (!window->requestedExit())
|
||||
{
|
||||
CProfileManager::Reset();
|
||||
|
||||
{
|
||||
BT_PROFILE("loop");
|
||||
|
||||
|
||||
|
||||
|
||||
{
|
||||
BT_PROFILE("startRendering");
|
||||
window->startRendering();
|
||||
}
|
||||
render.RenderScene();
|
||||
glFinish();
|
||||
float col[4]={0,1,0,1};
|
||||
// pprender->drawRect(10,50,120,60,col);
|
||||
// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
//glEnable(GL_TEXTURE_2D);
|
||||
|
||||
float x = 10;
|
||||
float y=220;
|
||||
float dx=0;
|
||||
if (1)
|
||||
{
|
||||
BT_PROFILE("font sth_draw_text");
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
GLint err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
sth_begin_draw(stash);
|
||||
sth_flush_draw(stash);
|
||||
sth_draw_text(stash, droidRegular,20.f, x, y, "Non-retina font rendering !@#$", &dx,g_OpenGLWidth,g_OpenGLHeight,0,1);//retinaScale);
|
||||
if (retinaScale!=1.f)
|
||||
sth_draw_text(stash, droidRegular,20.f*retinaScale, x, y+20, "Retina font rendering!@#$", &dx,g_OpenGLWidth,g_OpenGLHeight,0,retinaScale);
|
||||
sth_flush_draw(stash);
|
||||
|
||||
sth_end_draw(stash);
|
||||
}
|
||||
|
||||
if (1)
|
||||
{
|
||||
BT_PROFILE("gwen RenderCanvas");
|
||||
|
||||
if (pCanvas)
|
||||
{
|
||||
glEnable(GL_BLEND);
|
||||
GLint err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
//glColor4ub(255,0,0,255);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// saveOpenGLState(width,height);//m_glutScreenWidth,m_glutScreenHeight);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
|
||||
pCanvas->RenderCanvas();
|
||||
//restoreOpenGLState();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
window->endRendering();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
CProfileManager::Increment_Frame_Counter();
|
||||
|
||||
|
||||
|
||||
static bool printStats = true;
|
||||
|
||||
|
||||
if (printStats && !pauseSimulation)
|
||||
{
|
||||
static int count = 0;
|
||||
count--;
|
||||
if (count<0)
|
||||
{
|
||||
count = 100;
|
||||
{
|
||||
//BT_PROFILE("processProfileData");
|
||||
processProfileData(m_profileIterator,false);
|
||||
}
|
||||
//CProfileManager::dumpAll();
|
||||
//printStats = false;
|
||||
} else
|
||||
{
|
||||
// printf(".");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//delete pprender;
|
||||
// render.CleanupShaders();
|
||||
window->closeWindow();
|
||||
|
||||
delete window;
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
199
btgui/OpenGLWindow/renderscene.cpp
Normal file
199
btgui/OpenGLWindow/renderscene.cpp
Normal file
@@ -0,0 +1,199 @@
|
||||
int NUM_OBJECTS_X = 35;
|
||||
int NUM_OBJECTS_Y = 35;
|
||||
int NUM_OBJECTS_Z = 35;
|
||||
|
||||
|
||||
float X_GAP = 2.3f;
|
||||
float Y_GAP = 2.f;
|
||||
float Z_GAP = 2.3f;
|
||||
|
||||
bool keepStaticObjects = false;
|
||||
#include <stdio.h>
|
||||
|
||||
#include "OpenGLInclude.h"
|
||||
|
||||
#include "renderscene.h"
|
||||
|
||||
#include "GLInstancingRenderer.h"
|
||||
//#include "LinearMath/btQuickprof.h"
|
||||
#include "BulletCommon/btQuaternion.h"
|
||||
#include "BulletCommon/btMatrix3x3.h"
|
||||
//#include "../opencl/gpu_rigidbody_pipeline/btConvexUtility.h"
|
||||
#include "ShapeData.h"
|
||||
///work-in-progress
|
||||
///This ReadBulletSample is kept as simple as possible without dependencies to the Bullet SDK.
|
||||
///It can be used to load .bullet data for other physics SDKs
|
||||
///For a more complete example how to load and convert Bullet data using the Bullet SDK check out
|
||||
///the Bullet/Demos/SerializeDemo and Bullet/Serialize/BulletWorldImporter
|
||||
|
||||
|
||||
//using namespace Bullet;
|
||||
|
||||
struct GraphicsVertex
|
||||
{
|
||||
float xyzw[4];
|
||||
float normal[3];
|
||||
float uv[2];
|
||||
};
|
||||
struct GraphicsShape
|
||||
{
|
||||
const float* m_vertices;
|
||||
int m_numvertices;
|
||||
const int* m_indices;
|
||||
int m_numIndices;
|
||||
float m_scaling[4];
|
||||
};
|
||||
|
||||
struct InstanceGroup
|
||||
{
|
||||
// Bullet::btCollisionShapeData* m_shape;
|
||||
int m_collisionShapeIndex;
|
||||
|
||||
// btAlignedObjectArray<bParse::bStructHandle*> m_rigidBodies;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#define MY_UNITSPHERE_POINTS 42
|
||||
|
||||
static btVector3 sUnitSpherePoints[MY_UNITSPHERE_POINTS] =
|
||||
{
|
||||
btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)),
|
||||
btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)),
|
||||
btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)),
|
||||
btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)),
|
||||
btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)),
|
||||
btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)),
|
||||
btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)),
|
||||
btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)),
|
||||
btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)),
|
||||
btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)),
|
||||
btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)),
|
||||
btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)),
|
||||
btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)),
|
||||
btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)),
|
||||
btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)),
|
||||
btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)),
|
||||
btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)),
|
||||
btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)),
|
||||
btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)),
|
||||
btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)),
|
||||
btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)),
|
||||
btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)),
|
||||
btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)),
|
||||
btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)),
|
||||
btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)),
|
||||
btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)),
|
||||
btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)),
|
||||
btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)),
|
||||
btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)),
|
||||
btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)),
|
||||
btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)),
|
||||
btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)),
|
||||
btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)),
|
||||
btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)),
|
||||
btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)),
|
||||
btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)),
|
||||
btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)),
|
||||
btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)),
|
||||
btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)),
|
||||
btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)),
|
||||
btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)),
|
||||
btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))
|
||||
};
|
||||
|
||||
|
||||
void createSceneProgrammatically(GLInstancingRenderer& renderer)
|
||||
{
|
||||
int strideInBytes = sizeof(float)*9;
|
||||
|
||||
bool noHeightField = false;
|
||||
int barrelShapeIndex = -1;
|
||||
int cubeShapeIndex = -1;
|
||||
int tetraShapeIndex = -1;
|
||||
|
||||
float position[4]={0,0,0,0};
|
||||
btQuaternion born(btVector3(1,0,0),SIMD_PI*0.25*0.5);
|
||||
|
||||
float orn[4] = {0,0,0,1};
|
||||
// float rotOrn[4] = {born.getX(),born.getY(),born.getZ(),born.getW()};//
|
||||
float rotOrn[4] ={0,0,0,1};
|
||||
|
||||
|
||||
float color[4] = {1,1,1,1};
|
||||
int index=0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
float cubeScaling[4] = {1,1,1,1};
|
||||
{
|
||||
int numVertices = sizeof(cube_vertices)/strideInBytes;
|
||||
int numIndices = sizeof(cube_indices)/sizeof(int);
|
||||
cubeShapeIndex = renderer.registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (1)
|
||||
for (int i=0;i<NUM_OBJECTS_X;i++)
|
||||
{
|
||||
for (int j=0;j<NUM_OBJECTS_Y;j++)
|
||||
{
|
||||
int k=0;
|
||||
|
||||
for (;k<NUM_OBJECTS_Z;k++)
|
||||
{
|
||||
|
||||
float mass = 1.f;//j? 1.f : 0.f;
|
||||
|
||||
position[0]=(i*X_GAP-NUM_OBJECTS_X/2)+(j&1);
|
||||
position[1]=1+(j*Y_GAP);//-NUM_OBJECTS_Y/2);
|
||||
position[2]=(k*Z_GAP-NUM_OBJECTS_Z/2)+(j&1);
|
||||
position[3] = 0.f;
|
||||
|
||||
renderer.registerGraphicsInstance(cubeShapeIndex,position,rotOrn,color,cubeScaling);
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
int numVertices = sizeof(tetra_vertices)/strideInBytes;
|
||||
int numIndices = sizeof(tetra_indices)/sizeof(int);
|
||||
tetraShapeIndex = renderer.registerShape(&tetra_vertices[0],numVertices,tetra_indices,numIndices);
|
||||
}
|
||||
|
||||
{
|
||||
float groundScaling[4] = {2.5,2,2.5,1};
|
||||
|
||||
for (int i=0;i<50;i++)
|
||||
for (int j=0;j<50;j++)
|
||||
if (1)
|
||||
{
|
||||
void* ptr = (void*) index;
|
||||
float posnew[4];
|
||||
posnew[0] = i*5.0-120;
|
||||
posnew[1] = 0;
|
||||
posnew[2] = j*5.0-120;
|
||||
posnew[3] = 1.f;
|
||||
|
||||
color[0] = 1.f;
|
||||
color[1] = 0.f;
|
||||
color[2] = 0.f;
|
||||
renderer.registerGraphicsInstance(tetraShapeIndex,posnew,orn,color,groundScaling);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
7
btgui/OpenGLWindow/renderscene.h
Normal file
7
btgui/OpenGLWindow/renderscene.h
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
#ifndef RENDER_SCENE_H
|
||||
#define RENDER_SCENE_H
|
||||
|
||||
void createSceneProgrammatically(class GLInstancingRenderer& renderer);
|
||||
|
||||
#endif//
|
||||
@@ -96,6 +96,8 @@
|
||||
include "../btgui/Gwen"
|
||||
include "../btgui/GwenOpenGLTest"
|
||||
include "../btgui/OpenGLTrueTypeFont"
|
||||
include "../btgui/OpenGLWindow"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user