PDA

View Full Version : Why my code is so big ?



09-03-2004, 08:23 PM
I want to ask why my code is so big .
When I compile it ,it has 168 kb .
Here is the source code.
:confused:
#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();

}

MatthewL
09-03-2004, 10:46 PM
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! :p

lgrosshennig
09-04-2004, 04:35 AM
@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 ;)