PDA

View Full Version : Code Help



hoganh
11-24-2003, 01:13 PM
Hi,Im trying to design a swing and if all possible in 3d.My problem at the moment is im getting an error message saying
error C2660: 'glOrtho' : function does not take 5 parameters.
Could somebody tell me what this means.
Also im not able to see anything on the screen with the code.I be very gratefull if somebody could have a look at the code and point me in the right direction.Thanks


#include "gl/glut.h"
#include "stdlib.h"
#include "stdio.h"
#include "math.h"


void draw(void);
void idle(void);
void key(unsigned char k, int x, int y);
void reshape(int width, int height);
void init_drawing(void);
void instructions(void);

int direction;
float angle=0.0;
float rota=0.0;
float rotb=0.0;
bool pause=false;

int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
glutCreateWindow("TEST3");
init_drawing();
glutReshapeFunc(reshape);
glutKeyboardFunc(key);
glutIdleFunc(idle);
glutDisplayFunc(draw);
glutInitWindowSize(600,600);
glutReshapeWindow(600,600);
glutMainLoop();
return 0;
}

void drawSwing()
{
glColor3f(1.0, 0.0, 1.0);
glLineWidth(5.0);

// Draw the ropes
glBegin(GL_LINES);
glVertex3d(-20, 30, 0);
glVertex3d(-20, -30, 0);
glVertex3d(20, 30, 0);
glVertex3d(20, -30, 0);
glEnd();

glColor3f(0.0, 1.0, 0.0);

// Draw the sides of the seat
glBegin(GL_QUAD_STRIP);
glVertex3d(20, -30, -10);
glVertex3d(20, -33, -10);
glVertex3d(-20, -30, -10);
glVertex3d(-20, -33, -10);
glVertex3d(-20, -30, 10);
glVertex3d(-20, -33, 10);
glVertex3d(20, -30, 10);
glVertex3d(20, -33, 10);
glVertex3d(20, -30, -10);
glVertex3d(20, -33, -10);
glEnd();

glColor3f(0.0, 0.0, 1.0);

// Draw the top and bottom of the seat
glBegin(GL_QUADS);
glVertex3d(-20, -33, -10);
glVertex3d(20, -33, -10);
glVertex3d(20, -33, 10);
glVertex3d(-20, -33, 10);

glVertex3d(-20, -30, -10);
glVertex3d(20, -30, -10);
glVertex3d(20, -30, 10);
glVertex3d(-20, -30, 10);
glEnd();
}

void drawBar()
{
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 0.0);

// Bottom
glVertex3d(-50, 30, -1);
glVertex3d(50, 30, -1);
glVertex3d(50, 30, 1);
glVertex3d(-50, 30, 1);
// Top
glVertex3d(-50, 33, -1);
glVertex3d(50, 33, -1);
glVertex3d(50, 33, 1);
glVertex3d(-50, 33, 1);

glColor3f(1.0, 0.65, 0.0);

// Front
glVertex3d(-50, 33, 1);
glVertex3d(-50, 30, 1);
glVertex3d(50, 30, 1);
glVertex3d(50, 33, 1);
// Back
glVertex3d(50, 33, -1);
glVertex3d(50, 30, -1);
glVertex3d(-50, 30, -1);
glVertex3d(-50, 33, -1);

glColor3f(1.0, 0.0, 0.0);

// Left
glVertex3d(-50, 33, -1);
glVertex3d(-50, 30, -1);
glVertex3d(-50, 30, 1);
glVertex3d(-50, 33, 1);
// Right
glVertex3d(50, 33, 1);
glVertex3d(50, 30, 1);
glVertex3d(50, 30, -1);
glVertex3d(50, 33, -1);
glEnd();



}

void draw(void)
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// Rotate the bar and swing
glRotatef(60.0, 0.0, 1.0, 0.0);

// Draw the bar
drawBar();

// Translate and rotate the swing to make it `swing'
glTranslatef(0.0, 30.0, 0.0);
glRotatef(angle, 1.0, 0.0, 0.0);
glTranslatef(0.0, -30.0, 0.0);

// Draw the swing
drawSwing();


//glPushMatrix();
//glTranslatef(1.4,0.5,-10.0);
// glRotatef(rota,0,0,1);
// drawSquare();

// glTranslatef(0.0,-1.5,0.0);
// glRotatef(rotb,0,0,1);
// glTranslatef(0.0,-1.5,0.0);
// drawSquare();

glFlush();
glutSwapBuffers();

// Make the it swing back or forth depending upon direction
if (direction == 1)
angle++;
else
angle--;

// Change the direction if 40 or -40 is reached
if (angle == -40.0) {
direction = 1;
}
if (angle == 40.0) {
direction = 0;
}

}

void idle(void)
{
if(pause==false)
{
}
}

void key(unsigned char k, int x, int y)
{
switch(k)
{
case 27: //27 is the ASCII code for the ESCAPE key
exit(0);
break;
case 'a': rota +=1;draw();break;
case 'b': rotb +=1;draw();break;
}
}

void reshape(int width, int height)
{
glViewport(0,0,width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, 50.0, -150.0, 150.0);
// gluPerspective(45.0, (float) width / (float) height, 1.0, 100.0);
draw();
}

void init_drawing(void)
{
glShadeModel(GL_SMOOTH);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

glDisable(GL_LIGHTING);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
}

Deiussum
11-24-2003, 01:19 PM
glOrtho does not take 5 parameters.

From MSDN



void glOrtho(
GLdouble left,
GLdouble right,
GLdouble bottom,
GLdouble top,
GLdouble zNear,
GLdouble zFar
);


Note: There are 6 parameters there.

Here's where you call glOrtho:

glOrtho(-50.0, 50.0, 50.0, -150.0, 150.0);

Note: There are 5 paramters passed here.

I'm not sure how much simpler the compiler can tell you what exactly is wrong. A refresher course in C/C++ might be in order here.

Deiussum
11-24-2003, 01:26 PM
The next problem you are going to run into is that you have the line that sets the matrix mode to GL_MODELVIEW commented out. You'll want that uncommented or you will clear out your projection matrix, which is where you should have put your glOrtho call...

There may be other problems, but I haven't really looked that close.

hoganh
11-24-2003, 01:42 PM
Thanks I got it working.
Is there anybody who could help me make the swing in 3D.As you can see im only new to opengl.