experiments with params in AllBullet2Demos (quick hack for testing, will clean this up soon)

yet another workaround to make Intel GPU work with glDrawBuffers on Ubuntu
This commit is contained in:
Erwin Coumans (Google) 2014-07-08 16:42:57 -07:00
parent f89d70b895
commit 27b0e4d1e6
4 changed files with 120 additions and 28 deletions

View File

@ -71,6 +71,10 @@ struct CommonRigidBodySetup : public CommonPhysicsSetup
//remove the rigidbodies from the dynamics world and delete them
int i;
for (i = m_dynamicsWorld->getNumConstraints() - 1; i >= 0; i--)
{
m_dynamicsWorld->removeConstraint(m_dynamicsWorld->getConstraint(i));
}
if (m_dynamicsWorld)
{

View File

@ -14,6 +14,7 @@ static int sCurrentDemoIndex = 0;
static int sCurrentHightlighted = 0;
static BulletDemoInterface* sCurrentDemo = 0;
static b3AlignedObjectArray<const char*> allNames;
double motorA=0,motorB=0;
bool drawGUI=true;
@ -98,10 +99,12 @@ static void MyMouseButtonCallback(int button, int state, float x, float y)
void selectDemo(int demoIndex)
{
sCurrentDemoIndex = demoIndex;
sCurrentHightlighted = demoIndex;
int numDemos = sizeof(allDemos)/sizeof(BulletDemoEntry);
if (demoIndex>numDemos)
{
demoIndex = 0;
}
if (sCurrentDemo)
{
sCurrentDemo->exitPhysics();
@ -109,19 +112,20 @@ void selectDemo(int demoIndex)
delete sCurrentDemo;
sCurrentDemo=0;
}
if (allDemos[demoIndex].m_createFunc && app)
{
sCurrentDemo = (*allDemos[demoIndex].m_createFunc)(app);
if (sCurrentDemo)
{
sCurrentDemo->initPhysics();
}
}
}
void MyComboBoxCallback(int comboId, const char* item)
{
printf("comboId = %d, item = %s\n",comboId, item);
//printf("comboId = %d, item = %s\n",comboId, item);
if (comboId==DEMO_SELECTION_COMBOBOX)
{
//find selected item
@ -220,8 +224,87 @@ struct MyMenuItemHander :public Gwen::Event::Handler
};
template<typename T>
struct MySliderEventHandler : public Gwen::Event::Handler
{
Gwen::Controls::TextBox* m_label;
Gwen::Controls::Slider* m_pSlider;
char m_variableName[1024];
T* m_targetValue;
MySliderEventHandler(const char* varName, Gwen::Controls::TextBox* label, Gwen::Controls::Slider* pSlider,T* target)
:m_label(label),
m_pSlider(pSlider),
m_targetValue(target)
{
memcpy(m_variableName,varName,strlen(varName)+1);
}
void SliderMoved( Gwen::Controls::Base* pControl )
{
Gwen::Controls::Slider* pSlider = (Gwen::Controls::Slider*)pControl;
//printf("value = %f\n", pSlider->GetValue());//UnitPrint( Utility::Format( L"Slider Value: %.2f", pSlider->GetValue() ) );
float bla = pSlider->GetValue();
T v = T(bla);
SetValue(v);
}
void SetValue(T v)
{
if (v < m_pSlider->GetRangeMin())
{
printf("?\n");
}
if (v > m_pSlider->GetRangeMax())
{
printf("?\n");
}
m_pSlider->SetValue(v,true);
(*m_targetValue) = v;
int val = int(v);//todo: specialize on template type
char txt[1024];
sprintf(txt,"%s : %d", m_variableName,val);
m_label->SetText(txt);
}
};
void MyParameter(const char* name, GwenInternalData* data, double* param)
{
Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox(data->m_demoPage->GetPage());
//m_data->m_myControls.push_back(label);
label->SetText( name);
label->SetPos( 10, 10 + 25 );
label->SetWidth(110);
label->SetPos(10,data->m_curYposition);
data->m_curYposition+=22;
Gwen::Controls::HorizontalSlider* pSlider = new Gwen::Controls::HorizontalSlider( data->m_demoPage->GetPage());
//m_data->m_myControls.push_back(pSlider);
pSlider->SetPos( 10, data->m_curYposition );
pSlider->SetSize( 100, 20 );
pSlider->SetRange( -10, 10 );
pSlider->SetNotchCount(10);
pSlider->SetClampToNotches( true );
pSlider->SetValue( *param);//dimensions[i] );
char labelName[1024];
sprintf(labelName,"%s",name);//axisNames[0]);
MySliderEventHandler<double>* handler = new MySliderEventHandler<double>(labelName,label,pSlider,param);
pSlider->onValueChanged.Add( handler, &MySliderEventHandler<double>::SliderMoved );
handler->SliderMoved(pSlider);
float v = pSlider->GetValue();
data->m_curYposition+=22;
}
extern float shadowMapWorldSize;
int main(int argc, char* argv[])
{
shadowMapWorldSize = 25;
b3Clock clock;
float dt = 1./120.f;
@ -244,6 +327,9 @@ int main(int argc, char* argv[])
gui->init(width,height,fontstash,app->m_window->getRetinaScale());
// gui->getInternalData()->m_explorerPage
Gwen::Controls::TreeControl* tree = gui->getInternalData()->m_explorerTreeCtrl;
//gui->getInternalData()->m_demoPage;
int numDemos = sizeof(allDemos)/sizeof(BulletDemoEntry);
char nodeText[1024];
@ -304,6 +390,9 @@ int main(int argc, char* argv[])
*/
unsigned long int prevTimeInMicroseconds = clock.getTimeMicroseconds();
MyParameter("Motor A",gui->getInternalData(),&motorA);
MyParameter("Motor B",gui->getInternalData(),&motorB);
do
{

View File

@ -175,7 +175,7 @@ void GwenUserInterface::init(int width, int height,struct sth_stash* stash,float
tab->Dock( Gwen::Pos::Fill );
//tab->SetMargin( Gwen::Margin( 2, 2, 2, 2 ) );
Gwen::UnicodeString str1(L"Main");
Gwen::UnicodeString str1(L"Params");
m_data->m_demoPage = tab->AddPage(str1);

View File

@ -86,9 +86,8 @@ bool GLRenderToTexture::enable()
//Intel OpenGL driver crashes when using GL_NONE for glDrawBuffer on Linux, so use a workaround
if (gIntelLinuxglDrawBufferWorkaround)
{
GLenum drawBuffers[2] = { GL_DEPTH_ATTACHMENT,0};
GLenum drawBuffers[2] = { GL_COLOR_ATTACHMENT0,0};
glDrawBuffers(1, drawBuffers);
} else
{
glDrawBuffer(GL_NONE);