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

Commit

Permalink
Moved cottage drawing methods to cottage class
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartlomiej Kozal committed Jun 7, 2010
1 parent 7288ee1 commit c3f2642
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 113 deletions.
122 changes: 121 additions & 1 deletion cottage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,138 @@
*
*/

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

class cottage {

public:

cottages() {
cottage() {
this->draw();
}

~cottage() {}

GLuint texture_wall, texture_roof;

private:

GLuint loadTexture(Image* image) {
GLuint textureId;
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image->width, image->height,
0, GL_RGB, GL_UNSIGNED_BYTE, image->pixels);
return textureId;
}

void draw() {
glPushMatrix();
glScaled(0.8, 0.8, 1.1);
this->load_textures();
this->draw_roof();
this->draw_walls();
glPopMatrix();
glFlush();
}

void load_textures() {
Image *texture1 = loadBMP("wall.bmp");
this->texture_wall = this->loadTexture(texture1);
delete texture1;

Image *texture2 = loadBMP("roof.bmp");
this->texture_roof = this->loadTexture(texture2);
delete texture2;
}

void draw_roof() {
glBindTexture(GL_TEXTURE_2D, texture_roof);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glColor3f(1, 1, 1);

glBegin(GL_TRIANGLES);

glTexCoord2f(0, 0);
glVertex3f(-1, 1, 1);
glTexCoord2f(5, 0);
glVertex3f(1, 1, 1);
glTexCoord2f(2.5, 5);
glVertex3f(0, 2, 0);

glTexCoord2f(0, 0);
glVertex3f(1, 1, 1);
glTexCoord2f(5, 0);
glVertex3f(1, 1, -1);
glTexCoord2f(2.5, 5);
glVertex3f(0, 2, 0);

glTexCoord2f(0, 0);
glVertex3f(1, 1, -1);
glTexCoord2f(5, 0);
glVertex3f(-1, 1, -1);
glTexCoord2f(2.5, 5);
glVertex3f(0, 2, 0);

glTexCoord2f(0, 0);
glVertex3f(-1, 1, -1);
glTexCoord2f(5, 0);
glVertex3f(-1, 1, 1);
glTexCoord2f(2.5, 5);
glVertex3f(0, 2, 0);

glEnd();
}

void draw_walls() {

glBindTexture(GL_TEXTURE_2D, texture_wall);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glColor3f(1, 1, 1);

glBegin(GL_QUADS);

glTexCoord2f(0, 0);
glVertex3f(-1, 0, 1);
glTexCoord2f(1, 0);
glVertex3f(1, 0, 1);
glTexCoord2f(1, 1);
glVertex3f(1, 1, 1);
glTexCoord2f(0, 1);
glVertex3f(-1, 1, 1);

glTexCoord2f(0, 0);
glVertex3f(1, 0, 1);
glTexCoord2f(1, 0);
glVertex3f(1, 0, -1);
glTexCoord2f(1, 1);
glVertex3f(1, 1, -1);
glTexCoord2f(0, 1);
glVertex3f(1, 1, 1);

glTexCoord2f(0, 0);
glVertex3f(1, 0, -1);
glTexCoord2f(1, 0);
glVertex3f(-1, 0, -1);
glTexCoord2f(1, 1);
glVertex3f(-1, 1, -1);
glTexCoord2f(0, 1);
glVertex3f(1, 1, -1);

glTexCoord2f(0, 0);
glVertex3f(-1, 0, 1);
glTexCoord2f(1, 0);
glVertex3f(-1, 0, -1);
glTexCoord2f(1, 1);
glVertex3f(-1, 1, -1);
glTexCoord2f(0, 1);
glVertex3f(-1, 1, 1);

glEnd();
}

};
129 changes: 17 additions & 112 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
*
*/

// Load libs
#include <GLUT/GLUT.h>
#include <OpenGL/OpenGL.h>
#include <math.h>
#include <stdlib.h>
#include "imageloader.h"

// Load classes

#include "cottage.cpp"

float x = 0, y = 1, z = 20;
float lx = 0, ly = 0, lz = -1;
Expand All @@ -26,7 +24,7 @@ float background[] = {0.47, 0.75, 0.76, 0};
float ground[] = {0.9, 0.9, 0.9};
char object = 'c';

GLuint _texture_ground, _texture_wall, _texture_roof;
GLuint _texture_ground;

// textures

Expand Down Expand Up @@ -61,93 +59,6 @@ void move(float i) {

// draw

void cottage() {

glBindTexture(GL_TEXTURE_2D, _texture_wall);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glPushMatrix();
glScaled(0.8, 0.8, 1.1);
// walls
glColor3f(1, 1, 1);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex3f(-1, 0, 1);
glTexCoord2f(1, 0);
glVertex3f(1, 0, 1);
glTexCoord2f(1, 1);
glVertex3f(1, 1, 1);
glTexCoord2f(0, 1);
glVertex3f(-1, 1, 1);

glTexCoord2f(0, 0);
glVertex3f(1, 0, 1);
glTexCoord2f(1, 0);
glVertex3f(1, 0, -1);
glTexCoord2f(1, 1);
glVertex3f(1, 1, -1);
glTexCoord2f(0, 1);
glVertex3f(1, 1, 1);

glTexCoord2f(0, 0);
glVertex3f(1, 0, -1);
glTexCoord2f(1, 0);
glVertex3f(-1, 0, -1);
glTexCoord2f(1, 1);
glVertex3f(-1, 1, -1);
glTexCoord2f(0, 1);
glVertex3f(1, 1, -1);

glTexCoord2f(0, 0);
glVertex3f(-1, 0, 1);
glTexCoord2f(1, 0);
glVertex3f(-1, 0, -1);
glTexCoord2f(1, 1);
glVertex3f(-1, 1, -1);
glTexCoord2f(0, 1);
glVertex3f(-1, 1, 1);
glEnd();
// roof

glBindTexture(GL_TEXTURE_2D, _texture_roof);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glColor3f(1, 1, 1);
glBegin(GL_TRIANGLES);
glTexCoord2f(0, 0);
glVertex3f(-1, 1, 1);
glTexCoord2f(5, 0);
glVertex3f(1, 1, 1);
glTexCoord2f(2.5, 5);
glVertex3f(0, 2, 0);

glTexCoord2f(0, 0);
glVertex3f(1, 1, 1);
glTexCoord2f(5, 0);
glVertex3f(1, 1, -1);
glTexCoord2f(2.5, 5);
glVertex3f(0, 2, 0);

glTexCoord2f(0, 0);
glVertex3f(1, 1, -1);
glTexCoord2f(5, 0);
glVertex3f(-1, 1, -1);
glTexCoord2f(2.5, 5);
glVertex3f(0, 2, 0);

glTexCoord2f(0, 0);
glVertex3f(-1, 1, -1);
glTexCoord2f(5, 0);
glVertex3f(-1, 1, 1);
glTexCoord2f(2.5, 5);
glVertex3f(0, 2, 0);
glEnd();
glPopMatrix();
glFlush();
}

void teapot() {
glPushMatrix();
glColor3f(0, 1, 0);
Expand All @@ -174,14 +85,6 @@ void draw() {
_texture_ground = loadTexture(picture);
delete picture;

Image *picture2 = loadBMP("wall.bmp");
_texture_wall = loadTexture(picture2);
delete picture2;

Image *picture3 = loadBMP("roof.bmp");
_texture_roof = loadTexture(picture3);
delete picture3;

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _texture_ground);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
Expand All @@ -200,19 +103,21 @@ void draw() {
glEnd();

// cottages
for (int i = -2; i < 2; i++) {
for (int j = -2; j < 2; j++) {
glPushMatrix();
glTranslatef(i * 5, 0, j * 5);
switch (object) {
case 'c' : cottage();
break;
case 't' : teapot();
break;
}
glPopMatrix();
}
}
// for (int i = -1; i < 1; i++) {
// for (int j = -1; j < 1; j++) {
// glPushMatrix();
// glTranslatef(i * 5, 0, j * 5);
// switch (object) {
// case 'c' :
cottage *c = new cottage();
delete c;
// break;
// case 't' : teapot();
// break;
// }
// glPopMatrix();
// }
// }
glDisable(GL_TEXTURE_2D);
glutSwapBuffers();
}
Expand Down

0 comments on commit c3f2642

Please sign in to comment.