bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

back_push error (linux)???? help


From: zoe
Subject: back_push error (linux)???? help
Date: 20 May 2002 09:52:59 -0700

I try to compile the following program using gcc. 
But I got the following a lot of errors, all are:
"request for member 'push_back' in 'd_message', which is of
non-aggregate type 'int' "...

Is #include <vector> correct??? any different between that in
linux????

~~~~~~~~~~~~~~~~~~~~~~~~`code`~~~~~~~~~~~~~~~~~~~~~~~~~~`
#include <GL/glut.h>

#include <vector>
using namespace std;

#include "f00TexturedFont.h"
#include "f00TimeBase.h"
#include "f00StarField.h"


// Global variables.  Terrible, but everpresent in these small demos. 
Alas.
f00TexturedFont         d_statusFont;
f00TexturedFont         d_blockFont;
int                     d_screenW = 1;
int                     d_screenH = 1;
vector< string >        d_message;
f00TimeBase             d_timebase( 1000 );
f00StarField            d_starfield( 2500, true, false );


void draw3DStuff( float elapsedSeconds )
{
        // Genericus starfieldus.
        f00Quat viewDir;
        d_starfield.render( viewDir, elapsedSeconds );

        // Draw some demonstrative 3D text.
        glPushMatrix();

                //
                // The following is purely a joke hack.
                // Not *real* code.
                // ...
                // Really!
                //

                // Start out down-shifted and rotated to 'lie flat'.
                glTranslatef( 0.0f, -25.0f, 0.0f );
                glRotatef( -90.0f, 1.0f, 0.0f, 0.0f );

                // Cheap fog.  You REALLY shouldn't call this stuff per frame 
(just
the glEnable),
                // but since this is a hack, I left the code together.  It 
SHOULD go
in init().
                glFogf( GL_FOG_MODE, GL_LINEAR );
                glFogf( GL_FOG_START, 200.0f );
                glFogf( GL_FOG_END, 600.0f );
                glFogfv( GL_FOG_COLOR, f00RGBA_f( 0.0f, 0.0f, 0.0f, 0.0f
).getArray() );
                glEnable( GL_FOG );

                // Scrolling text hack!
                static GLfloat scrollPos = 80.0f;                       // Just 
below the bottom of the
screen.
                scrollPos += elapsedSeconds * 30.0f;            // Scroll at 30 
'units' per
second.

                // Another lame hack: this time to make the first line appear 
bigger
(and white).
                d_blockFont.setScaling( 20.0f, -80.0f );
                d_blockFont.setTextColor( f00RGBA_f( 1.0f, 1.0f, 1.0f, 1.0f ) );

                // Walk the message's strings.
                vector< string >::const_iterator i = d_message.begin();
                GLfloat yPos = scrollPos;
                while( i != d_message.end() )
                {
                        const char* pString = (*i).c_str();
                        d_blockFont.drawString( pString, 
-d_blockFont.getTextExtent(
pString ).d_x / 2.0f, yPos );
                        yPos -= 50.0f;
                        i++;

                        // Another lame hack: See?  Told you it was lame.  :-)
                        d_blockFont.setScaling( 10.0f, -40.0f );
                        d_blockFont.setTextColor( f00RGBA_f( 1.0f, 0.8f, 0.0f, 
1.0f ) );
                }

                // What it says.
                glDisable( GL_FOG );

                //
                // End hack.  (End hack?  NEVER!)
                //


        glPopMatrix();
}


void draw2DStuff( float elapsedSeconds )
{
        //
        // Ye Olde FPS Counter Hack.
        //

        // Cache the last N elapsed-intervals.  Let's assume hardware
accelleration: default to a large value.
        // Increase N to get a smoother reading, decrease for more
responsiveness.
        static vector< float > d_elapsedSeconds;
        d_elapsedSeconds.push_back( elapsedSeconds );
        if( d_elapsedSeconds.size() > 60 )
                d_elapsedSeconds.erase( d_elapsedSeconds.begin() );

        // Inter-call storage.
        static float lastFPS = 0.0f;
        static float lastUpdateAt = 0.0f;

        // Are we ready for an update (has a whole second elapsed)?
        float currentTime = d_timebase.getCurrentFrameBase() +
d_timebase.getCurrentFrameOffset();
        if( currentTime >= lastUpdateAt + 1.0f  )
        {
                // Divide the number of frames (N) by the sum of the intervals 
to
get frames per second....
                float deltaSeconds = 0.0f;
                vector< float >::const_iterator i = d_elapsedSeconds.begin();
                while( i != d_elapsedSeconds.end() )
                {
                        deltaSeconds += (*i);
                        i++;
                }
                if( deltaSeconds <= 0.0f )
                        deltaSeconds = 1.0f;

                // Store for next time....
                lastUpdateAt = currentTime;
                lastFPS = (float)d_elapsedSeconds.size() / deltaSeconds;
        }

        // The interesting part.
        char statusBuffer[ 1000 ];
        sprintf( statusBuffer, "FPS: %0.f", lastFPS );
        d_statusFont.drawString( statusBuffer, 10, 10 );
}


void displayFunc()
{
        // When are we?
        d_timebase.updateFrameValues();
        float elapsedSeconds = d_timebase.getLastFrameDelta();

        // Reset the scene.
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        glEnable( GL_DEPTH_TEST );
        glLoadIdentity();

        // Draw 3D stuff here.
        draw3DStuff( elapsedSeconds );

        // Switch to 'console/hud' mode.
        glDisable( GL_DEPTH_TEST );
        glMatrixMode( GL_PROJECTION );
        glPushMatrix();
        glLoadIdentity();
        glOrtho( 0.0f, d_screenW, d_screenH, 0.0f, -1.0f, 1.0f );
        glMatrixMode( GL_MODELVIEW );
        glPushMatrix();
        glLoadIdentity();

        // Draw 2D stuff here.
        draw2DStuff( elapsedSeconds );

        // Restore.
        glMatrixMode( GL_PROJECTION );
        glPopMatrix();
        glMatrixMode( GL_MODELVIEW );
        glPopMatrix();
        glEnable( GL_DEPTH_TEST );

        // Done!
        glutSwapBuffers();
        glutPostRedisplay();
}


void
reshapeFunc( int w, int h )
{
        glViewport( 0, 0, w, h );
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        if( h < 1 )
                h = 1;
        gluPerspective( 30.0, (double)w / (double)h, 1.0, 1000.0 );
        glMatrixMode( GL_MODELVIEW );
        d_screenW = w;
        d_screenH = h;
}


void
keyboardFunc( unsigned char key, int x, int y )
{
        // ESC key?
        if( key == 27 )
        {
                glutDestroyWindow( glutGetWindow() );
                exit( 0 );
        }
}


void init()
{
        // Load and setup a non-proportional ("typewriter") font....
        loadNPFFile( d_statusFont, "fixedsys.npf", GL_ALPHA );
        d_statusFont.uploadTexture();
        d_statusFont.setTextColor( f00RGBA_f( 1.0f, 1.0f, 1.0f, 0.5f ) );       
        //
Note the low alpha.  This allows the text to 'float' over the
background....

        // Load and setup a proportional font....
        loadPFFile( d_blockFont, "futura_21_smoothed.pf", GL_ALPHA );
        d_blockFont.uploadTexture();
        d_blockFont.setTextColor( f00RGBA_f( 1.0f, 0.8f, 0.0f, 1.0f ) );
        d_blockFont.usePixelUnits( false );

        // GLUT callbacks.
        glutReshapeFunc( reshapeFunc );
        glutDisplayFunc( displayFunc );
        glutKeyboardFunc( keyboardFunc );
        glClearColor( 0.0, 0.0, 0.0, 0.0 );

        // Heh, heh, heh....
        d_message.push_back( "#OPENGL" );
        d_message.push_back( "" );
        d_message.push_back( "Episode 3.14: A New Demo" );
        d_message.push_back( "" );
        d_message.push_back( "It is a dark time" );
        d_message.push_back( "for #OpenGL." );
        d_message.push_back( "Imperial forces," );
        d_message.push_back( "striking from a" );
        d_message.push_back( "secret channel have" );
        d_message.push_back( "stolen the plans" );
        d_message.push_back( "for ... aw, who" );
        d_message.push_back( "cares?  It's just" );
        d_message.push_back( "a demo.  =]" );
        d_message.push_back( "" );
        d_message.push_back( "" );
        d_message.push_back( "" );
        d_message.push_back( "GO AWAY!" );
        d_message.push_back( "" );
        d_message.push_back( "" );
        d_message.push_back( "(end of text)" );
}


void
main( int argc, char* argv[] )
{
        glutInit( &argc, argv );
        glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB );
        glutInitWindowSize( 640, 480 );
        glutCreateWindow( "f00TexturedFont - A demonstration of textured
text" );
        init();
        glutMainLoop();
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]