Computer Science Canada

Creating a sphere using GLUT

Author:  102jon [ Thu Dec 16, 2010 7:18 pm ]
Post subject:  Creating a sphere using GLUT

I'm working on a three body problem, but i'm having trouble using the glutSolidSphere function. Can anyone give me sample C++ source code that simply renders a single sphere? It would be greatly appreciated.

Author:  Ultrahex [ Fri Dec 17, 2010 9:44 am ]
Post subject:  Re: Creating a sphere using GLUT

There is many examples of this on the web, and this is relatively simple to do... It sounds to me like this is for an assignment, however here is code
that does something very similar to what you want.

c:
#include <iostream>
#include <cstdlib>
#include <GL/glut.h>
using namespace std;

static int win;
void disp(void);

void keyb(unsigned char key, int x, int y);

int main(int argc, char **argv){
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
    glutInitWindowSize(500,500);
    win = glutCreateWindow("Here is a sphere, for some reason");
    glutDisplayFunc(disp);
    glutKeyboardFunc(keyb);
    glClearColor(0.0,0.0,0.0,0.0);
    glutMainLoop();
    return 0;
}


void disp(void){
    glClear(GL_COLOR_BUFFER_BIT);

    glutWireSphere(0.5,100,100);
}

void keyb(unsigned char key, int x, int y){
    if(key == 'q'){
        glutDestroyWindow(win);
        exit(0);
    }
}


: