PDA

View Full Version : gluSphere (?)



Vlasko
01-25-2002, 12:14 AM
i have a problem with sphere showing up on screen i think there is a problem with glScaled
Code: #include<gl/glut.h>

void init(GLvoid)
{
glClearColor(0.0f,0.0f,0.0f,0.5f);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

}

void display(void)
{
GLUquadricObj* pKocka;
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glTranslated(200,200,200);
if(!(pKocka=gluNewQuadric())) exit(1);
glColor3ui(45,123,204);
gluSphere(pKocka,50,40,40);
glPopMatrix();
glutSwapBuffers();
glFlush();
}

void keyb(unsigned char a,int x,int y)
{
if(a=='b') glutPostRedisplay();
}

int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowPosition(10,10);
glutInitWindowSize(629,469);
glutCreateWindow("Gula");
glClearColor(0.0f,0.0f,0.0f,0.0f);
init();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScaled(400,400,400);
glutKeyboardFunc(keyb);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

Gavin
01-25-2002, 02:30 AM
try adding a reshape function

oid reshape_flir(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, (GLsizei) w, 0, (GLsizei) h, -10, 10);
glMatrixMode(GL_MODELVIEW);
glTranslatef(0.0, 0.0, -4.0);
}

Bob
01-25-2002, 02:48 AM
glColor3ui(45,123,204);

If you pass a color as integer types, then you pass values in the range [0, 2^n-1], where n is the number of bits in the type. For unsigned integers, n is usually 32. So 204 in that case corresponds to 0.000000047 when converted to a float. And due to finite precision of a floatingpoint value, this is equal to 0. So, you are passing a pure black color. And the fact that the background color also is black won't make things better if you want to see your sphere.

Maybe you should replace glColor3ui with glColor3ub.

And the size of your sphere is maybe a bit too large. The sphere you draw is 50 units in radius. Multiply that with 400, you get 20000 units large with the center located at (200, 200, 200). Since you have the identity matrix as projectipon matrix, every object outside the range x = [-1, 1], y = [-1, 1] and z = [-1, 1] will not be drawn. And your sphere is WAY outside this range.

Vlasko
01-26-2002, 08:21 AM
so how should i multiple matrix coordinates ? i don't want to use [-1,1] for all axis (maybe that has something to do with MSDN documentation - if you are not english american or somebody like that you won't understand that correctly :-))

Vlasko
01-27-2002, 07:04 AM
Thanks i did work(shrinking :-)) but i di get some weird colours it should be blue but i get black lines throught the sphere. Any suggestions ?