Skip to main content
GameDev.net gamedev.net
🔒 Locked

glut sphere

Started by emzee Jun 15, 2002 at 5:22 AM 4 replies 9.5k views
Original Post
emzee
emzee
Well, its strange, sometimes the sphere is rotated and sometimes it is not. It even depends where the mouse is and where the console box is. Compiled with mingw and Dev-C++ Code is here : void renderScene() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0, 1.0, 0.0); glRotatef(90.0, 1.0, 0.0, 0.0); glPopMatrix(); glutWireSphere(1.0, 12, 12); glFlush(); } void changeSize(int w, int h) { if(h==0) h=1; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0, 0, w, h); gluPerspective(45, (float)w/h, 1, 1000); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0,0.0,5.0, 0.0,0.0,-1.0, 0.0f,1.0f,0.0f); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitWindowPosition(-1, -1); glutInitWindowSize(1024, 768); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH); glutCreateWindow("Globe"); glutDisplayFunc(renderScene); glutReshapeFunc(changeSize); glutMainLoop(); return 0; } I didnt include the #include files, you should know what they are anyway. Thank you
4llj00rb4ndw1th4r3b3l0ngst0m3p0rn
gip
gip
Hi! I have the answer for it to you!!!

First you will need change GLUT_SINGLE to GLUT_DOUBLE (is more used for 3d animations)

Then, if you put a light in some direction, will could help you see the sphere rotating.

Take a look at OpenGL RedBook for more info.

Good Lucky!!!

Rafael G. Donato
"Be forgotten is worse than death..."[email=rgdonato@gmail.com]Rafael G. Donato[/email]
emzee
emzee
changing to GLUT_DOUBLE gives me a blank window and the spehere shouldnt rotate, it the "system" it must be drawn into, must be rotated just one time, to draw the sphere right.
4llj00rb4ndw1th4r3b3l0ngst0m3p0rn
gip
gip
Well, I used your code and made some modifications....
Sorry the English, but I''m Brazilian.
I made the keyboard rotate the Sphere, with LEFT and UP keys.
ESC exits too.

View if is this you wanna make...
It''s compiled in Dev-C/C++, with Project Options, compile as C++
Linker: -l?OpenGL32 -lGlu32 -lGlut32
And in in32 GUI.
----------------------------------------

#include <GL/glut.h>

float xf = 90.0;
float yf = 1.0;

void renderScene()
{
glClear( GL_COLOR_BUFFER_BIT );
glColor3f( 0.0, 1.0, 0.0 );

glRotatef( xf, 1.0, 0.0, yf );

glPopMatrix();
glutWireSphere( 1.0, 12, 12 );
glFlush();

glutSwapBuffers();

}

void keyboard( unsigned char key, int x, int y ) {

switch( key ) {

case 27:
exit( 1 );
break;

}

}

void spec_keyboard( int key, int x, int y ) {

switch( key ) {

case GLUT_KEY_UP:
xf += 0.001;
glutPostRedisplay();
break;

case GLUT_KEY_LEFT:
yf -= 0.01;
glutPostRedisplay();
break;

}

}

void changeSize( int w, int h )
{
if(h==0)
h=1;

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glViewport( 0, 0, w, h );
gluPerspective( 45, ( float ) w/h, 1, 1000 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt( 0.0,0.0,5.0, 0.0,0.0,-1.0, 0.0f,1.0f,0.0f );
}

int main(int argc, char *argv[])
{
glutInit( &argc, argv );
glutInitWindowPosition( -1, -1 );
glutInitWindowSize( 1024, 768 );
glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH );
glutCreateWindow( "Globe" );
glutDisplayFunc( renderScene );
glutReshapeFunc( changeSize );

glutSpecialFunc( spec_keyboard );
glutKeyboardFunc( keyboard );

glutMainLoop();
return 0;
}

--------------------------

Good Lucky Again.
"Be forgotten is worse than death..."[email=rgdonato@gmail.com]Rafael G. Donato[/email]
emzee
emzee
If you would take your app and it would be in a window and when you move the window and let it go, then still the sphere moves. But thanks anyway.
I took my own code, and tried various things with it, and by puting glPopMatrix() before and glPushMatrix() after the glutWireSphere(), i got that thing working properly.
It would still be nice, if somebody will explain me/us why is that.

[edited by - emzee on June 15, 2002 8:41:40 AM]
4llj00rb4ndw1th4r3b3l0ngst0m3p0rn
gip
gip
Hey, you''re right!!! I understand now what you''re talking about!!

I fix it! Sorry for before, but I''m brazilian and I have much to learn about interpretation in English! (

here''s the code
=====================================
#include <GL/glut.h>

float xf = 90.0;
float yf = 1.0;

void renderScene()
{
glClear( GL_COLOR_BUFFER_BIT );
glColor3f( 0.0, 1.0, 0.0 );

glPushMatrix(); //Where you are pushing the matrix in your code???You only finish it!!

glRotatef( xf, 1.0, 0.0, yf ); //this two have to be between the Push and Pop.
glutWireSphere( 1.0, 12, 12 );

glPopMatrix();
glFlush();

glutSwapBuffers();

}

void keyboard( unsigned char key, int x, int y ) {

switch( key ) {

case 27:
exit( 1 );
break;

}

}

void spec_keyboard( int key, int x, int y ) {

switch( key ) {

case GLUT_KEY_UP:
xf += 0.001;
glutPostRedisplay();
break;

case GLUT_KEY_LEFT:
yf -= 0.01;
glutPostRedisplay();
break;

}

}

void changeSize( int w, int h )
{
if(h==0)
h=1;

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glViewport( 0, 0, w, h );
gluPerspective( 45, ( float ) w/h, 1, 1000 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt( 0.0,0.0,5.0, 0.0,0.0,-1.0, 0.0f,1.0f,0.0f );
}

int main(int argc, char *argv[])
{
glutInit( &argc, argv );
glutInitWindowPosition( -1, -1 );
glutInitWindowSize( 1024, 768 );
glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH );
glutCreateWindow( "Globe" );
glutDisplayFunc( renderScene );
glutReshapeFunc( changeSize );

glutSpecialFunc( spec_keyboard );
glutKeyboardFunc( keyboard );

glutMainLoop();
return 0;
}

"Be forgotten is worse than death..."[email=rgdonato@gmail.com]Rafael G. Donato[/email]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.