PDA

View Full Version : problem with displaying 4 object



openglnovice
10-13-2005, 07:03 AM
Hello everyone..ok the idea is I just got this code from internet source ..it draw 4 object..then user can using mouse to choose different object ...so my attempt is I want to displaying 4 object all '4'once!!..so when i alter the code it seems nothing was display...so really need ur expertise help guys...here the code i've been using...


#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <GL/glut.h>


void drawSphere(void) {
glutWireSphere(3.0,20,10);
}


void drawCone(void) {
glutWireCone(5.0, 5.0, 10, 20);
}

void drawTorus(void) {
glutWireTorus(1.0, 5.0, 10, 20);
}

void drawTeapot(void) {
glutWireTeapot(5.0);
}


void display(void)
{
glClear( GL_COLOR_BUFFER_BIT );

/* set matrix mode to modelview */
glMatrixMode(GL_MODELVIEW);
/* save matrix */
glPushMatrix();

glPopMatrix();

/* swap buffers to display the frame */
glutSwapBuffers();
}

void myReshape(int w, int h)
{
/* set viewport to new width and height */
/* note that this command does not change the CTM */
glViewport(0, 0, w, h);

/*
* set viewing window using perspective projection
*/
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); /* init projection matrix */

/* perspective parameters: field of view, aspect, near clip, far clip */
gluPerspective( 60.0, (GLdouble)w/(GLdouble)h, 0.1, 40.0);

/* set matrix mode to modelview */
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 50.0, /* eye at (0,0,20) */
0.0, 0.0, 0.0, /* lookat point */
0.0, 10.0, 0.0); /* up is in +ive y */
}

/*
* myKey
*
* responds to key presses from the user
*/
void myKey(unsigned char k, int x, int y)
{
switch (k) {
case 'q':
case 'Q': exit(0);
break;
default:
printf("Unknown keyboard command \'%c\'.\n", k);
break;
}
}


void myMouse(int btn, int state, int x, int y)
{

if(btn==GLUT_LEFT_BUTTON &amp;&amp; state == GLUT_DOWN) ;//g_rotInc += ROT_INC;
if(btn==GLUT_MIDDLE_BUTTON &amp;&amp; state == GLUT_DOWN); //g_rotInc = ROT_INC;
/* if(btn==GLUT_RIGHT_BUTTON &amp;&amp; state == GLUT_DOWN) g_rotInc -= ROT_INC;
*/
/* force redisplay */
glutPostRedisplay();
}


int main(int argc, char **argv)
{
/* glutInit MUST be called before any other GLUT/OpenGL calls */
glutInit(&amp;argc, argv);

/* set double buffering, note no z buffering */
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(800, 600);
glutCreateWindow("Testing");

/* set callback functions */
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutKeyboardFunc(myKey);
glutMouseFunc(myMouse);

/* set clear colour */
glClearColor(1.0, 1.0, 1.0, 1.0);

/* set current colour to black */
glColor3f(0.5, 0.0, 5.0);

glutMainLoop();

return 0;
}
any help would be greatful...really need help..
tq

memfr0b
10-13-2005, 07:24 AM
Obviously, that's because you didn't call the acme_magic_do_what_i_want function.

Seriously, you have to call the draw functions of the objects you want to display. All your display routine currently does, is clear the window.

openglnovice
10-13-2005, 07:51 AM
Ok 1stly thnkas for the reply...

ok in my display routine i just put this..

glPushMatrix();
//1st function draw
drawSphere
glPopMatrix();

AND U KNOW WHAT IS STILL DIPSLAY NOTHING...so if I'mnot asking to much ..can u pls show me the rite path or else some walkthrough would be great..tq for ur concern..

tq

memfr0b
10-13-2005, 10:47 AM
You have your far plane set to 40, but the gluLookAt already moves the objects 50 units away, so your object are probably clipped by the far plane.

openglnovice
10-13-2005, 12:22 PM
u mean this portion of code..

gluPerspective( 60.0, (GLdouble)w/(GLdouble)h, 0.1, 20.0);
///////////////////////////

gluLookAt(0.0, 0.0, 20.0, /* eye at (0,0,20) */
0.0, 0.0, 0.0, /* lookat point */
0.0, 1.0, 0.0); /* up is in +ive y */

kind of confuse here..since I alter this code from the original...so u think what should I do...by the way this is my 1st time using openGL...stuck up already...will u point me which part I have to doing adjustment...

need to finished this before tomorrow..tq for ur times..

openglnovice
10-14-2005, 05:07 AM
bump!!..

anyone at least some walkthrough would be okay..really need help with it...

tq

memfr0b
10-14-2005, 02:09 PM
In your original post you have


gluPerspective(60.0, (GLdouble)w/(GLdouble)h, 0.1, 40.0);which will set the far clip plane to 40.

Then you do a lookat with


gluLookAt(0.0, 0.0, 50.0, /* eye at (0,0,20) */
0.0, 0.0, 0.0, /* lookat point */
0.0, 10.0, 0.0); /* up is in +ive y */which will move all objects 50 units away from the origin. This will position your objects behind the far clip plane, so they won't be displayed. You either need to increase the far clip distance, or not move the objects so far away.

openglnovice
10-14-2005, 03:43 PM
but..I just playing with this portion of code but it's still nothing was dipslaying....how was is it mate?..

Actually what I did is I increased the far clip distance


gluPerspective( 60.0, (GLdouble)w/(GLdouble)h, 0.1, 30.0);
then lookup I try to decrease it


gluLookAt(0.0, 0.0, 20.0, /* eye at (0,0,20) */
0.0, 0.0, 0.0, /* lookat point */
0.0, 10.0, 0.0); /* up is in +ive y */
}
so mate what should I do then to figure out this problem...

memfr0b
10-15-2005, 01:42 AM
You should take your original code, and do exactly the two modifications i mentioned, as i've done in openglnovice.c (http://memfrob.de/~memfrob/openglnovice.c) .

You might also have to resize your window once, as your matrix setup only happens in the reshape callback.