Skip to content
This repository has been archived by the owner on Dec 21, 2018. It is now read-only.

Commit

Permalink
Fixed textures, changed teapots to diamonds, draws many cottages
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartlomiej Kozal committed Jun 8, 2010
1 parent df05d0f commit b3ff7fb
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 39 deletions.
3 changes: 1 addition & 2 deletions cottage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
#include "cottage.h"

Cottage::Cottage() {
this->draw();
this->load_textures();
}

void Cottage::draw() {
glPushMatrix();
glScaled(0.8, 0.8, 1.1);
glEnable(GL_TEXTURE_2D);
this->load_textures();
this->draw_roof();
this->draw_walls();
glDisable(GL_TEXTURE_2D);
Expand Down
4 changes: 2 additions & 2 deletions cottage.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class Cottage : private Object {
public:

Cottage();
void draw();

private:

GLuint texture_wall, texture_roof;

void draw();

void load_textures();
void draw_roof();
void draw_walls();
Expand Down
12 changes: 6 additions & 6 deletions cottages.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
CCA60B3611B9152700D0477B /* GLUT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CCA60B3511B9152700D0477B /* GLUT.framework */; };
CCA60B3811B9152700D0477B /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CCA60B3711B9152700D0477B /* OpenGL.framework */; };
CCA60B3E11B9153400D0477B /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CCA60B3D11B9153400D0477B /* main.cpp */; };
CCB5B12C11BEAB7000A23607 /* teapot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CCB5B12B11BEAB7000A23607 /* teapot.cpp */; };
CCB5B31011BED1B700A23607 /* diamond.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CCB5B30F11BED1B700A23607 /* diamond.cpp */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -37,8 +37,8 @@
CCA60B3511B9152700D0477B /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = /System/Library/Frameworks/GLUT.framework; sourceTree = "<absolute>"; };
CCA60B3711B9152700D0477B /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework; sourceTree = "<absolute>"; };
CCA60B3D11B9153400D0477B /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
CCB5B12A11BEAB7000A23607 /* teapot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = teapot.h; sourceTree = "<group>"; };
CCB5B12B11BEAB7000A23607 /* teapot.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = teapot.cpp; sourceTree = "<group>"; };
CCB5B30E11BED1B700A23607 /* diamond.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = diamond.h; sourceTree = "<group>"; };
CCB5B30F11BED1B700A23607 /* diamond.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = diamond.cpp; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -89,8 +89,8 @@
CC49AF8211BCFCF500261BA1 /* ground.cpp */,
CC49AF8411BCFD0C00261BA1 /* cottage.h */,
CC49AF8511BCFD0C00261BA1 /* cottage.cpp */,
CCB5B12A11BEAB7000A23607 /* teapot.h */,
CCB5B12B11BEAB7000A23607 /* teapot.cpp */,
CCB5B30E11BED1B700A23607 /* diamond.h */,
CCB5B30F11BED1B700A23607 /* diamond.cpp */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -163,7 +163,7 @@
CC49AF8011BCFCD800261BA1 /* object.cpp in Sources */,
CC49AF8311BCFCF500261BA1 /* ground.cpp in Sources */,
CC49AF8611BCFD0C00261BA1 /* cottage.cpp in Sources */,
CCB5B12C11BEAB7000A23607 /* teapot.cpp in Sources */,
CCB5B31011BED1B700A23607 /* diamond.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
16 changes: 7 additions & 9 deletions teapot.cpp → diamond.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
/*
* teapot.cpp
* diamonds.cpp
* cottages
*
* Created by Bartlomiej Kozal on 08/06/2010.
* Copyright 2010 Bartlomiej Kozal. All rights reserved.
*
*/

#include "teapot.h"
#include "diamond.h"

Teapot::Teapot() {
this->draw();
}
Diamond::Diamond() {}

void Teapot::draw() {
void Diamond::draw() {
glPushMatrix();

glColor3f(0, 1, 0);
glColor3f(0, 0, 1);
glTranslatef(0, 1, 0);
glutSolidTeapot(1);
glutSolidOctahedron();

glPopMatrix();
glFlush();
Expand Down
13 changes: 5 additions & 8 deletions teapot.h → diamond.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
/*
* teapot.h
* diamonds.h
* cottages
*
* Created by Bartlomiej Kozal on 08/06/2010.
* Copyright 2010 Bartlomiej Kozal. All rights reserved.
*
*/

#ifndef TEAPOT
#define TEAPOT
#ifndef DIAMOND
#define DIAMOND

#include <GLUT/GLUT.h>
#include <OpenGL/OpenGL.h>
#include "object.h"

class Teapot : private Object {
class Diamond : private Object {

public:

Teapot();

private:

Diamond();
void draw();

};
Expand Down
41 changes: 29 additions & 12 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include "ground.h"
#include "cottage.h"
#include "teapot.h"
#include "diamond.h"

float x = 0, y = 1, z = 20;
float lx = 0, ly = 0, lz = -1;
Expand All @@ -24,9 +24,11 @@ float delta_move = 0;

float bred = 0.47, bgreen = 0.75, bblue = 0.76;
float gred = 0.9, ggreen = 0.9, gblue = 0.9;
char object;
char object = 'c';

Ground *ground;
Cottage *cottage;
Diamond *diamond;

// camera
void orientation(float angle) {
Expand Down Expand Up @@ -59,9 +61,22 @@ void draw() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

ground->draw();
for (int i = -3; i < 3; i++) {
for (int j = -3; j < 3; j++) {
glPushMatrix();
glTranslatef(i * 5, 0, j * 5);
switch (object) {
case 'c':
cottage->draw();
break;
case 'd':
diamond->draw();
break;
}
glPopMatrix();
}
}

Cottage *c = new Cottage();
delete c;
glutSwapBuffers();
}
void reshape(int width, int height) {
Expand Down Expand Up @@ -164,12 +179,16 @@ void change_background_color(int option) {
}
void change_shape (int option) {
switch (option) {
case 1 : object = 'c';
case 1:
object = 'c';
break;
case 2 : object = 't';
case 2:
object = 'd';
break;
}
}

// inits - menu, objects, lights
void init_menu() {
int submenu1 = glutCreateMenu(change_ground_color);
int submenu2 = glutCreateMenu(change_background_color);
Expand All @@ -187,7 +206,7 @@ void init_menu() {
glutAddMenuEntry("Reset", 4);
glutSetMenu(submenu3);
glutAddMenuEntry("Cottage", 1);
glutAddMenuEntry("Teapot", 2);
glutAddMenuEntry("Diamonds", 2);
glutCreateMenu(change_ground_color);
glutCreateMenu(change_background_color);
glutCreateMenu(change_shape);
Expand All @@ -197,13 +216,11 @@ void init_menu() {

glutAttachMenu(GLUT_RIGHT_BUTTON);
}

// objects
void init_objects() {
ground = new Ground(gred, ggreen, gblue);
cottage = new Cottage();
diamond = new Diamond();
}

// lights
void init_lights() {
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
Expand All @@ -221,7 +238,7 @@ int main(int argc, char *argv[]) {

init_menu();
init_objects();
// init_lights();
//init_lights();

glutReshapeFunc(reshape);
glutDisplayFunc(draw);
Expand Down

0 comments on commit b3ff7fb

Please sign in to comment.