#include <stdio.h> // this library is for standard input and output
#include "glut.h"// this library is for glut the OpenGL Utility Toolkit
#include <math.h>
float squareX = 0.0f;
float squareY = -0.3f;
float squareZ = 0.0f;
static int flag = 1;
void drawShape(void) {
glTranslatef(squareX, squareY, squareZ);
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(162, 50);
glVertex2f(162, 10);
glVertex2f(220, 10);
glVertex2f(220, 50);
glVertex2f(162, 50);
glEnd();
}
void initRendering() {
glEnable(GL_DEPTH_TEST);
}
// called when the window is resized
void handleResize(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, (float)w, 0.0f, (float)h, -1.0f, 1.0f);
}
void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
drawShape();
glutSwapBuffers();
}
// make the square go up
void update(int value) {
if (flag) {
squareY += 1.0f;
if (squareY > 400.0) {
flag = 0;
}
}
glutPostRedisplay();
glutTimerFunc(25, update, 0);
}
// make the square go right
/* void update(int value) {
if (flag) {
squareX += 1.0f;
if (squareX > 400.0) {
flag = 0;
}
}
glutPostRedisplay();
glutTimerFunc(25, update, 0);
} */
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(400, 400);
glutCreateWindow("Moving Square");
initRendering();
glutDisplayFunc(drawScene);
glutReshapeFunc(handleResize);
glutTimerFunc(25, update, 0);
glutMainLoop();
return(0);
}
I have uploaded this code before but this time I made the square go all the way up. The code just moves the square up, but I don't know how to position it on the left once it reaches the top, so then I can make it move to the right. I have uploaded a demonstration on how I want it to look below.
Preview:
What I want it to do next:
I recommend to initialize the variables squareX, squareY and squareZ with the start position of the rectangle:
float squareX = 162.0f;
float squareY = 0.0f;
float squareZ = 0.0f;
Do not draw a rectangle specific position, but draw a rectangle on the position (0,0) with a length (width, height). Let the model matrix (set by glTranslatef), do the job of the positioning:
void drawShape(void)
{
float width = 58.0f;
float height = 40.0f;
glTranslatef(squareX, squareY, squareZ);
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(0, 0);
glVertex2f(width, 0);
glVertex2f(width, height);
glVertex2f(0, height);
glVertex2f(0, 0);
glEnd();
}
Use a variable state, which has stated the direction of the current movement:
int state = 1; // 0: stop; 1: move up; 2: move right
If the rectangle a certain position has reached, then the state has to be changed and a the new start position can be set. At the final position, the rectangle can stop or the process can even be restarted:
void update(int value)
{
if (state == 1) // 1 : move up
{
squareY += 1.0f;
if (squareY > 400.0)
{
state = 2;
squareX = 0.0f;
squareY = 180.0f;
}
}
else if (state == 2) // 2 : move right
{
squareX += 1.0f;
if (squareX > 400.0)
{
state = 0;
// restart
//state = 1;
//squareX = 162.0f;
//squareY = 0.0f;
}
}
glutPostRedisplay();
glutTimerFunc(25, update, 0);
}
Related
I am trying to scroll a text as a banner. I used openGL with glut to make this work. The whole code works if I use a figure like a square. The square scrolls over the screen.
Now I want to do this with text. Every time this program started. The text came at its starting position, but when the timer starts, it vanished. This is probably because the screen was cleared every clocktick, but the screen doesn't build up again.
Someone who can help me with this translation animation and text?
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#ifdef WIN32
#include <windows.h>
#endif
#include <GL/gl.h>
#include <GL/glut.h>
using namespace std;
static int font_index = 0;
int state = 1;
void print_bitmap_string(/*void* font,*/ const char* s)
{
while (*s) {
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *s);
s++;
}
}
void my_reshape(int w, int h)
{
GLdouble size;
GLdouble aspect;
/* Use the whole window. */
glViewport(0, 0, w, h);
/* We are going to do some 2-D orthographic drawing. */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
size = (GLdouble)((w >= h) ? w : h) / 2.0;
if (w <= h) {
aspect = (GLdouble)h / (GLdouble)w;
glOrtho(-size, size, -size * aspect, size * aspect, -100000.0, 100000.0);
}
else {
aspect = (GLdouble)w / (GLdouble)h;
glOrtho(-size * aspect, size * aspect, -size, size, -100000.0, 100000.0);
}
/* Make the world and window coordinates coincide so that 1.0 in */
/* model space equals one pixel in window space. */
glScaled(aspect, aspect, 1.0);
/* Now determine where to draw things. */
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
float yild;
float ystep;
float x_pos = -200;
float y_pos = 70;
void draw()
{
const char* bitmap_font_names[7] = { "Hello train" };
/* Draw the strings, according to the current mode and font. */
glTranslatef(0.5, -100, 0);
//set the text color
glColor4f(0.0f, 255.0f, 140.0f, 1.0f);
ystep = 100.0;
yild = 20.0;
glRasterPos2f(x_pos, y_pos + 1.25 * yild);
print_bitmap_string(bitmap_font_names[0]);
}
void display(void)
{
//change background color
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
draw();
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_POLYGON);
glVertex2f(x_pos + 0.5f, 0.0f);
glVertex2f(x_pos+1.0f, 0.5f);
glVertex2f(x_pos+0.5f, 0.5f);
glEnd();
glutSwapBuffers();
}
void timer(int) {
glutPostRedisplay();
glutTimerFunc(1000 , timer, 0);
switch (state) {
case 1:
if (x_pos > -295) {
x_pos -= 1;
}
else {
state = -1;
}
break;
case -1:
x_pos = 180;
state = 1;
break;
}
cout << x_pos << endl;
}
int main(int argc, char** argv)
{
glutInitWindowSize(500, 150);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("Train Display");
glutDisplayFunc(display);
glutReshapeFunc(my_reshape);
glutTimerFunc(1000, timer, 0);
glutMainLoop();
return 0;
}
glTranslate does not just set a translation matrix, but multiply the current matrix by a translation matrix. You need to load the identity matrix with glLoadIdentity before glTranslatef or save and restore the current matrix with glPushMatrix/glPopMatrix:
void draw()
{
const char* bitmap_font_names[7] = { "Hello train" };
glPushMatrix();
/* Draw the strings, according to the current mode and font. */
glTranslatef(0.5, -100, 0);
//set the text color
glColor4f(0.0f, 255.0f, 140.0f, 1.0f);
ystep = 100.0;
yild = 20.0;
glRasterPos2f(x_pos, y_pos + 1.25 * yild);
print_bitmap_string(bitmap_font_names[0]);
glPopMatrix();
}
I am trying to write a simple program that moves a Sphere around a Ellipse in OpenGL. I thought that if I set translate coordinates to the same as the Ellipse coordinates it would simulate motion.
This is the code I already have:
#include "stdafx.h"
#include <windows.h>
#include <GL/Gl.h>
#include <GL/GLU.h>
#include <GL/glut.h>
#include <math.h>
const float eRad = 6.5;
void drawSphere(void)
{
float x = 0.5;
float y = 0.4;
float z = 0.0;
glMatrixMode(GL_PROJECTION | GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);
// Draw the Ellipse
glColor3d(1.0, 0.0, 1.0);
glBegin(GL_LINE_STRIP);
for (float i = 0; i <= eRad; i += 0.1)
{
glVertex2f(x*cos(i), y*sin(i));
}
glEnd();
//Draw the Sphere
glColor3d(1.0, 1.0, 0.0);
glPushMatrix();
glTranslatef(0.5, 0, 0);
glutWireSphere(0.15, 30, 30);
glPopMatrix();
glFlush();
}
void animation(void)
{
float x = 0.2;
float y = 0.1;
float z = 0.0;
for (float i = 0; i <= eRad; i += 0.1)
{
glTranslated(x*cos(i), y*sin(i), z);
}
drawSphere();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(0, 0);
glutCreateWindow("Moving Sphere Test");
glutDisplayFunc(drawSphere);
glutIdleFunc(animation);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glViewport(0, 0, 600, 600);
glutMainLoop();
}
The issue I am having is that the Ellipse is drawn in and so is the sphere, but its just staying at one point on the ellipse. So what am I doing wrong?
Yes, you need to use the functions correctly. The animation happens in glutDisplayFunc, the state setting can happen in glutIdleFunc(It does not have to). The gultTimerFunc() callback is what you want to be called every frame. I made a few modifications to your code. But you might want to use the GLUT correctly.
const float eRad = 6.5;
static float iter = 0.0;
void drawSphere(void)
{
float x = 0.5;
float y = 0.4;
float z = 0.0;
glMatrixMode(GL_PROJECTION | GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);
// Draw the Ellipse
glColor3d(1.0, 0.0, 1.0);
glBegin(GL_LINE_STRIP);
for (float i = 0; i <= eRad; i += 0.1)
{
glVertex2f(x*cos(i), y*sin(i));
}
glEnd();
//Draw the Sphere
glColor3d(1.0, 1.0, 0.0);
glPushMatrix();
glTranslatef(x*cos(iter), y*sin(iter), 0);
glutWireSphere(0.15, 30, 30);
glPopMatrix();
glFlush();
}
void animation(void)
{
iter = (iter < 6.5) ? iter+0.0001 : 0.0;
}
void Timer(int value) {
glutTimerFunc(33, Timer, 0);
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(0, 0);
glutCreateWindow("Moving Sphere Test");
glutDisplayFunc(drawSphere);
glutIdleFunc(animation);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glViewport(0, 0, 600, 600);
Timer(0);
glutMainLoop();
}
I'm trying to code a camera with glTranslate/glRotate. To implement the look-up / look-down functions I need all the objects in my rendering space to rotate around a point (that is, where the "camera" is at), point which usually differs from the origin. Still, things keep rotating around the origin. Is there a way to specify a different point?
EDIT: Added code
Thanks for your fast reply. It seems that I can't get it working right no matter what, so I've decided to add my code; I'd much appreciate if someone could take a look at it and tell me what changes are needed in order to translate/rotate/translate back.
#include <iostream>
#include <cmath>
#include <GLUT/GLUT.h>
const double roaming_step = .13;
double z_offset = .0;
double y_offset = .0;
double x_offset = .0;
const double angle_step = 1.5;
double angle_xz = .0;
double angle_yz = .0;
bool keyStates[256] = { false };
void drawFloor()
{
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_QUADS);
glVertex3f(-3.0, -1.0, 3.0);
glVertex3f(-3.0, -1.0, -3.0);
glVertex3f(3.0, -1.0, -3.0);
glVertex3f(3.0, -1.0, 3.0);
glEnd();
}
void drawBalls()
{
glTranslatef(-3.0, -.5, -3.0);
glColor3f(.8, .1, .1);
for(int i = 0; i < 3; i++)
{
glPushMatrix();
glTranslatef(.0, -.5, i * 3);
for(int j = 0; j < 3; j++)
{
glPushMatrix();
glTranslatef(j * 3, .0, .0);
glutSolidSphere(.5, 20, 20);
glPopMatrix();
}
glPopMatrix();
}
}
void keyPressed(unsigned char key, int x, int y)
{
keyStates[key] = true;
}
void keyReleased(unsigned char key, int x, int y)
{
keyStates[key] = false;
}
void keyboardOperations()
{
if(keyStates['w'])
z_offset += roaming_step;
if(keyStates['s'])
z_offset -= roaming_step;
if(keyStates['a'])
x_offset += roaming_step;
if(keyStates['d'])
x_offset -= roaming_step;
if(keyStates['i'])
{
angle_xz -= angle_step;
if(angle_xz < .0)
angle_xz += 360.0;
}
if(keyStates['o'])
{
angle_xz += angle_step;
if(angle_xz >= 360.0)
angle_xz -= 360.0;
}
if(keyStates['u'])
{
angle_yz -= angle_step;
if(angle_yz < .0)
angle_yz += 360.0;
}
if(keyStates['j'])
{
angle_yz += angle_step;
if(angle_yz >= 360.0)
angle_yz -= 360.0;
}
if(keyStates['q'])
exit(0);
}
// I guess it has to be done in this function
// but didn't get how
void camera()
{
glLoadIdentity();
// Forward / Backward
glTranslated(.0, .0, z_offset);
// Left / Right
glTranslated(x_offset, .0, .0);
// XZ Rotation
glRotated(angle_xz, .0, 1.0, .0);
// YZ Rotation
glRotated(angle_yz, 1.0, .0, .0);
}
void display(void)
{
keyboardOperations();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
camera();
drawFloor();
drawBalls();
glutSwapBuffers();
}
void reshape(int width, int height)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, width, height);
GLdouble aspect = (GLdouble) width / (GLdouble) height;
gluPerspective(60, aspect, 1, 100);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("openGLtest3");
glClearColor(.0, .0, .0, .0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_FLAT);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(display);
glutIgnoreKeyRepeat(true);
glutKeyboardFunc(keyPressed);
glutKeyboardUpFunc(keyReleased);
glutMainLoop();
return 0;
}
In openGL, glRotation fuction takes origin as a reference. In order to rotate around a point (your camera coordinate in this case) you should translate your camera position to the origin (Translate all your objects accordingly) and then apply rotation function.And then you can translate your camera back (with all your objects)
lets say your camera position is (a,b,c) so your code should be something like :
foreach object
{
glPushMatrix();
glTranslate(a,b,c);
glRotate(...);
glTranslate(-a,-b,-c);
//render
glPopMatrix();
}
My OpenGL program is not working properly. Inside the drawScene() function I created two loops. One loop for GL_LINES another loop for GL_POINTS. The GL_LINES loop works fine but GL_POINTS loop doesn't work. Any help appreciated.
#include <iostream>
#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>
#define PI 3.14159265
using namespace std;
//Called when a key is pressed
void handleKeypress(unsigned char key, int x, int y) {
switch (key) {
case 27: //Escape key
exit(0);
}
}
//Initializes 3D rendering
void initRendering() {
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL); //Enable color
glClearColor(0.7f, 0.9f, 1.0f, 1.0f); //Change the background to sky blue
}
//Called when the window is resized
void handleResize(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0);
}
float _angle = 0.0f;
float _cameraAngle = 0.0f;
float x = -1.5;
float y = -0.5;
//Draws the 3D scene
void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glLineWidth (9.0f);
glBegin(GL_LINES);
glColor3f(1.0f, 0.0f, 0.0f);
double r = 0.5;
for(int c = 0;c<=360;c++){
double y = r*cos (c*PI/180);
double x = r*sin (c*PI/180);
glVertex3d(x,y,-5.0);
glVertex3d(0.0,0.0,-5.0);
}
glEnd();
glPointSize (7.0f);
glBegin(GL_POINTS);
glColor3f(0.0f, 1.0f, 0.0f);
double r = 1.0;
for(int c = 0;c<=360;c++){
double y = r*cos (c*PI/180);
double x = r*sin (c*PI/180);
glVertex3d(x,y,-5.0);
//glVertex3d(0.0,0.0,-5.0);
}
glEnd();
glutSwapBuffers();
//glutPostRedisplay();
}
void update(int value) {
_angle += 2.0f;
if (_angle > 360) {
_angle -= 360;
}
glutPostRedisplay();
glutTimerFunc(60, update, 0);
}
int main(int argc, char** argv) {
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(400, 400);
//Create the window
glutCreateWindow("two circle");
initRendering();
//Set handler functions
glutDisplayFunc(drawScene);
glutKeyboardFunc(handleKeypress);
glutReshapeFunc(handleResize);
glutTimerFunc(25, update, 0); //Add a timer
glutMainLoop();
return 0;
}
Right now, you're declaring the variable r in two places: where you set double r = 0.5; and at double r = 1.0;
Try changing it to:
double r = 0.5;
//First loop
r = 1.0;
//Second loop
I have to make a bowling game in openGL. This is the code I have so far. What it does that it draws a ball and is moved accordingly when an arrow key is pressed.
So far, I have that ball moving, that is fine. What I want to do that other point I have created, that should not be moved. Because, when that ball reaches to that point, it should be drop or something I will make that obstacle is dropped.
The code is written in Eclipse IDE.
#include <stdio.h>
#include <GL/glut.h>
#include <math.h>
#include <stdio.h> /* printf, scanf, puts, NULL */
float posX = 0, posY = -0.1, posZ = 0;
GLfloat rotation = 90.0;
double x, y, angle;
#define PI 3.1415926535898
GLint circle_points = 50;
void reshape(int width, int heigth) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//clip the windows so its shortest side is 2.0
if (width < heigth) {
glOrtho(-2.0, 2.0, -2.0 * (GLfloat) heigth / (GLfloat) width,
2.0 * (GLfloat) heigth / (GLfloat) width, 2.0, 2.0);
} else {
glOrtho(-2.0, 2.0, -2.0 * (GLfloat) width / (GLfloat) heigth,
2.0 * (GLfloat) width / (GLfloat) heigth, 2.0, 2.0);
}
// set viewport to use the entire new window
glViewport(0, 0, width, heigth);
}
void circ() {
glColor3f(0.0, 0.0, 1.0);
glPointSize(11.0);
glBegin(GL_POINTS);
glVertex3f(0.1, 0.1, 0.0);
glEnd();
glBegin(GL_TRIANGLE_FAN);
for (int i = 0; i <= 300; i++) {
angle = 2 * PI * i / 300;
x = cos(angle) / 20;
y = sin(angle) / 20;
glVertex2d(x, y);
}
glEnd();
}
void display() {
//Clear Window
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glTranslatef(posX, posY, posZ);
circ();
glPopMatrix();
glFlush();
}
void init() {
// set clear color to black
glClearColor(1.0, 1.0, 1.0, 0.0);
// set fill color to white
glColor3f(1.0, 1.0, 1.0);
//This is the default view and these statements could be removed
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.0, 1.0, -1.0, 1.0);
}
float move_unit = 0.02f;
void keyboardown(int key, int x, int y) {
switch (key) {
case GLUT_KEY_RIGHT:
posX += move_unit;
break;
case GLUT_KEY_LEFT:
posX -= move_unit;
break;
case GLUT_KEY_UP:
posY += move_unit;
break;
case GLUT_KEY_DOWN:
posY -= move_unit;
break;
default:
break;
}
glutPostRedisplay();
}
int main(int argc, char** argv) {
//initialize mode and open a windows in upper left corner of screen
//Windows tittle is name of program
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("Practice 1");
glutDisplayFunc(display);
init();
glutSpecialFunc(keyboardown);
glutMainLoop();
}
Modern graphics APIs simulating finite state machine. That means that before Draw calls you must fully configure (or leave default) graphics pipeline "machine":
SetStates(); // Configure pipeline state: set geometry, textures, matrices, etc.
Begin();
Draw(); // Render frame according to current pipeline configuration (state)
End(); // Swap screen buffers
In case of many objects, you can just wrap all stuff with for loop:
for( each_object )
{
SetStates(); // current object's vertex/index buffer, texture, matrices, etc.
Begin();
Draw();
End();
}
Not very efficient. Next step of improvement might include: frustum culling, instancing, vertex buffers merging, texture atlases, draw calls sorting, etc.
BTW, consider using Vertex Buffer Objects (VBOs), instead of Begin/glVertex2d/End which is deprecated
Try this:
#include <GL/glut.h>
#include <cmath>
float posX = 0, posY = -0.1, posZ = 0;
GLfloat rotation = 90.0;
double x, y, angle;
#define PI 3.1415926535898
GLint circle_points = 50;
void point()
{
glColor3f(0.0, 0.0, 1.0);
glPointSize(11.0);
glBegin(GL_POINTS);
glVertex3f(0.1, 0.1, 0.0);
glEnd();
}
void circ()
{
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_TRIANGLE_FAN);
for (int i = 0; i <= 300; i++)
{
angle = 2 * PI * i / 300;
x = cos(angle) / 20;
y = sin(angle) / 20;
glVertex2d(x, y);
}
glEnd();
}
void display()
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.0, 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
point();
glPopMatrix();
glPushMatrix();
glTranslatef(posX, posY, posZ);
circ();
glPopMatrix();
glutSwapBuffers();
}
float move_unit = 0.02f;
void keyboardown(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_RIGHT:
posX += move_unit;
break;
case GLUT_KEY_LEFT:
posX -= move_unit;
break;
case GLUT_KEY_UP:
posY += move_unit;
break;
case GLUT_KEY_DOWN:
posY -= move_unit;
break;
default:
break;
}
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(600, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("Practice 1");
glutDisplayFunc(display);
glutSpecialFunc(keyboardown);
glutMainLoop();
}