PDA

View Full Version : more than one object in a scene



matt
12-01-2001, 11:46 AM
what am i doing wrong. i want to be able to see the two spheres but only one appear can you help a novice please?

#include <windows.h>
#include <gl/glut.h>


void sheep(void) //draw scene
{


glClear(GL_COLOR_BUFFER_BIT);//clear window
glScalef(0.8f,1.0f,1.0f);
glColor3f(1.0f,1.0f,1.0f);
GLUquadricObj *sheepBody;
sheepBody = gluNewQuadric();
gluSphere(sheepBody,30, 30, 30);


glTranslatef(20.0f,30.0f,0.0f);
glScalef(1.0f,0.8f,1.0f);
glColor3f(0.0f,0.0f,0.0f);
GLUquadricObj *sheepHead;
sheepHead = gluNewQuadric();
gluSphere(sheepHead,10, 10, 10);

}

void SetupRC(void) //setup rendering state
{
glClearColor(0.0f,0.0f,1.0f,1.0f);
}

void ChangeSize(GLsizei w, GLsizei h)
{
GLfloat nRange = 100.0f;
//GLfloat fAspect;

if(h==0)
h=1;

glViewport(0,0,w,h);

//fAspect = (GLfloat)w/GLfloat)h;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(0.0f,0.0f,1.0,425.0);

if (w <= h)
glOrtho (-nRange,nRange,-nRange*h/w,nRange*h/w,-nRange,nRange);
else
glOrtho (-nRange*w/h,nRange*w/h,-nRange,nRange,-nRange,nRange);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();


}

void main(void) //program entry point
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("Sheep");
glutDisplayFunc(sheep);
glutReshapeFunc(ChangeSize);


SetupRC();

glutMainLoop();
}

Bob
12-01-2001, 02:45 PM
Use either orthographic or perspective projection, but not both of them at the same time. Of course, uless you know what you're doing, and that's what you want.

WhatEver
12-01-2001, 08:25 PM
Do this:



glPushMatrix();
glClear(GL_COLOR_BUFFER_BIT);//clear window
glScalef(0.8f,1.0f,1.0f);
glColor3f(1.0f,1.0f,1.0f);
GLUquadricObj *sheepBody;
sheepBody = gluNewQuadric();
gluSphere(sheepBody,30, 30, 30);
glPopMatrix();

glPushMatrix();
glTranslatef(20.0f,30.0f,0.0f);
glScalef(1.0f,0.8f,1.0f);
glColor3f(0.0f,0.0f,0.0f);
GLUquadricObj *sheepHead;
sheepHead = gluNewQuadric();
gluSphere(sheepHead,10, 10, 10);
glPopMatrix();


[This message has been edited by WhatEver (edited 12-01-2001).]

matt
12-02-2001, 02:09 AM
thanks for the help guys, i just needed to flush the buffer and i was there. still having problems getting perpective to work rather than ortho.

Thug
12-07-2001, 11:25 AM
Another thing that you can do to speed up the program would be to make only one GLUquadricObj object... it does not store any geometry of the object that you are trying to draw.