I want to see the movement of the Sphere on the screen(OpenGL)
up vote
1
down vote
favorite
I want to see the movement of the Sphere on the screen.
but, If you run the code, you will not be able to update the screen.
How do I change the code to show a change in the location of the phrase I created?
void display() {
glLoadIdentity();
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
GLfloat diffuse1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat ambient1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat position1 = { 0, 0, 0, 1.0 };
GLfloat diffuse2 = { 0.5, 0.5, 0.5, 1 };
GLfloat ambient2 = { 0.1, 0.1, 0.1, 1 };
GLfloat specular2 = { 0.5, 0.5, 0.5, 1 };
GLfloat emission2 = { 0, 0, 0, 1 };
GLfloat shine = 300;
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient1);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular1);
glPushMatrix();
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient2);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse2);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular2);
glMaterialfv(GL_FRONT, GL_EMISSION, emission2);
glMaterialf(GL_FRONT, GL_SHININESS, shine);
glRotatef(mer_revolution, 0, 0, 1);
glTranslatef(0, 0.8, 0);
glRotatef(mer_rotate, 0, 0, 1);
glutSolidSphere(1, 300, 300);
glPopMatrix();
glFlush();
}
void main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,600);
glutCreateWindow("");
glClearColor(0, 0, 0, 0);
glColor3f(1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(move);
glutMainLoop();
}
c++ opengl
New contributor
add a comment |
up vote
1
down vote
favorite
I want to see the movement of the Sphere on the screen.
but, If you run the code, you will not be able to update the screen.
How do I change the code to show a change in the location of the phrase I created?
void display() {
glLoadIdentity();
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
GLfloat diffuse1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat ambient1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat position1 = { 0, 0, 0, 1.0 };
GLfloat diffuse2 = { 0.5, 0.5, 0.5, 1 };
GLfloat ambient2 = { 0.1, 0.1, 0.1, 1 };
GLfloat specular2 = { 0.5, 0.5, 0.5, 1 };
GLfloat emission2 = { 0, 0, 0, 1 };
GLfloat shine = 300;
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient1);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular1);
glPushMatrix();
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient2);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse2);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular2);
glMaterialfv(GL_FRONT, GL_EMISSION, emission2);
glMaterialf(GL_FRONT, GL_SHININESS, shine);
glRotatef(mer_revolution, 0, 0, 1);
glTranslatef(0, 0.8, 0);
glRotatef(mer_rotate, 0, 0, 1);
glutSolidSphere(1, 300, 300);
glPopMatrix();
glFlush();
}
void main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,600);
glutCreateWindow("");
glClearColor(0, 0, 0, 0);
glColor3f(1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(move);
glutMainLoop();
}
c++ opengl
New contributor
There is a typo in the code:position
should beposition1
. Furhter the projection matrix is missing, so the sphere is not in clip space and not "visible". Please correct that, to make it a Minimal, Complete, and Verifiable example
– Rabbid76
Nov 18 at 14:53
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I want to see the movement of the Sphere on the screen.
but, If you run the code, you will not be able to update the screen.
How do I change the code to show a change in the location of the phrase I created?
void display() {
glLoadIdentity();
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
GLfloat diffuse1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat ambient1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat position1 = { 0, 0, 0, 1.0 };
GLfloat diffuse2 = { 0.5, 0.5, 0.5, 1 };
GLfloat ambient2 = { 0.1, 0.1, 0.1, 1 };
GLfloat specular2 = { 0.5, 0.5, 0.5, 1 };
GLfloat emission2 = { 0, 0, 0, 1 };
GLfloat shine = 300;
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient1);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular1);
glPushMatrix();
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient2);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse2);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular2);
glMaterialfv(GL_FRONT, GL_EMISSION, emission2);
glMaterialf(GL_FRONT, GL_SHININESS, shine);
glRotatef(mer_revolution, 0, 0, 1);
glTranslatef(0, 0.8, 0);
glRotatef(mer_rotate, 0, 0, 1);
glutSolidSphere(1, 300, 300);
glPopMatrix();
glFlush();
}
void main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,600);
glutCreateWindow("");
glClearColor(0, 0, 0, 0);
glColor3f(1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(move);
glutMainLoop();
}
c++ opengl
New contributor
I want to see the movement of the Sphere on the screen.
but, If you run the code, you will not be able to update the screen.
How do I change the code to show a change in the location of the phrase I created?
void display() {
glLoadIdentity();
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
GLfloat diffuse1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat ambient1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat position1 = { 0, 0, 0, 1.0 };
GLfloat diffuse2 = { 0.5, 0.5, 0.5, 1 };
GLfloat ambient2 = { 0.1, 0.1, 0.1, 1 };
GLfloat specular2 = { 0.5, 0.5, 0.5, 1 };
GLfloat emission2 = { 0, 0, 0, 1 };
GLfloat shine = 300;
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient1);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular1);
glPushMatrix();
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient2);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse2);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular2);
glMaterialfv(GL_FRONT, GL_EMISSION, emission2);
glMaterialf(GL_FRONT, GL_SHININESS, shine);
glRotatef(mer_revolution, 0, 0, 1);
glTranslatef(0, 0.8, 0);
glRotatef(mer_rotate, 0, 0, 1);
glutSolidSphere(1, 300, 300);
glPopMatrix();
glFlush();
}
void main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,600);
glutCreateWindow("");
glClearColor(0, 0, 0, 0);
glColor3f(1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(move);
glutMainLoop();
}
c++ opengl
c++ opengl
New contributor
New contributor
New contributor
asked Nov 18 at 14:13
Paul Z.
61
61
New contributor
New contributor
There is a typo in the code:position
should beposition1
. Furhter the projection matrix is missing, so the sphere is not in clip space and not "visible". Please correct that, to make it a Minimal, Complete, and Verifiable example
– Rabbid76
Nov 18 at 14:53
add a comment |
There is a typo in the code:position
should beposition1
. Furhter the projection matrix is missing, so the sphere is not in clip space and not "visible". Please correct that, to make it a Minimal, Complete, and Verifiable example
– Rabbid76
Nov 18 at 14:53
There is a typo in the code:
position
should be position1
. Furhter the projection matrix is missing, so the sphere is not in clip space and not "visible". Please correct that, to make it a Minimal, Complete, and Verifiable example– Rabbid76
Nov 18 at 14:53
There is a typo in the code:
position
should be position1
. Furhter the projection matrix is missing, so the sphere is not in clip space and not "visible". Please correct that, to make it a Minimal, Complete, and Verifiable example– Rabbid76
Nov 18 at 14:53
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
Move 'gL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT' at the top of the display.
The screen must be initialized when performing a function. Only then will the screen continue to change.
add a comment |
up vote
0
down vote
There are 2 issues. Of course you have to clear the framebuffer at the begin of every frame glClear
. But you have to "tell" the display to be continuously redisplayed, too. ths can be done by glutPostRedisplay
.
Further you should incrementally change the angles mer_revolution
and mer_rotate
to animate the scene:
void display( void )
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
....
glFlush();
glutPostRedisplay();
mer_revolution += 1.0f;
mer_rotate += 0.5f;
}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Move 'gL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT' at the top of the display.
The screen must be initialized when performing a function. Only then will the screen continue to change.
add a comment |
up vote
2
down vote
Move 'gL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT' at the top of the display.
The screen must be initialized when performing a function. Only then will the screen continue to change.
add a comment |
up vote
2
down vote
up vote
2
down vote
Move 'gL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT' at the top of the display.
The screen must be initialized when performing a function. Only then will the screen continue to change.
Move 'gL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT' at the top of the display.
The screen must be initialized when performing a function. Only then will the screen continue to change.
answered Nov 18 at 14:21
Sera
462
462
add a comment |
add a comment |
up vote
0
down vote
There are 2 issues. Of course you have to clear the framebuffer at the begin of every frame glClear
. But you have to "tell" the display to be continuously redisplayed, too. ths can be done by glutPostRedisplay
.
Further you should incrementally change the angles mer_revolution
and mer_rotate
to animate the scene:
void display( void )
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
....
glFlush();
glutPostRedisplay();
mer_revolution += 1.0f;
mer_rotate += 0.5f;
}
add a comment |
up vote
0
down vote
There are 2 issues. Of course you have to clear the framebuffer at the begin of every frame glClear
. But you have to "tell" the display to be continuously redisplayed, too. ths can be done by glutPostRedisplay
.
Further you should incrementally change the angles mer_revolution
and mer_rotate
to animate the scene:
void display( void )
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
....
glFlush();
glutPostRedisplay();
mer_revolution += 1.0f;
mer_rotate += 0.5f;
}
add a comment |
up vote
0
down vote
up vote
0
down vote
There are 2 issues. Of course you have to clear the framebuffer at the begin of every frame glClear
. But you have to "tell" the display to be continuously redisplayed, too. ths can be done by glutPostRedisplay
.
Further you should incrementally change the angles mer_revolution
and mer_rotate
to animate the scene:
void display( void )
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
....
glFlush();
glutPostRedisplay();
mer_revolution += 1.0f;
mer_rotate += 0.5f;
}
There are 2 issues. Of course you have to clear the framebuffer at the begin of every frame glClear
. But you have to "tell" the display to be continuously redisplayed, too. ths can be done by glutPostRedisplay
.
Further you should incrementally change the angles mer_revolution
and mer_rotate
to animate the scene:
void display( void )
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
....
glFlush();
glutPostRedisplay();
mer_revolution += 1.0f;
mer_rotate += 0.5f;
}
answered Nov 18 at 14:39
Rabbid76
30.4k112842
30.4k112842
add a comment |
add a comment |
Paul Z. is a new contributor. Be nice, and check out our Code of Conduct.
Paul Z. is a new contributor. Be nice, and check out our Code of Conduct.
Paul Z. is a new contributor. Be nice, and check out our Code of Conduct.
Paul Z. is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361819%2fi-want-to-see-the-movement-of-the-sphere-on-the-screenopengl%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
There is a typo in the code:
position
should beposition1
. Furhter the projection matrix is missing, so the sphere is not in clip space and not "visible". Please correct that, to make it a Minimal, Complete, and Verifiable example– Rabbid76
Nov 18 at 14:53