PDA

View Full Version : Sphere isn't filled (freeglut / OpenGL)



Clément
03-09-2012, 03:33 PM
Hello,

I've been trying to render a sphere using freeglut and OpenGL.. so far I only succeeded in obtaining a "circle".

Here is most of the code I use (some part that are not related have been removed):


As I had never used either freeglut nor OpenGL before, some part of the code may sound absurd.
If they do, please do not hesitate to indicate them (along with some explanations of course :P)


#define FREEGLUT_STATIC
#include <GL/freeglut.h>
#include <list>
#include <cstdlib>
#include "Coordinate.hh"

static void resize(int width, int height)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity() ;
glOrtho(0.0f, (GLfloat) width, 0.0f,
(GLfloat) height, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
glViewport(0, 0, width, height);
}


static void display(void)
{
glutMainLoopEvent();

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1,0,0);
for (std::list<Coordinate *>::iterator it = Positions.begin(); it != Positions.end(); ++it)
{
// Coordinate is a class containing two floats (x, y)
// They are public attribute.
glColor3f(0.60f,0.80f,0.90f);
glPushMatrix();
glTranslatef((**it).x, (**it).y, -20.0f);
glRotatef(100.0, 10.0, 0, 0);
glutSolidSphere(30, 18 , 36);
glPopMatrix();
}
glutSwapBuffers();
}

void init_window(const unsigned int &amp;size_x, const unsigned int &amp;size_y)
{
int init_glut = 0;

glutInit(&amp;init_glut, NULL);
glutInitWindowSize(size_x, size_y);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("sphere");

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, (GLfloat) size_x, 0.0f,
(GLfloat) size_y, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutSpecialFunc(SpecialKeys);
glutIdleFunc(idle);
}

Here is what I get for example:

http://imageup.fr/uploads/1331323440.png

Problem might come from the angle of view..
I had tried fixing it with some functions like gluPerspective but without success.

I'd be thankfull is someone could help me =)

PS: I apologise if my english is poor, I'm french x)