more X11/Linux debug-graphics fixes
This commit is contained in:
@@ -68,8 +68,8 @@ void MyMouseButtonCallback(int button, int state, float x, float y)
|
||||
}
|
||||
}
|
||||
|
||||
int sWidth = 1050;
|
||||
int sHeight = 768;
|
||||
int sWidth = 800;//1050;
|
||||
int sHeight = 600;//768;
|
||||
GLPrimitiveRenderer* primRenderer=0;
|
||||
//GwenOpenGL3CoreRenderer* gwenRenderer=0;
|
||||
Gwen::Renderer::Base* gwenRenderer =0;
|
||||
@@ -107,7 +107,7 @@ sth_stash* initFont(GLPrimitiveRenderer* primRenderer)
|
||||
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");
|
||||
@@ -121,7 +121,7 @@ sth_stash* initFont(GLPrimitiveRenderer* primRenderer)
|
||||
float sx,sy,dx,dy,lh;
|
||||
GLuint texture;
|
||||
|
||||
|
||||
|
||||
|
||||
const char* fontPaths[]={
|
||||
"./",
|
||||
@@ -131,16 +131,16 @@ sth_stash* initFont(GLPrimitiveRenderer* primRenderer)
|
||||
};
|
||||
|
||||
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");
|
||||
@@ -151,7 +151,7 @@ sth_stash* initFont(GLPrimitiveRenderer* primRenderer)
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
assert(fp);
|
||||
if (fp)
|
||||
{
|
||||
@@ -195,7 +195,7 @@ sth_stash* initFont(GLPrimitiveRenderer* primRenderer)
|
||||
}
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
sprintf(fullFontFileName,"%s%s",fontPath,"DroidSansJapanese.ttf");
|
||||
if (!(droidJapanese = sth_add_font(stash,fullFontFileName)))
|
||||
{
|
||||
@@ -222,7 +222,7 @@ void keyCallback(int key, int value)
|
||||
{
|
||||
printf("key = %d, value = %d\n", key,value);
|
||||
//pCanvas->InputKey(key,value==1);
|
||||
|
||||
|
||||
|
||||
int gwenKey = -1;
|
||||
|
||||
@@ -278,8 +278,8 @@ void keyCallback(int key, int value)
|
||||
gwenKey = Gwen::Key::Control;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
default:
|
||||
{
|
||||
@@ -308,57 +308,68 @@ int main()
|
||||
b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow();
|
||||
window->setKeyboardCallback(keyCallback);
|
||||
b3gWindowConstructionInfo wci;
|
||||
wci.m_openglVersion = 2;
|
||||
wci.m_openglVersion = 3;
|
||||
wci.m_width = sWidth;
|
||||
wci.m_height = sHeight;
|
||||
// wci.m_resizeCallback = MyResizeCallback;
|
||||
|
||||
|
||||
window->createWindow(wci);
|
||||
window->setResizeCallback(MyResizeCallback);
|
||||
window->setWindowTitle("render test");
|
||||
|
||||
|
||||
int majorGlVersion, minorGlVersion;
|
||||
|
||||
|
||||
if (!sscanf((const char*)glGetString(GL_VERSION), "%d.%d", &majorGlVersion, &minorGlVersion)==2)
|
||||
{
|
||||
printf("Exit: Error cannot extract OpenGL version from GL_VERSION string\n");
|
||||
exit(0);
|
||||
}
|
||||
if (majorGlVersion>=3)
|
||||
if (majorGlVersion>=3 && wci.m_openglVersion>=3)
|
||||
{
|
||||
float retinaScale = 1.f;
|
||||
|
||||
|
||||
#ifndef __APPLE__
|
||||
#ifndef _WIN32
|
||||
//we need glewExperimental on Linux
|
||||
glewExperimental = GL_TRUE;
|
||||
#endif // _WIN32
|
||||
glewInit();
|
||||
#endif
|
||||
|
||||
|
||||
//we ned to call glGetError twice, because of some Ubuntu/Intel/OpenGL issue
|
||||
|
||||
GLuint err = glGetError();
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
retinaScale = window->getRetinaScale();
|
||||
|
||||
|
||||
primRenderer = new GLPrimitiveRenderer(sWidth,sHeight);
|
||||
|
||||
|
||||
sth_stash* font = initFont(primRenderer );
|
||||
|
||||
|
||||
|
||||
|
||||
gwenRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,sWidth,sHeight,retinaScale);
|
||||
|
||||
} else
|
||||
{
|
||||
//OpenGL 2.x
|
||||
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
||||
|
||||
|
||||
|
||||
|
||||
skin.SetRender( gwenRenderer );
|
||||
|
||||
|
||||
pCanvas = new Gwen::Controls::Canvas( &skin );
|
||||
pCanvas->SetSize( sWidth, sHeight);
|
||||
pCanvas->SetDrawBackground( true );
|
||||
pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );
|
||||
|
||||
|
||||
glClearColor(1,0,0,1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Create a GWEN OpenGL Renderer
|
||||
@@ -368,7 +379,7 @@ int main()
|
||||
//
|
||||
// Create a GWEN skin
|
||||
//
|
||||
|
||||
|
||||
|
||||
#ifdef USE_TEXTURED_SKIN
|
||||
Gwen::Skin::TexturedBase skin;
|
||||
@@ -398,7 +409,7 @@ int main()
|
||||
pUnit->SetPos( 10, 10 );
|
||||
|
||||
//
|
||||
// Create a Windows Control helper
|
||||
// Create a Windows Control helper
|
||||
// (Processes Windows MSG's and fires input at GWEN)
|
||||
//
|
||||
//Gwen::Input::Windows GwenInput;
|
||||
@@ -410,7 +421,7 @@ int main()
|
||||
// MSG msg;
|
||||
while( !window->requestedExit() )
|
||||
{
|
||||
if (majorGlVersion<3)
|
||||
if (majorGlVersion<3 || wci.m_openglVersion<3)
|
||||
{
|
||||
saveOpenGLState(sWidth,sHeight);
|
||||
}
|
||||
@@ -437,7 +448,7 @@ int main()
|
||||
}
|
||||
|
||||
window->startRendering();
|
||||
|
||||
|
||||
// Main OpenGL Render Loop
|
||||
{
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
@@ -447,33 +458,33 @@ int main()
|
||||
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);
|
||||
|
||||
@@ -485,25 +496,25 @@ int main()
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pCanvas->RenderCanvas();
|
||||
|
||||
|
||||
if (avoidUpdate<=0)
|
||||
avoidUpdate++;
|
||||
|
||||
// SwapBuffers( GetDC( g_pHWND ) );
|
||||
}
|
||||
window->endRendering();
|
||||
|
||||
if (majorGlVersion<3)
|
||||
|
||||
if (majorGlVersion<3 || wci.m_openglVersion<3)
|
||||
{
|
||||
restoreOpenGLState();
|
||||
}
|
||||
@@ -511,6 +522,6 @@ int main()
|
||||
|
||||
window->closeWindow();
|
||||
delete window;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,26 @@
|
||||
|
||||
///See http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/
|
||||
|
||||
bool gIntelLinuxglDrawBufferWorkaround=false;
|
||||
|
||||
#include "GLRenderToTexture.h"
|
||||
#include "Bullet3Common/b3Scalar.h" // for b3Assert
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
bool gIntelLinuxglDrawBufferWorkaround=false;
|
||||
|
||||
GLRenderToTexture::GLRenderToTexture()
|
||||
:m_framebufferName(0)
|
||||
{
|
||||
const GLubyte* ven = glGetString(GL_VENDOR);
|
||||
printf("ven = %s\n",ven);
|
||||
|
||||
if (strncmp((const char*)ven,"Intel",5)==0)
|
||||
{
|
||||
printf("Workaround for some crash in the Intel OpenGL driver on Linux/Ubuntu\n");
|
||||
gIntelLinuxglDrawBufferWorkaround=true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GLRenderToTexture::init(int width, int height, GLuint textureId, int renderTextureType)
|
||||
|
||||
@@ -17,7 +17,6 @@ struct GLRenderToTexture
|
||||
bool m_initialized;
|
||||
int m_renderTextureType;
|
||||
public:
|
||||
|
||||
GLRenderToTexture();
|
||||
|
||||
void init(int width, int height, GLuint textureId, int renderTextureType=RENDERTEXTURE_COLOR);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <pthread.h>
|
||||
extern bool gIntelLinuxglDrawBufferWorkaround;
|
||||
|
||||
GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };
|
||||
static bool forceOpenGL3 = true;
|
||||
@@ -235,11 +234,6 @@ void X11OpenGLWindow::enableOpenGL()
|
||||
const GLubyte* ven = glGetString(GL_VENDOR);
|
||||
printf("GL_VENDOR=%s\n", ven);
|
||||
|
||||
if (strncmp((const char*)ven,"Intel",5)==0)
|
||||
{
|
||||
printf("Workaround for some crash in the Intel OpenGL driver on Linux/Ubuntu\n");
|
||||
gIntelLinuxglDrawBufferWorkaround=true;
|
||||
}
|
||||
const GLubyte* ren = glGetString(GL_RENDERER);
|
||||
printf("GL_RENDERER=%s\n",ren);
|
||||
const GLubyte* ver = glGetString(GL_VERSION);
|
||||
@@ -276,7 +270,10 @@ printf("createWindow\n");
|
||||
|
||||
m_data->m_root = DefaultRootWindow(m_data->m_dpy);
|
||||
|
||||
|
||||
if (ci.m_openglVersion < 3)
|
||||
{
|
||||
forceOpenGL3 = false;
|
||||
}
|
||||
|
||||
if (forceOpenGL3)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user