2015-05-07 21:11:17 +00:00
|
|
|
#ifndef NO_OPENGL3
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
#include "SimpleOpenGL3App.h"
|
|
|
|
#include "ShapeData.h"
|
|
|
|
#ifdef __APPLE__
|
|
|
|
#include "MacOpenGLWindow.h"
|
|
|
|
#else
|
|
|
|
|
2015-04-16 22:29:39 +00:00
|
|
|
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "Win32OpenGLWindow.h"
|
|
|
|
#else
|
|
|
|
//let's cross the fingers it is Linux/X11
|
2017-02-07 00:22:17 +00:00
|
|
|
#ifdef BT_USE_EGL
|
|
|
|
#include "EGLOpenGLWindow.h"
|
|
|
|
#else
|
2015-04-16 16:55:32 +00:00
|
|
|
#include "X11OpenGLWindow.h"
|
2017-02-07 00:22:17 +00:00
|
|
|
#endif //BT_USE_EGL
|
2015-04-16 16:55:32 +00:00
|
|
|
#endif //_WIN32
|
|
|
|
#endif//__APPLE__
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "GLPrimitiveRenderer.h"
|
|
|
|
#include "GLInstancingRenderer.h"
|
|
|
|
|
|
|
|
#include "Bullet3Common/b3Vector3.h"
|
|
|
|
#include "Bullet3Common/b3Logging.h"
|
|
|
|
|
|
|
|
#include "fontstash.h"
|
|
|
|
#include "TwFonts.h"
|
|
|
|
#include "opengl_fontstashcallbacks.h"
|
|
|
|
#include <assert.h>
|
|
|
|
#include "GLRenderToTexture.h"
|
|
|
|
#include "Bullet3Common/b3Quaternion.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define popen _popen
|
|
|
|
#define pclose _pclose
|
|
|
|
#endif // _WIN32
|
|
|
|
|
|
|
|
struct SimpleInternalData
|
|
|
|
{
|
|
|
|
GLuint m_fontTextureId;
|
|
|
|
GLuint m_largeFontTextureId;
|
|
|
|
struct sth_stash* m_fontStash;
|
|
|
|
OpenGL2RenderCallbacks* m_renderCallbacks;
|
|
|
|
int m_droidRegular;
|
|
|
|
const char* m_frameDumpPngFileName;
|
|
|
|
FILE* m_ffmpegFile;
|
|
|
|
GLRenderToTexture* m_renderTexture;
|
|
|
|
void* m_userPointer;
|
|
|
|
int m_upAxis;//y=1 or z=2 is supported
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
static SimpleOpenGL3App* gApp=0;
|
|
|
|
|
|
|
|
static void SimpleResizeCallback( float widthf, float heightf)
|
|
|
|
{
|
|
|
|
int width = (int)widthf;
|
|
|
|
int height = (int)heightf;
|
2016-05-04 06:46:29 +00:00
|
|
|
if (gApp && gApp->m_instancingRenderer)
|
|
|
|
gApp->m_instancingRenderer->resize(width,height);
|
|
|
|
|
|
|
|
if (gApp && gApp->m_primRenderer)
|
|
|
|
gApp->m_primRenderer->setScreenSize(width,height);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SimpleKeyboardCallback(int key, int state)
|
|
|
|
{
|
|
|
|
if (key==B3G_ESCAPE && gApp && gApp->m_window)
|
|
|
|
{
|
|
|
|
gApp->m_window->setRequestExit();
|
|
|
|
} else
|
|
|
|
{
|
2015-04-16 22:16:13 +00:00
|
|
|
//gApp->defaultKeyboardCallback(key,state);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:16:13 +00:00
|
|
|
void SimpleMouseButtonCallback( int button, int state, float x, float y)
|
|
|
|
{
|
|
|
|
gApp->defaultMouseButtonCallback(button,state,x,y);
|
|
|
|
}
|
|
|
|
void SimpleMouseMoveCallback( float x, float y)
|
|
|
|
{
|
|
|
|
gApp->defaultMouseMoveCallback(x,y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleWheelCallback( float deltax, float deltay)
|
|
|
|
{
|
|
|
|
gApp->defaultWheelCallback(deltax,deltay);
|
|
|
|
}
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2016-10-13 06:03:36 +00:00
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
|
2015-04-16 16:55:32 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
|
|
|
return TexID;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern unsigned char OpenSansData[];
|
|
|
|
|
2015-08-07 23:21:33 +00:00
|
|
|
SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height, bool allowRetina)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
gApp = this;
|
2016-05-04 06:46:29 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
m_data = new SimpleInternalData;
|
|
|
|
m_data->m_frameDumpPngFileName = 0;
|
|
|
|
m_data->m_renderTexture = 0;
|
|
|
|
m_data->m_ffmpegFile = 0;
|
|
|
|
m_data->m_userPointer = 0;
|
|
|
|
m_data->m_upAxis = 1;
|
|
|
|
|
|
|
|
m_window = new b3gDefaultOpenGLWindow();
|
2016-05-04 06:46:29 +00:00
|
|
|
|
2015-08-07 23:21:33 +00:00
|
|
|
m_window->setAllowRetina(allowRetina);
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
b3gWindowConstructionInfo ci;
|
|
|
|
ci.m_title = title;
|
|
|
|
ci.m_width = width;
|
|
|
|
ci.m_height = height;
|
|
|
|
m_window->createWindow(ci);
|
|
|
|
|
|
|
|
m_window->setWindowTitle(title);
|
|
|
|
|
|
|
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
|
|
|
|
2015-08-05 01:24:30 +00:00
|
|
|
glClearColor( m_backgroundColorRGB[0],
|
|
|
|
m_backgroundColorRGB[1],
|
|
|
|
m_backgroundColorRGB[2],
|
|
|
|
1.f);
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
m_window->startRendering();
|
2016-05-04 06:46:29 +00:00
|
|
|
width = m_window->getWidth();
|
|
|
|
height = m_window->getHeight();
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
|
|
|
|
2017-02-07 00:22:17 +00:00
|
|
|
#ifndef NO_GLEW
|
2015-04-16 16:55:32 +00:00
|
|
|
#ifndef __APPLE__
|
|
|
|
#ifndef _WIN32
|
2017-02-07 00:22:17 +00:00
|
|
|
//some Linux implementations need the 'glewExperimental' to be true
|
2015-04-16 16:55:32 +00:00
|
|
|
glewExperimental = GL_TRUE;
|
2017-02-07 00:22:17 +00:00
|
|
|
#endif //_WIN32
|
|
|
|
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
if (glewInit() != GLEW_OK)
|
|
|
|
exit(1); // or handle the error in a nicer way
|
|
|
|
if (!GLEW_VERSION_2_1) // check that the machine supports the 2.1 API.
|
|
|
|
exit(1); // or handle the error in a nicer way
|
2017-02-07 00:22:17 +00:00
|
|
|
|
|
|
|
#endif //__APPLE__
|
|
|
|
#endif //NO_GLEW
|
2015-04-16 16:55:32 +00:00
|
|
|
glGetError();//don't remove this call, it is needed for Ubuntu
|
|
|
|
|
|
|
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
|
|
|
|
|
|
|
m_parameterInterface = 0;
|
2016-05-04 06:46:29 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
|
|
|
|
2016-09-24 04:59:38 +00:00
|
|
|
m_instancingRenderer = new GLInstancingRenderer(128*1024,128*1024*1024);
|
2016-10-14 22:06:09 +00:00
|
|
|
|
2016-05-04 06:46:29 +00:00
|
|
|
m_primRenderer = new GLPrimitiveRenderer(width,height);
|
|
|
|
|
|
|
|
m_renderer = m_instancingRenderer ;
|
|
|
|
m_window->setResizeCallback(SimpleResizeCallback);
|
|
|
|
|
|
|
|
|
|
|
|
m_instancingRenderer->init();
|
2015-04-16 16:55:32 +00:00
|
|
|
m_instancingRenderer->resize(width,height);
|
2016-05-04 06:46:29 +00:00
|
|
|
m_primRenderer->setScreenSize(width,height);
|
|
|
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
m_instancingRenderer->InitShaders();
|
|
|
|
|
2015-04-16 22:16:13 +00:00
|
|
|
m_window->setMouseMoveCallback(SimpleMouseMoveCallback);
|
|
|
|
m_window->setMouseButtonCallback(SimpleMouseButtonCallback);
|
2015-04-16 16:55:32 +00:00
|
|
|
m_window->setKeyboardCallback(SimpleKeyboardCallback);
|
2015-04-16 22:16:13 +00:00
|
|
|
m_window->setWheelCallback(SimpleWheelCallback);
|
2016-05-04 06:46:29 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
TwGenerateDefaultFonts();
|
|
|
|
m_data->m_fontTextureId = BindFont(g_DefaultNormalFont);
|
|
|
|
m_data->m_largeFontTextureId = BindFont(g_DefaultLargeFont);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_data->m_renderCallbacks = new OpenGL2RenderCallbacks(m_primRenderer);
|
|
|
|
m_data->m_fontStash = sth_create(512,512,m_data->m_renderCallbacks);//256,256);//,1024);//512,512);
|
|
|
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
|
|
|
|
|
|
|
if (!m_data->m_fontStash)
|
|
|
|
{
|
|
|
|
b3Warning("Could not create stash");
|
|
|
|
//fprintf(stderr, "Could not create stash.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned char* data2 = OpenSansData;
|
|
|
|
unsigned char* data = (unsigned char*) data2;
|
|
|
|
if (!(m_data->m_droidRegular = sth_add_font_from_memory(m_data->m_fontStash, data)))
|
|
|
|
{
|
|
|
|
b3Warning("error!\n");
|
|
|
|
}
|
|
|
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct sth_stash* SimpleOpenGL3App::getFontStash()
|
|
|
|
{
|
|
|
|
return m_data->m_fontStash;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleOpenGL3App::drawText3D( const char* txt, float worldPosX, float worldPosY, float worldPosZ, float size1)
|
|
|
|
{
|
2016-09-19 14:02:43 +00:00
|
|
|
B3_PROFILE("SimpleOpenGL3App::drawText3D");
|
2015-04-16 16:55:32 +00:00
|
|
|
float viewMat[16];
|
|
|
|
float projMat[16];
|
2015-04-16 22:16:13 +00:00
|
|
|
CommonCameraInterface* cam = m_instancingRenderer->getActiveCamera();
|
|
|
|
|
|
|
|
cam->getCameraViewMatrix(viewMat);
|
|
|
|
cam->getCameraProjectionMatrix(projMat);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
float camPos[4];
|
2015-04-16 22:16:13 +00:00
|
|
|
cam->getCameraPosition(camPos);
|
2015-07-27 20:28:47 +00:00
|
|
|
//b3Vector3 cp= b3MakeVector3(camPos[0],camPos[2],camPos[1]);
|
|
|
|
//b3Vector3 p = b3MakeVector3(worldPosX,worldPosY,worldPosZ);
|
2015-04-16 16:55:32 +00:00
|
|
|
//float dist = (cp-p).length();
|
|
|
|
//float dv = 0;//dist/1000.f;
|
|
|
|
//
|
|
|
|
//printf("str = %s\n",unicodeText);
|
|
|
|
|
|
|
|
float dx=0;
|
|
|
|
|
|
|
|
//int measureOnly=0;
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
int viewport[4]={0,0,m_instancingRenderer->getScreenWidth(),m_instancingRenderer->getScreenHeight()};
|
|
|
|
|
|
|
|
float posX = 450.f;
|
|
|
|
float posY = 100.f;
|
|
|
|
float winx,winy, winz;
|
|
|
|
|
|
|
|
if (!projectWorldCoordToScreen(worldPosX, worldPosY, worldPosZ,viewMat,projMat,viewport,&winx, &winy, &winz))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
posX = winx;
|
|
|
|
posY = m_instancingRenderer->getScreenHeight()/2+(m_instancingRenderer->getScreenHeight()/2)-winy;
|
|
|
|
|
|
|
|
|
|
|
|
if (0)//m_useTrueTypeFont)
|
|
|
|
{
|
|
|
|
bool measureOnly = false;
|
|
|
|
|
|
|
|
float fontSize= 32;//64;//512;//128;
|
2016-09-19 14:02:43 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
sth_draw_text(m_data->m_fontStash,
|
|
|
|
m_data->m_droidRegular,fontSize,posX,posY,
|
|
|
|
txt,&dx, this->m_instancingRenderer->getScreenWidth(),this->m_instancingRenderer->getScreenHeight(),measureOnly,m_window->getRetinaScale());
|
|
|
|
sth_end_draw(m_data->m_fontStash);
|
|
|
|
sth_flush_draw(m_data->m_fontStash);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
//float width = 0.f;
|
|
|
|
int pos=0;
|
|
|
|
//float color[]={0.2f,0.2,0.2f,1.f};
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D,m_data->m_largeFontTextureId);
|
|
|
|
|
|
|
|
//float width = r.x;
|
|
|
|
//float extraSpacing = 0.;
|
|
|
|
|
|
|
|
float startX = posX;
|
|
|
|
float startY = posY-g_DefaultLargeFont->m_CharHeight*size1;
|
|
|
|
|
|
|
|
|
|
|
|
while (txt[pos])
|
|
|
|
{
|
|
|
|
int c = txt[pos];
|
|
|
|
//r.h = g_DefaultNormalFont->m_CharHeight;
|
|
|
|
//r.w = g_DefaultNormalFont->m_CharWidth[c]+extraSpacing;
|
|
|
|
float endX = startX+g_DefaultLargeFont->m_CharWidth[c]*size1;
|
|
|
|
float endY = posY;
|
|
|
|
|
|
|
|
|
|
|
|
float currentColor[]={1.f,0.2,0.2f,1.f};
|
|
|
|
|
|
|
|
// m_primRenderer->drawTexturedRect(startX, startY, endX, endY, currentColor,g_DefaultLargeFont->m_CharU0[c],g_DefaultLargeFont->m_CharV0[c],g_DefaultLargeFont->m_CharU1[c],g_DefaultLargeFont->m_CharV1[c]);
|
|
|
|
float u0 = g_DefaultLargeFont->m_CharU0[c];
|
|
|
|
float u1 = g_DefaultLargeFont->m_CharU1[c];
|
|
|
|
float v0 = g_DefaultLargeFont->m_CharV0[c];
|
|
|
|
float v1 = g_DefaultLargeFont->m_CharV1[c];
|
|
|
|
float color[4] = {currentColor[0],currentColor[1],currentColor[2],currentColor[3]};
|
|
|
|
float x0 = startX;
|
|
|
|
float x1 = endX;
|
|
|
|
float y0 = startY;
|
|
|
|
float y1 = endY;
|
|
|
|
int screenWidth = m_instancingRenderer->getScreenWidth();
|
|
|
|
int screenHeight = m_instancingRenderer->getScreenHeight();
|
|
|
|
|
|
|
|
float z = 2.f*winz-1.f;//*(far
|
|
|
|
float identity[16]={1,0,0,0,
|
|
|
|
0,1,0,0,
|
|
|
|
0,0,1,0,
|
|
|
|
0,0,0,1};
|
|
|
|
PrimVertex vertexData[4] = {
|
2016-12-29 06:24:03 +00:00
|
|
|
PrimVertex(PrimVec4(-1.f+2.f*x0/float(screenWidth), 1.f-2.f*y0/float(screenHeight), z, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u0,v0)),
|
|
|
|
PrimVertex(PrimVec4(-1.f+2.f*x0/float(screenWidth), 1.f-2.f*y1/float(screenHeight), z, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u0,v1)),
|
|
|
|
PrimVertex(PrimVec4( -1.f+2.f*x1/float(screenWidth), 1.f-2.f*y1/float(screenHeight), z, 1.f ), PrimVec4(color[0], color[1], color[2], color[3]) ,PrimVec2(u1,v1)),
|
|
|
|
PrimVertex(PrimVec4( -1.f+2.f*x1/float(screenWidth), 1.f-2.f*y0/float(screenHeight), z, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u1,v0))
|
2015-04-16 16:55:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
m_primRenderer->drawTexturedRect3D(vertexData[0],vertexData[1],vertexData[2],vertexData[3],identity,identity,false);
|
|
|
|
|
|
|
|
//DrawTexturedRect(0,r,g_DefaultNormalFont->m_CharU0[c],g_DefaultNormalFont->m_CharV0[c],g_DefaultNormalFont->m_CharU1[c],g_DefaultNormalFont->m_CharV1[c]);
|
|
|
|
// DrawFilledRect(r);
|
|
|
|
|
|
|
|
startX = endX;
|
|
|
|
//startY = endY;
|
|
|
|
|
|
|
|
pos++;
|
|
|
|
|
|
|
|
}
|
|
|
|
glBindTexture(GL_TEXTURE_2D,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-27 07:01:45 +00:00
|
|
|
void SimpleOpenGL3App::drawText( const char* txt, int posXi, int posYi, float size)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
float posX = (float)posXi;
|
|
|
|
float posY = (float) posYi;
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//printf("str = %s\n",unicodeText);
|
|
|
|
|
|
|
|
float dx=0;
|
|
|
|
|
|
|
|
//int measureOnly=0;
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
|
|
|
|
if (1)//m_useTrueTypeFont)
|
|
|
|
{
|
|
|
|
bool measureOnly = false;
|
|
|
|
|
2016-09-27 07:01:45 +00:00
|
|
|
float fontSize= 64*size;//512;//128;
|
2015-04-16 16:55:32 +00:00
|
|
|
sth_draw_text(m_data->m_fontStash,
|
|
|
|
m_data->m_droidRegular,fontSize,posX,posY,
|
|
|
|
txt,&dx, this->m_instancingRenderer->getScreenWidth(),
|
|
|
|
this->m_instancingRenderer->getScreenHeight(),
|
|
|
|
measureOnly,
|
|
|
|
m_window->getRetinaScale());
|
|
|
|
|
|
|
|
sth_end_draw(m_data->m_fontStash);
|
|
|
|
sth_flush_draw(m_data->m_fontStash);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
//float width = 0.f;
|
|
|
|
int pos=0;
|
|
|
|
//float color[]={0.2f,0.2,0.2f,1.f};
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D,m_data->m_largeFontTextureId);
|
|
|
|
|
|
|
|
//float width = r.x;
|
|
|
|
//float extraSpacing = 0.;
|
|
|
|
|
|
|
|
float startX = posX;
|
|
|
|
float startY = posY;
|
|
|
|
|
|
|
|
|
|
|
|
while (txt[pos])
|
|
|
|
{
|
|
|
|
int c = txt[pos];
|
|
|
|
//r.h = g_DefaultNormalFont->m_CharHeight;
|
|
|
|
//r.w = g_DefaultNormalFont->m_CharWidth[c]+extraSpacing;
|
|
|
|
float endX = startX+g_DefaultLargeFont->m_CharWidth[c];
|
|
|
|
float endY = startY+g_DefaultLargeFont->m_CharHeight;
|
|
|
|
|
|
|
|
|
|
|
|
float currentColor[]={0.2f,0.2,0.2f,1.f};
|
|
|
|
|
|
|
|
m_primRenderer->drawTexturedRect(startX, startY, endX, endY, currentColor,g_DefaultLargeFont->m_CharU0[c],g_DefaultLargeFont->m_CharV0[c],g_DefaultLargeFont->m_CharU1[c],g_DefaultLargeFont->m_CharV1[c]);
|
|
|
|
|
|
|
|
//DrawTexturedRect(0,r,g_DefaultNormalFont->m_CharU0[c],g_DefaultNormalFont->m_CharV0[c],g_DefaultNormalFont->m_CharU1[c],g_DefaultNormalFont->m_CharV1[c]);
|
|
|
|
// DrawFilledRect(r);
|
|
|
|
|
|
|
|
startX = endX;
|
|
|
|
//startY = endY;
|
|
|
|
|
|
|
|
pos++;
|
|
|
|
|
|
|
|
}
|
|
|
|
glBindTexture(GL_TEXTURE_2D,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
2016-05-18 06:57:19 +00:00
|
|
|
|
|
|
|
void SimpleOpenGL3App::drawTexturedRect(float x0, float y0, float x1, float y1, float color[4], float u0,float v0, float u1, float v1, int useRGBA)
|
|
|
|
{
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
m_primRenderer->drawTexturedRect(x0,y0,x1,y1,color,u0,v0,u1,v1,useRGBA);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
struct GfxVertex
|
|
|
|
{
|
|
|
|
float x,y,z,w;
|
|
|
|
float nx,ny,nz;
|
|
|
|
float u,v;
|
|
|
|
};
|
|
|
|
|
2015-08-10 21:30:00 +00:00
|
|
|
int SimpleOpenGL3App::registerCubeShape(float halfExtentsX,float halfExtentsY, float halfExtentsZ, int textureIndex, float textureScaling)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
int strideInBytes = 9*sizeof(float);
|
2015-08-10 21:30:00 +00:00
|
|
|
int numVertices = sizeof(cube_vertices_textured)/strideInBytes;
|
2015-04-16 16:55:32 +00:00
|
|
|
int numIndices = sizeof(cube_indices)/sizeof(int);
|
|
|
|
|
|
|
|
b3AlignedObjectArray<GfxVertex> verts;
|
|
|
|
verts.resize(numVertices);
|
|
|
|
for (int i=0;i<numVertices;i++)
|
|
|
|
{
|
2015-08-10 21:30:00 +00:00
|
|
|
verts[i].x = halfExtentsX*cube_vertices_textured[i*9];
|
|
|
|
verts[i].y = halfExtentsY*cube_vertices_textured[i*9+1];
|
|
|
|
verts[i].z = halfExtentsZ*cube_vertices_textured[i*9+2];
|
|
|
|
verts[i].w = cube_vertices_textured[i*9+3];
|
|
|
|
verts[i].nx = cube_vertices_textured[i*9+4];
|
|
|
|
verts[i].ny = cube_vertices_textured[i*9+5];
|
|
|
|
verts[i].nz = cube_vertices_textured[i*9+6];
|
|
|
|
verts[i].u = cube_vertices_textured[i*9+7]*textureScaling;
|
|
|
|
verts[i].v = cube_vertices_textured[i*9+8]*textureScaling;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2015-08-06 02:03:27 +00:00
|
|
|
int shapeId = m_instancingRenderer->registerShape(&verts[0].x,numVertices,cube_indices,numIndices,B3_GL_TRIANGLES,textureIndex);
|
2015-04-16 16:55:32 +00:00
|
|
|
return shapeId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleOpenGL3App::registerGrid(int cells_x, int cells_z, float color0[4], float color1[4])
|
|
|
|
{
|
|
|
|
b3Vector3 cubeExtents=b3MakeVector3(0.5,0.5,0.5);
|
|
|
|
cubeExtents[m_data->m_upAxis] = 0;
|
|
|
|
int cubeId = registerCubeShape(cubeExtents[0],cubeExtents[1],cubeExtents[2]);
|
|
|
|
|
|
|
|
b3Quaternion orn(0,0,0,1);
|
|
|
|
b3Vector3 center=b3MakeVector3(0,0,0,1);
|
|
|
|
b3Vector3 scaling=b3MakeVector3(1,1,1,1);
|
|
|
|
|
|
|
|
for ( int i = 0; i < cells_x; i++)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < cells_z; j++)
|
|
|
|
{
|
|
|
|
float* color =0;
|
|
|
|
if ((i + j) % 2 == 0)
|
|
|
|
{
|
|
|
|
color = (float*)color0;
|
|
|
|
} else {
|
|
|
|
color = (float*)color1;
|
|
|
|
}
|
|
|
|
if (this->m_data->m_upAxis==1)
|
|
|
|
{
|
|
|
|
center =b3MakeVector3((i + 0.5f) - cells_x * 0.5f, 0.f, (j + 0.5f) - cells_z * 0.5f);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
center =b3MakeVector3((i + 0.5f) - cells_x * 0.5f, (j + 0.5f) - cells_z * 0.5f,0.f );
|
|
|
|
}
|
|
|
|
m_instancingRenderer->registerGraphicsInstance(cubeId,center,orn,color,scaling);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-06 02:03:27 +00:00
|
|
|
int SimpleOpenGL3App::registerGraphicsUnitSphereShape(EnumSphereLevelOfDetail lod, int textureId)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
int strideInBytes = 9*sizeof(float);
|
|
|
|
|
|
|
|
int graphicsShapeIndex = -1;
|
|
|
|
|
2015-08-06 02:03:27 +00:00
|
|
|
switch (lod)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2015-08-06 02:03:27 +00:00
|
|
|
case SPHERE_LOD_POINT_SPRITE:
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
int numVertices = sizeof(point_sphere_vertices)/strideInBytes;
|
|
|
|
int numIndices = sizeof(point_sphere_indices)/sizeof(int);
|
2015-08-06 02:03:27 +00:00
|
|
|
graphicsShapeIndex = m_instancingRenderer->registerShape(&point_sphere_vertices[0],numVertices,point_sphere_indices,numIndices,B3_GL_POINTS,textureId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SPHERE_LOD_LOW:
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2015-08-06 02:03:27 +00:00
|
|
|
int numVertices = sizeof(low_sphere_vertices)/strideInBytes;
|
|
|
|
int numIndices = sizeof(low_sphere_indices)/sizeof(int);
|
|
|
|
graphicsShapeIndex = m_instancingRenderer->registerShape(&low_sphere_vertices[0],numVertices,low_sphere_indices,numIndices,B3_GL_TRIANGLES,textureId);
|
|
|
|
break;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
2015-08-06 02:03:27 +00:00
|
|
|
case SPHERE_LOD_MEDIUM:
|
|
|
|
{
|
|
|
|
int numVertices = sizeof(medium_sphere_vertices)/strideInBytes;
|
|
|
|
int numIndices = sizeof(medium_sphere_indices)/sizeof(int);
|
|
|
|
graphicsShapeIndex = m_instancingRenderer->registerShape(&medium_sphere_vertices[0],numVertices,medium_sphere_indices,numIndices,B3_GL_TRIANGLES,textureId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SPHERE_LOD_HIGH:
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
int numVertices = sizeof(detailed_sphere_vertices)/strideInBytes;
|
|
|
|
int numIndices = sizeof(detailed_sphere_indices)/sizeof(int);
|
|
|
|
graphicsShapeIndex = m_instancingRenderer->registerShape(&detailed_sphere_vertices[0],numVertices,detailed_sphere_indices,numIndices,B3_GL_TRIANGLES,textureId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2015-04-16 16:55:32 +00:00
|
|
|
return graphicsShapeIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SimpleOpenGL3App::drawGrid(DrawGridData data)
|
|
|
|
{
|
|
|
|
int gridSize = data.gridSize;
|
|
|
|
float upOffset = data.upOffset;
|
|
|
|
int upAxis = data.upAxis;
|
|
|
|
float gridColor[4];
|
|
|
|
gridColor[0] = data.gridColor[0];
|
|
|
|
gridColor[1] = data.gridColor[1];
|
|
|
|
gridColor[2] = data.gridColor[2];
|
|
|
|
gridColor[3] = data.gridColor[3];
|
|
|
|
|
|
|
|
int sideAxis=-1;
|
|
|
|
int forwardAxis=-1;
|
|
|
|
|
|
|
|
switch (upAxis)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
forwardAxis=2;
|
|
|
|
sideAxis=0;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
forwardAxis=1;
|
|
|
|
sideAxis=0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
b3Assert(0);
|
|
|
|
};
|
|
|
|
//b3Vector3 gridColor = b3MakeVector3(0.5,0.5,0.5);
|
|
|
|
|
2015-07-27 20:28:47 +00:00
|
|
|
b3AlignedObjectArray<unsigned int> indices;
|
|
|
|
b3AlignedObjectArray<b3Vector3> vertices;
|
2015-04-16 16:55:32 +00:00
|
|
|
int lineIndex=0;
|
|
|
|
for(int i=-gridSize;i<=gridSize;i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
|
|
|
b3Vector3 from = b3MakeVector3(0,0,0);
|
|
|
|
from[sideAxis] = float(i);
|
|
|
|
from[upAxis] = upOffset;
|
|
|
|
from[forwardAxis] = float(-gridSize);
|
|
|
|
b3Vector3 to=b3MakeVector3(0,0,0);
|
|
|
|
to[sideAxis] = float(i);
|
|
|
|
to[upAxis] = upOffset;
|
|
|
|
to[forwardAxis] = float(gridSize);
|
|
|
|
vertices.push_back(from);
|
|
|
|
indices.push_back(lineIndex++);
|
|
|
|
vertices.push_back(to);
|
|
|
|
indices.push_back(lineIndex++);
|
2015-07-27 20:28:47 +00:00
|
|
|
// m_instancingRenderer->drawLine(from,to,gridColor);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
|
|
|
{
|
|
|
|
|
|
|
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
|
|
|
b3Vector3 from=b3MakeVector3(0,0,0);
|
|
|
|
from[sideAxis] = float(-gridSize);
|
|
|
|
from[upAxis] = upOffset;
|
|
|
|
from[forwardAxis] = float(i);
|
|
|
|
b3Vector3 to=b3MakeVector3(0,0,0);
|
|
|
|
to[sideAxis] = float(gridSize);
|
|
|
|
to[upAxis] = upOffset;
|
|
|
|
to[forwardAxis] = float(i);
|
|
|
|
vertices.push_back(from);
|
|
|
|
indices.push_back(lineIndex++);
|
|
|
|
vertices.push_back(to);
|
|
|
|
indices.push_back(lineIndex++);
|
2015-07-27 20:28:47 +00:00
|
|
|
// m_instancingRenderer->drawLine(from,to,gridColor);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-27 20:28:47 +00:00
|
|
|
m_instancingRenderer->drawLines(&vertices[0].x,
|
2015-04-16 16:55:32 +00:00
|
|
|
gridColor,
|
|
|
|
vertices.size(),sizeof(b3Vector3),&indices[0],indices.size(),1);
|
2015-07-27 20:28:47 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
m_instancingRenderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(1,0,0),b3MakeVector3(1,0,0),3);
|
|
|
|
m_instancingRenderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(0,1,0),b3MakeVector3(0,1,0),3);
|
|
|
|
m_instancingRenderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(0,0,1),b3MakeVector3(0,0,1),3);
|
|
|
|
|
|
|
|
// void GLInstancingRenderer::drawPoints(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, float pointDrawSize)
|
|
|
|
|
|
|
|
//we don't use drawPoints because all points would have the same color
|
|
|
|
// b3Vector3 points[3] = { b3MakeVector3(1, 0, 0), b3MakeVector3(0, 1, 0), b3MakeVector3(0, 0, 1) };
|
|
|
|
// m_instancingRenderer->drawPoints(&points[0].x, b3MakeVector3(1, 0, 0), 3, sizeof(b3Vector3), 6);
|
|
|
|
|
|
|
|
m_instancingRenderer->drawPoint(b3MakeVector3(1,0,0),b3MakeVector3(1,0,0),6);
|
|
|
|
m_instancingRenderer->drawPoint(b3MakeVector3(0,1,0),b3MakeVector3(0,1,0),6);
|
|
|
|
m_instancingRenderer->drawPoint(b3MakeVector3(0,0,1),b3MakeVector3(0,0,1),6);
|
|
|
|
}
|
|
|
|
|
2015-08-05 01:24:30 +00:00
|
|
|
void SimpleOpenGL3App::setBackgroundColor(float red, float green, float blue)
|
|
|
|
{
|
|
|
|
CommonGraphicsApp::setBackgroundColor(red,green,blue);
|
|
|
|
glClearColor(m_backgroundColorRGB[0],m_backgroundColorRGB[1],m_backgroundColorRGB[2],1.f);
|
|
|
|
}
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
SimpleOpenGL3App::~SimpleOpenGL3App()
|
|
|
|
{
|
2016-07-15 03:42:00 +00:00
|
|
|
|
|
|
|
delete m_instancingRenderer;
|
2015-04-16 16:55:32 +00:00
|
|
|
delete m_primRenderer ;
|
2016-07-15 03:42:00 +00:00
|
|
|
sth_delete(m_data->m_fontStash);
|
|
|
|
delete m_data->m_renderCallbacks;
|
|
|
|
TwDeleteDefaultFonts();
|
2016-07-16 07:55:56 +00:00
|
|
|
m_window->closeWindow();
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
delete m_window;
|
|
|
|
delete m_data ;
|
|
|
|
}
|
|
|
|
|
2016-07-13 01:16:13 +00:00
|
|
|
void SimpleOpenGL3App::getScreenPixels(unsigned char* rgbaBuffer, int bufferSizeInBytes, float* depthBuffer, int depthBufferSizeInBytes)
|
2016-05-31 17:23:04 +00:00
|
|
|
{
|
2016-06-02 00:47:41 +00:00
|
|
|
|
2016-05-31 17:23:04 +00:00
|
|
|
int width = (int)m_window->getRetinaScale()*m_instancingRenderer->getScreenWidth();
|
|
|
|
int height = (int)m_window->getRetinaScale()*m_instancingRenderer->getScreenHeight();
|
|
|
|
if ((width*height*4) == bufferSizeInBytes)
|
|
|
|
{
|
|
|
|
glReadPixels(0,0,width, height, GL_RGBA, GL_UNSIGNED_BYTE, rgbaBuffer);
|
2017-01-16 16:23:49 +00:00
|
|
|
int glstat;
|
|
|
|
glstat = glGetError();
|
2016-05-31 17:23:04 +00:00
|
|
|
b3Assert(glstat==GL_NO_ERROR);
|
2016-07-13 01:16:13 +00:00
|
|
|
}
|
|
|
|
if ((width*height*sizeof(float)) == depthBufferSizeInBytes)
|
|
|
|
{
|
|
|
|
glReadPixels(0,0,width, height, GL_DEPTH_COMPONENT, GL_FLOAT, depthBuffer);
|
2017-01-16 16:23:49 +00:00
|
|
|
int glstat;
|
|
|
|
glstat = glGetError();
|
2016-07-13 01:16:13 +00:00
|
|
|
b3Assert(glstat==GL_NO_ERROR);
|
2016-05-31 17:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
//#define STB_IMAGE_WRITE_IMPLEMENTATION
|
|
|
|
#include "stb_image_write.h"
|
|
|
|
static void writeTextureToFile(int textureWidth, int textureHeight, const char* fileName, FILE* ffmpegVideo)
|
|
|
|
{
|
|
|
|
int numComponents = 4;
|
|
|
|
//glPixelStorei(GL_PACK_ALIGNMENT,1);
|
|
|
|
|
|
|
|
b3Assert(glGetError()==GL_NO_ERROR);
|
|
|
|
//glReadBuffer(GL_BACK);//COLOR_ATTACHMENT0);
|
|
|
|
|
|
|
|
float* orgPixels = (float*)malloc(textureWidth*textureHeight*numComponents*4);
|
|
|
|
glReadPixels(0,0,textureWidth, textureHeight, GL_RGBA, GL_FLOAT, orgPixels);
|
|
|
|
//it is useful to have the actual float values for debugging purposes
|
|
|
|
|
|
|
|
//convert float->char
|
|
|
|
char* pixels = (char*)malloc(textureWidth*textureHeight*numComponents);
|
|
|
|
assert(glGetError()==GL_NO_ERROR);
|
|
|
|
|
|
|
|
for (int j=0;j<textureHeight;j++)
|
|
|
|
{
|
|
|
|
for (int i=0;i<textureWidth;i++)
|
|
|
|
{
|
|
|
|
pixels[(j*textureWidth+i)*numComponents] = char(orgPixels[(j*textureWidth+i)*numComponents]*255.f);
|
|
|
|
pixels[(j*textureWidth+i)*numComponents+1]=char(orgPixels[(j*textureWidth+i)*numComponents+1]*255.f);
|
|
|
|
pixels[(j*textureWidth+i)*numComponents+2]=char(orgPixels[(j*textureWidth+i)*numComponents+2]*255.f);
|
|
|
|
pixels[(j*textureWidth+i)*numComponents+3]=char(orgPixels[(j*textureWidth+i)*numComponents+3]*255.f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ffmpegVideo)
|
|
|
|
{
|
|
|
|
fwrite(pixels, textureWidth*textureHeight*numComponents, 1, ffmpegVideo);
|
|
|
|
//fwrite(pixels, 100,1,ffmpegVideo);//textureWidth*textureHeight*numComponents, 1, ffmpegVideo);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (1)
|
|
|
|
{
|
|
|
|
//swap the pixels
|
|
|
|
unsigned char tmp;
|
|
|
|
|
|
|
|
for (int j=0;j<textureHeight/2;j++)
|
|
|
|
{
|
|
|
|
for (int i=0;i<textureWidth;i++)
|
|
|
|
{
|
|
|
|
for (int c=0;c<numComponents;c++)
|
|
|
|
{
|
|
|
|
tmp = pixels[(j*textureWidth+i)*numComponents+c];
|
|
|
|
pixels[(j*textureWidth+i)*numComponents+c]=
|
|
|
|
pixels[((textureHeight-j-1)*textureWidth+i)*numComponents+c];
|
|
|
|
pixels[((textureHeight-j-1)*textureWidth+i)*numComponents+c] = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stbi_write_png(fileName, textureWidth,textureHeight, numComponents, pixels, textureWidth*numComponents);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
free(pixels);
|
|
|
|
free(orgPixels);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SimpleOpenGL3App::swapBuffer()
|
|
|
|
{
|
2016-07-27 16:11:08 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
if (m_data->m_frameDumpPngFileName)
|
|
|
|
{
|
2016-07-26 22:36:21 +00:00
|
|
|
int width = (int)m_window->getRetinaScale()*m_instancingRenderer->getScreenWidth();
|
|
|
|
int height = (int) m_window->getRetinaScale()*this->m_instancingRenderer->getScreenHeight();
|
|
|
|
writeTextureToFile(width,
|
|
|
|
height,m_data->m_frameDumpPngFileName,
|
2015-04-16 16:55:32 +00:00
|
|
|
m_data->m_ffmpegFile);
|
2015-08-05 01:24:30 +00:00
|
|
|
m_data->m_renderTexture->disable();
|
2015-08-10 21:30:00 +00:00
|
|
|
if (m_data->m_ffmpegFile==0)
|
|
|
|
{
|
|
|
|
m_data->m_frameDumpPngFileName = 0;
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
2017-03-16 16:13:33 +00:00
|
|
|
m_window->endRendering();
|
|
|
|
m_window->startRendering();
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// see also http://blog.mmacklin.com/2013/06/11/real-time-video-capture-with-ffmpeg/
|
|
|
|
void SimpleOpenGL3App::dumpFramesToVideo(const char* mp4FileName)
|
|
|
|
{
|
2017-03-16 16:13:33 +00:00
|
|
|
if (mp4FileName)
|
|
|
|
{
|
|
|
|
int width = (int)m_window->getRetinaScale()*m_instancingRenderer->getScreenWidth();
|
|
|
|
int height = (int)m_window->getRetinaScale()*m_instancingRenderer->getScreenHeight();
|
|
|
|
char cmd[8192];
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2016-07-29 01:06:03 +00:00
|
|
|
sprintf(cmd, "ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - "
|
2017-03-30 19:38:13 +00:00
|
|
|
"-threads 0 -y -b:v 50000k -c:v libx264 -preset slow -crf 22 -an -pix_fmt yuv420p -vf vflip %s", width, height, mp4FileName);
|
2016-07-29 01:06:03 +00:00
|
|
|
|
|
|
|
//sprintf(cmd, "ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - "
|
|
|
|
// "-y -crf 0 -b:v 1500000 -an -vcodec h264 -vf vflip %s", width, height, mp4FileName);
|
2015-04-16 16:55:32 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
sprintf(cmd, "ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - "
|
2017-03-30 19:38:13 +00:00
|
|
|
"-threads 0 -y -b 50000k -c:v libx264 -preset slow -crf 22 -an -pix_fmt yuv420p -vf vflip %s", width, height, mp4FileName);
|
2015-04-16 16:55:32 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//sprintf(cmd,"ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - "
|
|
|
|
// "-threads 0 -y -crf 0 -b 50000k -vf vflip %s",width,height,mp4FileName);
|
|
|
|
|
|
|
|
// sprintf(cmd,"ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - "
|
|
|
|
// "-threads 0 -preset fast -y -crf 21 -vf vflip %s",width,height,mp4FileName);
|
|
|
|
|
2017-03-16 16:13:33 +00:00
|
|
|
if (m_data->m_ffmpegFile)
|
|
|
|
{
|
|
|
|
pclose(m_data->m_ffmpegFile);
|
|
|
|
}
|
|
|
|
if (mp4FileName)
|
|
|
|
{
|
|
|
|
m_data->m_ffmpegFile = popen(cmd, "w");
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2017-03-16 16:13:33 +00:00
|
|
|
m_data->m_frameDumpPngFileName = mp4FileName;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (m_data->m_ffmpegFile)
|
|
|
|
{
|
|
|
|
fflush(m_data->m_ffmpegFile);
|
|
|
|
pclose(m_data->m_ffmpegFile);
|
|
|
|
m_data->m_frameDumpPngFileName = 0;
|
|
|
|
}
|
|
|
|
m_data->m_ffmpegFile = 0;
|
2015-07-17 06:58:36 +00:00
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
void SimpleOpenGL3App::dumpNextFrameToPng(const char* filename)
|
|
|
|
{
|
|
|
|
|
|
|
|
// open pipe to ffmpeg's stdin in binary write mode
|
|
|
|
|
|
|
|
m_data->m_frameDumpPngFileName = filename;
|
|
|
|
|
|
|
|
//you could use m_renderTexture to allow to render at higher resolutions, such as 4k or so
|
2015-07-17 06:58:36 +00:00
|
|
|
if (!m_data->m_renderTexture)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
m_data->m_renderTexture = new GLRenderToTexture();
|
|
|
|
GLuint renderTextureId;
|
|
|
|
glGenTextures(1, &renderTextureId);
|
|
|
|
|
|
|
|
// "Bind" the newly created texture : all future texture functions will modify this texture
|
|
|
|
glBindTexture(GL_TEXTURE_2D, renderTextureId);
|
|
|
|
|
|
|
|
// Give an empty image to OpenGL ( the last "0" )
|
|
|
|
//glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, g_OpenGLWidth,g_OpenGLHeight, 0,GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
|
|
|
//glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA32F, g_OpenGLWidth,g_OpenGLHeight, 0,GL_RGBA, GL_FLOAT, 0);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA32F,
|
2015-08-05 01:24:30 +00:00
|
|
|
m_instancingRenderer->getScreenWidth()*m_window->getRetinaScale(),m_instancingRenderer->getScreenHeight()*m_window->getRetinaScale()
|
2015-04-16 16:55:32 +00:00
|
|
|
, 0,GL_RGBA, GL_FLOAT, 0);
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
2016-10-13 06:03:36 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
2015-04-16 16:55:32 +00:00
|
|
|
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
|
2015-08-05 01:24:30 +00:00
|
|
|
m_data->m_renderTexture->init(m_instancingRenderer->getScreenWidth()*m_window->getRetinaScale(),this->m_instancingRenderer->getScreenHeight()*m_window->getRetinaScale(),renderTextureId, RENDERTEXTURE_COLOR);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 20:28:47 +00:00
|
|
|
m_data->m_renderTexture->enable();
|
2015-07-17 06:58:36 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleOpenGL3App::setUpAxis(int axis)
|
|
|
|
{
|
|
|
|
b3Assert((axis == 1)||(axis==2));//only Y or Z is supported at the moment
|
|
|
|
m_data->m_upAxis = axis;
|
|
|
|
}
|
|
|
|
int SimpleOpenGL3App::getUpAxis() const
|
|
|
|
{
|
|
|
|
return m_data->m_upAxis;
|
|
|
|
}
|
2015-05-07 21:11:17 +00:00
|
|
|
#endif//#ifndef NO_OPENGL3
|
2015-04-16 16:55:32 +00:00
|
|
|
|