Permalink
Browse files

moved back-face poly culling, which was preventing text from being di…

…splayed on OS X
  • Loading branch information...
rtv committed Nov 5, 2011
1 parent 7881264 commit 974c30bc1c8489048b1ee369fe086b444a6365fa
Showing with 142 additions and 145 deletions.
  1. +34 −32 libstage/canvas.cc
  2. +90 −95 libstage/model_camera.cc
  3. +13 −13 libstage/worldfile.cc
  4. +4 −4 libstage/worldgui.cc
  5. +1 −1 worlds/everything.world
View
@@ -118,8 +118,9 @@ void Canvas::InitGl()
glDisable( GL_LIGHTING );
glEnable( GL_DEPTH_TEST );
glDepthFunc( GL_LESS );
- glCullFace( GL_BACK );
- glEnable (GL_CULL_FACE);
+ // culling disables text drawing on OS X, so I've disabled it until I understand why
+ //glCullFace( GL_BACK );
+ //glEnable (GL_CULL_FACE);
glEnable( GL_BLEND );
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glEnable( GL_LINE_SMOOTH );
@@ -594,9 +595,35 @@ void Canvas::RemoveModel( Model* mod )
void Canvas::DrawGlobalGrid()
{
-
bounds3d_t bounds = world->GetExtent();
+ glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+
+ glEnable(GL_POLYGON_OFFSET_FILL);
+ glPolygonOffset(2.0, 2.0);
+ glDisable(GL_BLEND);
+
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, checkTex );
+ glColor3f( 1.0, 1.0, 1.0 );
+
+ glBegin(GL_QUADS);
+ glTexCoord2f( bounds.x.min/2.0, bounds.y.min/2.0 );
+ glVertex2f( bounds.x.min, bounds.y.min );
+ glTexCoord2f( bounds.x.max/2.0, bounds.y.min/2.0);
+ glVertex2f( bounds.x.max, bounds.y.min );
+ glTexCoord2f( bounds.x.max/2.0, bounds.y.max/2.0 );
+ glVertex2f( bounds.x.max, bounds.y.max );
+ glTexCoord2f( bounds.x.min/2.0, bounds.y.max/2.0 );
+ glVertex2f( bounds.x.min, bounds.y.max );
+ glEnd();
+
+ glDisable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+
+ glDisable(GL_POLYGON_OFFSET_FILL );
+
+
/* printf( "bounds [%.2f %.2f] [%.2f %.2f] [%.2f %.2f]\n",
bounds.x.min, bounds.x.max,
bounds.y.min, bounds.y.max,
@@ -617,56 +644,31 @@ void Canvas::DrawGlobalGrid()
for( double i=0; i < bounds.x.max; i+=skip)
{
snprintf( str, 16, "%d", (int)i );
- Gl::draw_string( i, 0, 0.00, str );
+ Gl::draw_string( i, 0, 0, str );
}
for( double i=0; i >= bounds.x.min; i-=skip)
{
snprintf( str, 16, "%d", (int)i );
- Gl::draw_string( i, 0, 0.00, str );
+ Gl::draw_string( i, 0, 0, str );
}
for( double i=0; i < bounds.y.max; i+=skip)
{
snprintf( str, 16, "%d", (int)i );
- Gl::draw_string( 0, i, 0.00, str );
+ Gl::draw_string( 0, i, 0, str );
}
for( double i=0; i >= bounds.y.min; i-=skip)
{
snprintf( str, 16, "%d", (int)i );
- Gl::draw_string( 0, i, 0.00, str );
+ Gl::draw_string( 0, i, 0, str );
}
PopColor();
- glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
-
- glEnable(GL_POLYGON_OFFSET_FILL);
- glPolygonOffset(2.0, 2.0);
- glDisable(GL_BLEND);
-
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, checkTex );
- glColor3f( 1.0, 1.0, 1.0 );
-
- glBegin(GL_QUADS);
- glTexCoord2f( bounds.x.min/2.0, bounds.y.min/2.0 );
- glVertex2f( bounds.x.min, bounds.y.min );
- glTexCoord2f( bounds.x.max/2.0, bounds.y.min/2.0);
- glVertex2f( bounds.x.max, bounds.y.min );
- glTexCoord2f( bounds.x.max/2.0, bounds.y.max/2.0 );
- glVertex2f( bounds.x.max, bounds.y.max );
- glTexCoord2f( bounds.x.min/2.0, bounds.y.max/2.0 );
- glVertex2f( bounds.x.min, bounds.y.max );
- glEnd();
-
- glDisable(GL_TEXTURE_2D);
- glEnable(GL_BLEND);
-
- glDisable(GL_POLYGON_OFFSET_FILL );
}
//draw the floor without any grid ( for robot's perspective camera model )
View
@@ -242,105 +242,100 @@ bool ModelCamera::GetFrame( void )
//TODO create lines outlining camera frustrum, then iterate over each depth measurement and create a square
void ModelCamera::DataVisualize( Camera* cam )
-{
-
- if( _frame_data == NULL || !showCameraData )
- return;
-
- float w_fov = _camera.horizFov();
- float h_fov = _camera.vertFov();
-
- float start_fov = w_fov / 2.0 + 180.0; //start at right
- float start_vert_fov = h_fov / 2.0 + 90.0; //start at top
-
- int w = _width;
- int h = _height;
- float a_space = w_fov / w; //degrees between each sample
- float vert_a_space = h_fov / h; //degrees between each vertical sample
-
- //Create unit vectors representing a sphere - and cache it
- if( _valid_vertexbuf_cache == false ) {
- for( int j = 0; j < h; j++ ) {
- for( int i = 0; i < w; i++ ) {
-
- float a = start_fov - static_cast< float >( i ) * a_space;
- float vert_a = start_vert_fov - static_cast< float >( h - j - 1 ) * vert_a_space;
-
- int index = i + j * w;
- ColoredVertex* vertex = _vertexbuf_cache + index;
-
- //calculate and cache normal unit vectors of the sphere
- float x = -sin( dtor( vert_a ) ) * cos( dtor( a ) );
- float y = -sin( dtor( vert_a ) ) * sin( dtor( a ) );
- float z = -cos( dtor( vert_a ) );
-
- //rotate them about the pitch and yaw offsets - keeping distortion of the sphere at the extremes
- a = dtor( - _yaw_offset );
- vertex->x = x * cos( a ) - y * sin( a );
- vertex->y = x * sin( a ) + y * cos( a );
- vertex->z = z;
-
- x = vertex->x; y = vertex->y; z = vertex->z;
- a = dtor( _pitch_offset );
- vertex->x = z * sin( a ) + x * cos( a );
- vertex->y = y;
- vertex->z = z * cos( a ) - x * sin( a );
- }
- }
- _valid_vertexbuf_cache = true;
- }
+{
+ if( _frame_data == NULL || !showCameraData )
+ return;
+
+ float w_fov = _camera.horizFov();
+ float h_fov = _camera.vertFov();
+
+ float start_fov = w_fov / 2.0 + 180.0; //start at right
+ float start_vert_fov = h_fov / 2.0 + 90.0; //start at top
+
+ int w = _width;
+ int h = _height;
+ float a_space = w_fov / w; //degrees between each sample
+ float vert_a_space = h_fov / h; //degrees between each vertical sample
+
+ //Create unit vectors representing a sphere - and cache it
+ if( _valid_vertexbuf_cache == false ) {
+ for( int j = 0; j < h; j++ ) {
+ for( int i = 0; i < w; i++ ) {
- glDisable( GL_CULL_FACE );
- //glBegin( GL_QUADS );
+ float a = start_fov - static_cast< float >( i ) * a_space;
+ float vert_a = start_vert_fov - static_cast< float >( h - j - 1 ) * vert_a_space;
+ int index = i + j * w;
+ ColoredVertex* vertex = _vertexbuf_cache + index;
- //Scale cached unit vectors with depth-buffer
- float* depth_data = ( float* )( _frame_data );
- for( int j = 0; j < h; j++ ) {
- for( int i = 0; i < w; i++ ) {
- int index = i + j * w;
- const ColoredVertex* unit_vertex = _vertexbuf_cache + index;
- const float length = depth_data[ index ];
-
- //scale unitvectors with depth-buffer
- float sx = unit_vertex->x * length;
- float sy = unit_vertex->y * length;
- float sz = unit_vertex->z * length;
-
- //create a quad based on the current camera pixel, and normal vector
- //the quad size is porpotial to the depth distance
- float x, y, z;
- x = 0; y = 0; z = length * M_PI * a_space / 360.0;
- cross( x, y, z, unit_vertex->x, unit_vertex->y, unit_vertex->z );
-
- z = length * M_PI * vert_a_space / 360.0;
-
- GLfloat* p = _camera_quads + index * 4 * 3;
- p[ 0 ] = sx - x; p[ 1 ] = sy - y; p[ 2 ] = sz - z;
- p[ 3 ] = sx - x; p[ 4 ] = sy - y; p[ 5 ] = sz + z;
- p[ 6 ] = sx + x; p[ 7 ] = sy + y; p[ 8 ] = sz + z;
- p[ 9 ] = sx + x; p[ 10 ] = sy + y; p[ 11 ] = sz - z;
-
- //copy color for each vertex
- //TODO using a color index would be smarter
- const GLubyte* color = _frame_color_data + index * 4;
- for( int i = 0; i < 4; i++ ) {
- GLubyte* cp = _camera_colors + index * 4 * 3 + i * 3;
- memcpy( cp, color, sizeof( GLubyte ) * 3 );
- }
- }
- }
+ //calculate and cache normal unit vectors of the sphere
+ float x = -sin( dtor( vert_a ) ) * cos( dtor( a ) );
+ float y = -sin( dtor( vert_a ) ) * sin( dtor( a ) );
+ float z = -cos( dtor( vert_a ) );
-
- //glEnableClientState( GL_VERTEX_ARRAY );
- glEnableClientState( GL_COLOR_ARRAY );
-
- glVertexPointer( 3, GL_FLOAT, 0, _camera_quads );
- glColorPointer( 3, GL_UNSIGNED_BYTE, 0, _camera_colors );
- glDrawArrays( GL_QUADS, 0, w * h * 4 );
+ //rotate them about the pitch and yaw offsets - keeping distortion of the sphere at the extremes
+ a = dtor( - _yaw_offset );
+ vertex->x = x * cos( a ) - y * sin( a );
+ vertex->y = x * sin( a ) + y * cos( a );
+ vertex->z = z;
- glDisableClientState( GL_COLOR_ARRAY );
-// glDisableClientState( GL_VERTEX_ARRAY ); //TODO FIXME - something is using vertex arrays without properly enabling it
-
+ x = vertex->x; y = vertex->y; z = vertex->z;
+ a = dtor( _pitch_offset );
+ vertex->x = z * sin( a ) + x * cos( a );
+ vertex->y = y;
+ vertex->z = z * cos( a ) - x * sin( a );
+ }
+ }
+ _valid_vertexbuf_cache = true;
+ }
+
+ // glDisable( GL_CULL_FACE );
+
+
+ //Scale cached unit vectors with depth-buffer
+ float* depth_data = ( float* )( _frame_data );
+ for( int j = 0; j < h; j++ ) {
+ for( int i = 0; i < w; i++ ) {
+ int index = i + j * w;
+ const ColoredVertex* unit_vertex = _vertexbuf_cache + index;
+ const float length = depth_data[ index ];
+
+ //scale unitvectors with depth-buffer
+ float sx = unit_vertex->x * length;
+ float sy = unit_vertex->y * length;
+ float sz = unit_vertex->z * length;
+
+ //create a quad based on the current camera pixel, and normal vector
+ //the quad size is porpotial to the depth distance
+ float x, y, z;
+ x = 0; y = 0; z = length * M_PI * a_space / 360.0;
+ cross( x, y, z, unit_vertex->x, unit_vertex->y, unit_vertex->z );
+
+ z = length * M_PI * vert_a_space / 360.0;
+
+ GLfloat* p = _camera_quads + index * 4 * 3;
+ p[ 0 ] = sx - x; p[ 1 ] = sy - y; p[ 2 ] = sz - z;
+ p[ 3 ] = sx - x; p[ 4 ] = sy - y; p[ 5 ] = sz + z;
+ p[ 6 ] = sx + x; p[ 7 ] = sy + y; p[ 8 ] = sz + z;
+ p[ 9 ] = sx + x; p[ 10 ] = sy + y; p[ 11 ] = sz - z;
+
+ //copy color for each vertex
+ //TODO using a color index would be smarter
+ const GLubyte* color = _frame_color_data + index * 4;
+ for( int i = 0; i < 4; i++ ) {
+ GLubyte* cp = _camera_colors + index * 4 * 3 + i * 3;
+ memcpy( cp, color, sizeof( GLubyte ) * 3 );
+ }
+ }
+ }
+
+ // vertex arrays are already enabled
+ glEnableClientState( GL_COLOR_ARRAY );
+
+ glVertexPointer( 3, GL_FLOAT, 0, _camera_quads );
+ glColorPointer( 3, GL_UNSIGNED_BYTE, 0, _camera_colors );
+ glDrawArrays( GL_QUADS, 0, w * h * 4 );
+
+ glDisableClientState( GL_COLOR_ARRAY );
}
View
@@ -222,19 +222,19 @@ bool Worldfile::Save(const std::string& filename )
// Check for unused properties and print warnings
bool Worldfile::WarnUnused()
{
- bool unused = false;
-
- FOR_EACH( it, properties )
- {
- if( ! it->second->used )
- {
- PRINT_WARN3("worldfile %s:%d : property [%s] is defined but not used",
- this->filename.c_str(), it->second->line, it->second->name.c_str());
- unused = true;
- }
- }
-
- return unused;
+ bool unused = false;
+
+ FOR_EACH( it, properties )
+ {
+ if( ! it->second->used )
+ {
+ PRINT_WARN3("worldfile %s:%d : property [%s] is defined but not used",
+ this->filename.c_str(), it->second->line, it->second->name.c_str());
+ unused = true;
+ }
+ }
+
+ return unused;
}
View
@@ -166,8 +166,8 @@ static const char* AboutText =
"Toby Collett, Alex Couture-Beil, Jeremy Asher \n"
"and contributors\n"
"\n"
- "Distributed under the terms of the \n"
- "GNU General Public License v2";
+ "Distributed under the terms of the \n"
+ "GNU General Public License v2";
static const char* MoreHelpText =
"http://playerstage.org\n"
@@ -183,13 +183,13 @@ static const char* MoreHelpText =
"is not built by default. To build the manual, run \"make\"\n"
"in the directory \"docsrc\" to produce \"docsrc/stage/index.html\" .\n"
"(requires Doxygen and supporting programs to be installed first).\n";
-
+
WorldGui::WorldGui(int W,int H,const char* L) :
Fl_Window(W,H,L ),
canvas( new Canvas( this,0,30,W,H-30 ) ),
drawOptions(),
fileMan( new FileManager() ),
- interval_log(),
+ interval_log(),
speedup(1.0), // real time
mbar( new Fl_Menu_Bar(0,0, W, 30)),
oDlg( NULL ),
View
@@ -16,7 +16,7 @@ window
center [-7.205 1.437]
scale 71.472 # pixels per meter
- show_data 1
+ show_data 0
)
floorplan

0 comments on commit 974c30b

Please sign in to comment.