i am very new to openGL. i’m trying to follow codes in the textbook to draw a parameterized house. but the program does not success. i guess it’s because something i dont declare, but i dunno how, and dunno where. this is my whole codes, can someone help me on this?
#include <GL\glut.h>
//------------------------------------------------------
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0); // set the background to white
glColor3f(0.0f, 0.0f, 0.0f); // set the drawing color to black
well, i modified the code (below) so that it actually compiles/runs. it doesn’t draw a house, but it does display something. if you want to draw a house, you need to modify the parameterizedHouse function so that the vertices actually specify the points which would define a house’s outline. oh, and the numbers i pass into the house function are totally random right now – i just wanted to see if it would draw anything.
#include <GL\glut.h>
typedef struct {
int x;
int y;
} point;
//------------------------------------------------------
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0); // set the background to white
glColor3f(0.0f, 0.0f, 0.0f); // set the drawing color to black
i got another problem. i have drawn the shell of the house and add a door, but it draws a house that turns upside down. may i know what’s the real problem?
Wutup Fuyu…Here is my parametrized house code you can work with.
This function uses a GLintPoint object and I have included implementation of this class below. Its very short and succinct as you can see.
Good Luck Hombre
//GLintPoint Class
class GLintPoint
{
public:
int x,y;
GLintPoint(int a, int b)
{x=a,y=b;}
};
void parametrizedHouse(GLintPoint peak,GLint width,GLint height)
{
GLint ChWidth = width/50;
GLint DoorWidth = width/10;
GLint DoorHeight= height/10;
GLint WindowW= width/10;
GLint WindowH= height/10;
//Skeleton of the House
glBegin(GL_LINE_LOOP);
glVertex2i((GLint)peak.x,peak.y);
GLintPoint secondPoint((GLint)peak.x+width/2, (GLint)peak.y-3*height/8);
glVertex2i(secondPoint.x,secondPoint.y);
GLintPoint thirdPoint((GLint)peak.x+width/2, (GLint)peak.y-height);
glVertex2i(thirdPoint.x,thirdPoint.y);
GLintPoint fourthPoint((GLint)peak.x-width/2,(GLint)peak.y-height);
glVertex2i(fourthPoint.x,fourthPoint.y);
GLintPoint fifthPoint((GLint)peak.x-width/2,(GLint)peak.y-3*height/8);
glVertex2i(fifthPoint.x,fifthPoint.y);
glEnd();
//Chimeney of the house
glBegin(GL_LINE_STRIP);
glVertex2i(((peak.x+fifthPoint.x)/2)-ChWidth, ((peak.y+fifthPoint.y)/2)-ChWidth);
glVertex2i(((peak.x+fifthPoint.x)/2)-ChWidth,peak.y);
glVertex2i(((peak.x+fifthPoint.x)/2)+ChWidth,peak.y);
glVertex2i(((peak.x+fifthPoint.x)/2)+ChWidth,((peak.y+fifthPoint.y)/2)+ChWidth);
glEnd();
//Door of the House
glBegin(GL_LINE_STRIP);
glVertex2i(((thirdPoint.x+fourthPoint.x)/2)-DoorWidth,fourthPoint.y);
glVertex2i(((thirdPoint.x+fourthPoint.x)/2)-DoorWidth,fifthPoint.y-DoorHeight);
glVertex2i(((thirdPoint.x+fourthPoint.x)/2)+DoorWidth,fifthPoint.y-DoorHeight);
glVertex2i(((thirdPoint.x+fourthPoint.x)/2)+DoorWidth,fourthPoint.y);
glEnd();
//Window of the House
glBegin(GL_LINE_LOOP);
glVertex2i(((thirdPoint.x+((thirdPoint.x+fourthPoint.x)/2)+DoorWidth)/2)-WindowW,fifthPoint.y-DoorHeight);
glVertex2i(((thirdPoint.x+((thirdPoint.x+fourthPoint.x)/2)+DoorWidth)/2)-WindowW,fifthPoint.y-DoorHeight+WindowH);
glVertex2i(((thirdPoint.x+((thirdPoint.x+fourthPoint.x)/2)+DoorWidth)/2)+WindowW,fifthPoint.y-DoorHeight+WindowH);
glVertex2i(((thirdPoint.x+((thirdPoint.x+fourthPoint.x)/2)+DoorWidth)/2)+WindowW,fifthPoint.y-DoorHeight);
glEnd();
glFlush();