Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Why my code is so big ?

  1. #1
    Guest

    Why my code is so big ?

    I want to ask why my code is so big .
    When I compile it ,it has 168 kb .
    Here is the source code.

    #include <windows.h>
    #include <GL/gl.h>
    #include <GL/glut.h>

    #pragma comment(linker,"/entry:\"mainCRTStartup\"")

    void init(void)
    {
    glEnable( GL_DEPTH_TEST );

    glDepthFunc( GL_LESS );

    glClearColor( 0.0, 0.0, 0.0, 0.0 );

    glClearDepth( 1 );

    glShadeModel( GL_SMOOTH );
    }

    void display(void)
    {
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );

    glLoadIdentity();

    glRotatef( 45.0, 1.0, 1.0, 1.0 );

    glBegin( GL_QUADS );
    // front
    glColor3f( 1.0, 0.0, 0.0 );

    glVertex3f( 1.0, 1.0, 1.0 );
    glVertex3f(-1.0, 1.0, 1.0 );
    glVertex3f(-1.0,-1.0, 1.0 );
    glVertex3f( 1.0,-1.0, 1.0 );
    // back
    glVertex3f(-1.0, 1.0,-1.0 );
    glVertex3f( 1.0, 1.0,-1.0 );
    glVertex3f( 1.0,-1.0,-1.0 );
    glVertex3f(-1.0,-1.0,-1.0 );
    // left
    glColor3f( 0.0, 1.0, 0.0 );

    glVertex3f(-1.0, 1.0, 1.0 );
    glVertex3f(-1.0, 1.0,-1.0 );
    glVertex3f(-1.0,-1.0,-1.0 );
    glVertex3f(-1.0,-1.0, 1.0 );
    // right
    glVertex3f( 1.0, 1.0,-1.0 );
    glVertex3f( 1.0, 1.0, 1.0 );
    glVertex3f( 1.0,-1.0, 1.0 );
    glVertex3f( 1.0,-1.0,-1.0 );
    // top
    glColor3f( 0.0, 0.0, 1.0 );

    glVertex3f( 1.0, 1.0,-1.0 );
    glVertex3f(-1.0, 1.0,-1.0 );
    glVertex3f(-1.0, 1.0, 1.0 );
    glVertex3f( 1.0, 1.0, 1.0 );
    // bottom
    glVertex3f( 1.0,-1.0, 1.0 );
    glVertex3f(-1.0,-1.0, 1.0 );
    glVertex3f(-1.0,-1.0,-1.0 );
    glVertex3f( 1.0,-1.0,-1.0 );

    glEnd();

    glutSwapBuffers();
    glutPostRedisplay();
    }

    void reshape( int width,int height )
    {
    glMatrixMode( GL_PROJECTION );

    glLoadIdentity();

    gluPerspective( 45.0, (GLdouble)width/(GLdouble)height, 1.0, 50.0 );

    glTranslatef( 0.0, 0.0, -10.0 );

    glViewport( 0, 0, width, height);

    glMatrixMode( GL_MODELVIEW );
    }

    void main( void )
    {
    glutInitWindowSize( 600, 512 );

    glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );

    glutCreateWindow( "OpenGL" );

    glutDisplayFunc( display );

    glutReshapeFunc( reshape );

    init();

    glutMainLoop();

    }

  2. #2
    Junior Member Newbie
    Join Date
    Jun 2004
    Posts
    24

    Re: Why my code is so big ?

    Hi!

    Well, there can be many reasons.
    Firstly, which compiler you use is very important. Visual C++ is knwn to be a bad choice for size-dependant programs such as 64K demos.
    (try LCCWin!)

    Your current buildmode could be set to 'debug' instead of 'release'. Check to see if that's the case.If you ae using VC++, you can also choose to favor size above speed, but that doesn't work that well for -100K projects.

    And lastly, check to see what default libraries your project links to. MSVC++ is known to link to a lot of libraries that add some size even if you don't use any functions in them.

    In short, if you want some good small code, try LCCWin. It should create a 5K executable out of your code.

    Bye!

  3. #3
    Junior Member Regular Contributor
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    200

    Re: Why my code is so big ?

    @keviwin

    I just took your code and compiled it using MSVC7:

    Codesize debug build : 120kb
    Codesize relase build : 30kb

    Since I dont think the MSVC6 is much worse, you may try a release build without all the debug infos

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •