X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=scene.c;h=b98621238e7e864cadafa097a1e967c098dd58a0;hb=fddfc54be4d34bca813016b3349597500725d231;hp=002fadc3a7e22505b7a3aa50a9602b6c27109002;hpb=19fa399bf0c4b47f6f23a320627533f0c902bca8;p=atyndall%2Fcits2231.git diff --git a/scene.c b/scene.c index 002fadc..b986212 100644 --- a/scene.c +++ b/scene.c @@ -1,9 +1,7 @@ -// compile this program using: -// gcc -O3 -Wall -std=c99 -o scene scene.c bitmap.c -lglut -// Or, with cygwin: (-mno-cygwin is only so the executable runs from windows) -// gcc -mno-cygwin -O3 -Wall -std=c99 -o scene scene.c bitmap.c -lglut32 -lglu32 -lopengl32 -// Or, use make via the supplied Makefile: (For cygwin, install the package for make) -// make +/** + * CITS2231 Graphics Scene Editor + * @author Ashley Tyndall (20915779) + */ #include #include @@ -105,13 +103,28 @@ const char *objectMenuEntries[NMESH] = { SceneObject sceneObjs[MAXOBJECTS]; // An array with details of the objects in a scene int nObjects=0; // How many objects there are in the scene currently. +// Directories containing models +char *dirDefault1 = "models-textures"; +char *dirDefault2 = "/cslinux/examples/CITS2231/project-files/models-textures"; + +char dataDir[200]; // Stores the directory name for the meshes and textures. + +/** + * Prints out error message when file cannot be read + * @param fileName Name of file that could not be read + */ void fileErr(char* fileName) { printf("Error reading file: %s\n", fileName); printf("If not in the CSSE labs, you will need to include the directory containing\n"); printf("the models on the command line, or put it in the same folder as the exectutable."); - exit(1); + exit(EXIT_FAILURE); } +/** + * Reads .bmp texture files and converts them to a texture object + * @param fileName .bmp texture file + * @return texture object + */ texture* loadTexture(char *fileName) { texture* t = malloc(sizeof (texture)); BITMAPINFO *info; @@ -123,8 +136,11 @@ texture* loadTexture(char *fileName) { return t; } -// The following works for the supplied .x files -// but probably not for .x files from other sources. +/** + * Reads .x files and converts them to a mesh object + * @param fileName .x mesh file + * @return mesh object + */ mesh* loadMesh(char* fileName) { mesh* m = malloc(sizeof (mesh)); FILE* fp = fopen(fileName, "r"); @@ -167,11 +183,13 @@ mesh* loadMesh(char* fileName) { return m; } -char dataDir[200]; // Stores the directory name for the meshes and textures. - -// getMesh(i) loads mesh[i] if it isn't already loaded. -// You must call getMesh(i) at least once before using mesh[i]. // [You may want to add to this function.] +/** + * Loads mesh[i] if it isn't already loaded. + * You must call getMesh(i) at least once before using mesh[i]. + * + * @param i Mesh ID + */ void getMesh(int i) { // getMesh(i) loads mesh[i] if it isn't already loaded. char fileName[220]; if(i>=NMESH || i<0) { @@ -184,13 +202,21 @@ void getMesh(int i) { // getMesh(i) loads mesh[i] if it isn't already loaded. meshes[i] = loadMesh(fileName); } -// getTexture(i) loads texture i if it isn't already loaded. -// After calling getTexture(i), you can make texture i the current texture using -// glBindTexture(GL_TEXTURE_2D, i); (Use i=0 to return to the default plain texture.) -// You can then scale the texture via: (See the textbook, section 8.8.3.) -// glMatrixMode(GL_TEXTURE); -// You must call getTexture(i) at least once before using texture i. -void getTexture(int i) { // getTexture(i) loads texture i if it isn't already loaded. +/** + * Loads texture i if it isn't already loaded + * + * After calling getTexture(i), you can make texture i the current texture using + * glBindTexture(GL_TEXTURE_2D, i); + * Use i=0 to return to the default plain texture. + * + * You can then scale the texture via: + * glMatrixMode(GL_TEXTURE); + * See the textbook, section 8.8.3. + * + * You must call getTexture(i) at least once before using texture i. + * @param i Texture ID + */ +void getTexture(int i) { char fileName[220]; if(i<1 || i>NTEXTURE) { printf("Error in getTexture - wrong texture number"); @@ -216,6 +242,10 @@ void getTexture(int i) { // getTexture(i) loads texture i if it isn't already lo glBindTexture(GL_TEXTURE_2D, 0); // Back to default texture } +/** + * Event hander for main menu events + * @param id ID of menu item selected + */ void processMainEvents(int id) { switch (id) { case ROTATE_MOVE_CAMERA: @@ -236,10 +266,10 @@ void processMainEvents(int id) { } } -void processObjectEvents(int id) { - -} - +/** + * Event hander for materials menu events + * @param id ID of menu item selected + */ void processMaterialEvents(int id) { switch (id) { case MATERIAL_ALL_RGB: @@ -277,14 +307,10 @@ void processMaterialEvents(int id) { } } -void processTextureEvents(int id) { - -} - -void processGTextureEvents(int id) { - -} - +/** + * Event hander for light menu events + * @param id ID of menu item selected + */ void processLightEvents(int id) { switch (id) { case LIGHT_MOVE_LIGHT_1: @@ -306,6 +332,30 @@ void processLightEvents(int id) { } } +/** + * Event hander for object menu events + * @param id ID of object selected + */ +void processObjectEvents(int id) { + +} + +/** + * Event hander for texture menu events + * @param id ID of texutre selected + */ +void processTextureEvents(int id) { + +} + +/** + * Event hander for ground texture menu events + * @param id ID of ground texture selected + */ +void processGTextureEvents(int id) { + +} + /** * Rounds up numbers, from http://stackoverflow.com/questions/3407012/c-rounding-up-to-the-nearest-multiple-of-a-number * @param numToRound Number to round @@ -361,6 +411,9 @@ int makeSubmenuFromArray( const char *menuEntries[], unsigned int menuEntriesSiz return mainMenu; } +/** + * Creates menu for program + */ void makeMenu() { // Construct material menu int materialMenu = glutCreateMenu(processMaterialEvents); @@ -390,29 +443,66 @@ void makeMenu() { int gTextureMenu = makeSubmenuFromArray( textureMenuEntries, textureMenuEntriesSize, processGTextureEvents ); // Construct main menu - int mainMenu = glutCreateMenu(processMainEvents); - glutAddMenuEntry("Rotate/Move Camera", ROTATE_MOVE_CAMERA); - glutAddSubMenu("Add object", objectMenu); - glutAddMenuEntry("Position/Scale", POSITION_SCALE); - glutAddMenuEntry("Rotation/Texture Scale", ROTATION_TEXTURE_SCALE); - glutAddSubMenu("Material", materialMenu); - glutAddSubMenu("Texture", textureMenu); - glutAddSubMenu("Ground texture", gTextureMenu); - glutAddSubMenu("Lights", lightMenu); + glutCreateMenu(processMainEvents); + //glutAddMenuEntry("Rotate/Move Camera", ROTATE_MOVE_CAMERA); + //glutAddSubMenu("Add object", objectMenu); + //glutAddMenuEntry("Position/Scale", POSITION_SCALE); + //glutAddMenuEntry("Rotation/Texture Scale", ROTATION_TEXTURE_SCALE); + //glutAddSubMenu("Material", materialMenu); + //glutAddSubMenu("Texture", textureMenu); + //glutAddSubMenu("Ground texture", gTextureMenu); + //glutAddSubMenu("Lights", lightMenu); glutAddMenuEntry("Exit", EXIT); // Bind to right mouse button glutAttachMenu(GLUT_RIGHT_BUTTON); } +/** + * Called when window is resized + * @param width New width + * @param height New height + */ +void windowReshape(int width, int height) { + glViewport(0, 0, (GLsizei)width, (GLsizei)height); + printf("Width: %d, height: %d\n", width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60, (GLfloat)width / (GLfloat)height, 0.1, 1000.0); + glMatrixMode(GL_MODELVIEW); +} + +/** + * Called when mouse event occurs + * @param btn Mouse button + * @param state State of mouse button + * @param x Mouse x position + * @param y Mouse y position + */ +void mouse(int btn, int state, int x, int y) { + +} + +/** + * Display function + */ void display() { - // You probably want to change both of the following. - glClear(GL_COLOR_BUFFER_BIT); - glFlush(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glLoadIdentity(); + + glTranslatef(0.0f,0.0f,-3.0f); // Move Left 1.5 Units And Into The Screen 6.0 + + glutSolidTeapot(1); + + glutSwapBuffers(); } -char *dirDefault1 = "models-textures"; -char *dirDefault2 = "/cslinux/examples/CITS2231/project-files/models-textures"; +/** + * Main function + * @param argc Number of arguments + * @param argv Array of arguments + * @return Program exit code + */ int main(int argc, char **argv) { if(argc>1) @@ -426,12 +516,23 @@ int main(int argc, char **argv) { for(int i=0; i