Skip to content

Commit

Permalink
more vertex arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
rtv committed May 23, 2008
1 parent 6ada4e3 commit c68a660
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 54 deletions.
102 changes: 86 additions & 16 deletions libstage/block.cc
Expand Up @@ -25,7 +25,9 @@ StgBlock::StgBlock( StgModel* mod,
this->pt_count = pt_count;
this->pts = (stg_point_t*)g_memdup( pts, pt_count * sizeof(stg_point_t));
// allocate space for the integer version of the block vertices
this->pts_global = new stg_point_int_t[pt_count];
this->pts_global_pixels = new stg_point_int_t[pt_count];
this->global_vertices = new stg_vertex_t[2*pt_count+2];

this->zmin = zmin;
this->zmax = zmax;
this->color = color;
Expand All @@ -36,13 +38,27 @@ StgBlock::StgBlock( StgModel* mod,
// flag these as unset until StgBlock::Map() is called.
this->global_zmin = -1;
this->global_zmax = -1;

this->edge_indices = new GLubyte[ 6 * pt_count ];
for( int i=0; i<pt_count; i++ )
{
this->edge_indices[6*i] = 2*i;
this->edge_indices[6*i+1] = 2*i+1;
this->edge_indices[6*i+2] = 2*i;
this->edge_indices[6*i+3] = 2*i+2;
this->edge_indices[6*i+4] = 2*i+1;
this->edge_indices[6*i+5] = 2*i+3;
}

}

StgBlock::~StgBlock()
{
this->UnMap();
g_free( pts );
g_array_free( rendered_points, TRUE );

delete[] edge_indices;
}

void Stg::stg_block_list_destroy( GList* list )
Expand All @@ -57,18 +73,16 @@ void Stg::stg_block_list_destroy( GList* list )
void StgBlock::DrawTop()
{
// draw a top that fits over the side strip
glBegin(GL_POLYGON);

for( unsigned int p=0; p<pt_count; p++ )
glVertex3f( pts[p].x, pts[p].y, zmax );

glEnd();
glPushMatrix();
glTranslatef( 0,0,zmax);
glVertexPointer( 2, GL_DOUBLE, 0, pts );
glDrawArrays( GL_POLYGON, 0, pt_count );
glPopMatrix();
}

void StgBlock::DrawSides()
{
// construct a strip that wraps around the polygon

// construct a strip that wraps around the polygon
glBegin(GL_QUAD_STRIP);
for( unsigned int p=0; p<pt_count; p++)
{
Expand All @@ -91,6 +105,7 @@ void StgBlock::DrawFootPrint()
glEnd();
}


void StgBlock::Draw()
{
// draw filled color polygons
Expand Down Expand Up @@ -119,6 +134,45 @@ void StgBlock::Draw()
PopColor();
}

void StgBlock::DrawGlobal()
{
// draw filled color polygons
stg_color_t color = Color();

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL );
PushColor( color );
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0, 1.0);

// glColorPointer(3, GL_UNSIGNED_BYTE, 0, colors );

// top - we skip every 2nd vertex
glVertexPointer( 3, GL_FLOAT, 6*sizeof(GLfloat), global_vertices );
glDrawArrays( GL_TRIANGLE_FAN, 0, pt_count );

// sides - we use all vertices
glVertexPointer( 3, GL_FLOAT, 0, global_vertices );
glDrawArrays( GL_TRIANGLE_STRIP, 0, pt_count*2+2 );

glDisable(GL_POLYGON_OFFSET_FILL);

// draw the block outline in a darker version of the same color
double r,g,b,a;
stg_color_unpack( color, &r, &g, &b, &a );
PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE );
glDepthMask(GL_FALSE);

// we use the array of vertices
glDrawElements( GL_LINES, pt_count*6, GL_UNSIGNED_BYTE, edge_indices );

glDepthMask(GL_TRUE);

PopColor();
PopColor();
}

void StgBlock::Draw2D()
{
// draw filled color polygons
Expand Down Expand Up @@ -175,19 +229,35 @@ void StgBlock::Map()
local.z = zmin;

global = mod->LocalToGlobal( local );

pts_global[p].x = (int32_t)floor(global.x*ppm);
pts_global[p].y = (int32_t)floor(global.y*ppm);

// top surface vertex
global_vertices[2*p].x = global.x;
global_vertices[2*p].y = global.y;
global_vertices[2*p].z = global.z + zmax;

// bottom surface vertex
global_vertices[2*p+1].x = global.x;
global_vertices[2*p+1].y = global.y;
global_vertices[2*p+1].z = global.z;

pts_global_pixels[p].x = (int32_t)floor(global.x*ppm);
pts_global_pixels[p].y = (int32_t)floor(global.y*ppm);

PRINT_DEBUG2("loc [%.2f %.2f]",
pts[p].x,
pts[p].y );

PRINT_DEBUG2("glb [%d %d]",
pts_global[p].x,
pts_global[p].y );
pts_global_pixels[p].x,
pts_global_pixels[p].y );
}


// close the strip
// top surface vertex
global_vertices[2*pt_count] = global_vertices[0];
global_vertices[2*pt_count+1] = global_vertices[1];


// store the block's global vertical bounds for inspection by the
// raytracer
global_zmin = global.z;
Expand All @@ -197,7 +267,7 @@ void StgBlock::Map()
render_info.world = mod->GetWorld();
render_info.block = this;

stg_polygon_3d( pts_global, pt_count,
stg_polygon_3d( pts_global_pixels, pt_count,
(stg_line3d_func_t)StgWorld::AddBlockPixel,
(void*)&render_info );

Expand Down
29 changes: 15 additions & 14 deletions libstage/canvas.cc
Expand Up @@ -27,7 +27,7 @@ StgCanvas::StgCanvas( StgWorld* world, int x, int y, int w, int h)
selected_models = NULL;
last_selection = NULL;

startx = starty = 0;
startx = starty = 0;
panx = pany = stheta = sphi = 0.0;
scale = 15.0;
interval = 100; //msec between redraws
Expand Down Expand Up @@ -389,8 +389,13 @@ void StgCanvas::draw()
glRotatef( rtod(sphi), 0,0,1 ); // rotate about z - yaw

// ... to here to get rotation about the center of the window (but broken panning)

// enable vertex arrays
glEnableClientState( GL_VERTEX_ARRAY );
//glEnableClientState( GL_COLOR_ARRAY );
}


// Clear screen to bg color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

Expand Down Expand Up @@ -459,18 +464,18 @@ void StgCanvas::draw()
{
glDisable( GL_DEPTH_TEST );
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL );

for( GList* it=world->children; it; it=it->next )
{
((StgModel*)it->data)->DrawTrailFootprint();
}
glEnable( GL_DEPTH_TEST );
}

if( showflags & STG_SHOW_TRAILS )
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL );

for( GList* it=world->children; it; it=it->next )
{
((StgModel*)it->data)->DrawTrailBlocks();
Expand All @@ -487,15 +492,14 @@ void StgCanvas::draw()
}

if( showflags & STG_SHOW_BLOCKS )
for( GList* it=world->children; it; it=it->next )
{
uint32_t flags = showflags;

if( (stheta == 0) && (sphi == 0) )
flags |= STG_SHOW_BLOCKS_2D;

((StgModel*)it->data)->Draw( flags );
for( GList* it=world->children; it; it=it->next )
((StgModel*)it->data)->DrawBlocks();
}

// draw everything else
for( GList* it=world->children; it; it=it->next )
((StgModel*)it->data)->Draw( showflags );
}

if( world->GetRayList() )
Expand Down Expand Up @@ -532,9 +536,6 @@ void StgCanvas::draw()
glEnable( GL_DEPTH_TEST );
glPopMatrix();
}

// find all the flags
//GList* flags = NULL;
}

void StgCanvas::resize(int X,int Y,int W,int H)
Expand Down
24 changes: 13 additions & 11 deletions libstage/model.cc
Expand Up @@ -878,6 +878,19 @@ void StgModel::DrawTrailArrows()
}


void StgModel::DrawBlocks( )
{
LISTMETHOD( this->children, StgModel*, DrawBlocks );

LISTMETHOD( this->blocks, StgBlock*, DrawGlobal );
}

void StgModel::DrawBlocks( gpointer dummykey,
StgModel* mod, void* dummyarg )
{
mod->DrawBlocks();

}

void StgModel::Draw( uint32_t flags )
{
Expand All @@ -889,17 +902,6 @@ void StgModel::Draw( uint32_t flags )
gl_pose_shift( &this->pose );
gl_pose_shift( &this->geom.pose );

// draw all the blocks
if( flags & STG_SHOW_BLOCKS_2D )
{
LISTMETHOD( this->blocks, StgBlock*, Draw2D );
}
else if( flags & STG_SHOW_BLOCKS )
{
LISTMETHOD( this->blocks, StgBlock*, Draw );
}
//else

//if( this->say_string )
// gl_speech_bubble( 0,0,0, this->say_string );

Expand Down
18 changes: 11 additions & 7 deletions libstage/model_laser.cc
Expand Up @@ -299,6 +299,7 @@ void StgModelLaser::SetSamples( stg_laser_sample_t* samples, uint32_t count)
this->data_dirty = true;
}


void StgModelLaser::DataVisualize( void )
{
if( ! (samples && sample_count) )
Expand All @@ -316,6 +317,10 @@ void StgModelLaser::DataVisualize( void )

PushColor( 0, 0, 1, 0.5 );

glPointSize( 4.0 );

glVertexPointer( 2, GL_FLOAT, 0, pts );

for( unsigned int s=0; s<sample_count; s++ )
{
double ray_angle = (s * (fov / (sample_count-1))) - fov/2.0;
Expand All @@ -325,24 +330,23 @@ void StgModelLaser::DataVisualize( void )
// if the sample is unusually bright, draw a little blob
if( samples[s].reflectance > 0 )
{
glPointSize( 4.0 );
glBegin( GL_POINTS );
glVertex2f( pts[2*s+2], pts[2*s+3] );
glVertex2f( pts[2*s+2], pts[2*s+3] );
glEnd();

// why doesn't this work?
//glDrawArrays( GL_POINTS, 2*s+2, 1 );
}

}
PopColor();


glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 2, GL_FLOAT, 0, pts );


glDepthMask( GL_FALSE );
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );

// draw the filled polygon in transparent blue
PushColor( 0, 0, 1, 0.1 );

glDrawArrays( GL_POLYGON, 0, sample_count+1 );

// draw the beam strike points in black
Expand Down

0 comments on commit c68a660

Please sign in to comment.