Making the square bigger when it moves - c++

#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 = 200.0f;
static int flag = 1;
void drawShape(void) {
float width = 58.0f;
float height = 40.0f;
glTranslatef(squareX, squareY, 0);
// test
// glScalef(0.0, 0.0, 0.0);
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();
}
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);
}
int state = 1;
void update(int value) {
if (state == 1) { // 1 : move right
squareX += 1.0f;
if (squareX > 400.0) {
state = 0;
}
}
glutPostRedisplay();
glutTimerFunc(25, update, 0);
}
void display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
drawShape();
glutSwapBuffers();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(400, 400);
glutCreateWindow("Moving Square");
initRendering();
glutDisplayFunc(display);
glutReshapeFunc(handleResize);
glutTimerFunc(25, update, 0);
glutMainLoop();
return(0);
}
I want to make the square get bigger while it is moving to the right. See the second GIF below. I know that I need glScalef to make the square bigger but I don't know how to make it bigger while it is moving.
Code preview:
I need it to do something similar to this (sorry about the quality, I created the GIF myself):

Use glScale to scale the rectangle dependent on the X position (squareX):
float rectScale = 1.0f + (squareX / 400.0f);
glScalef(rectScale, rectScale, 1.0f);
Note squareX is in range [0.0, 400.0], so 1.0f + (squareX / 400.0f) is in range [1.0, 2.0].
First the scaling has to be applied to the rectangle. This means it has to be the last operation, which is applied to the model view matrix, before the rectangle is drawn. the final function drawShape may look like this:
void drawShape(void) {
float width = 58.0f;
float height = 40.0f;
glTranslatef(squareX, squareY, 0);
float rectScale = 1.0f + (squareX / 400.0f);
glScalef(rectScale, rectScale, 1.0f);
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();
}
Preview:

Related

Performance drop with GL_LINES?

I tried to draw a simple line in OpenGL:
#include "stdafx.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <freeglut.h>
float startX = -180.0f;
float startZ = -100.0f;
float qtyX = 36;
float qtyZ = 20;
float red = 0.0f, green = 0.0f, blue = 0.0f;
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0.0, 50.0f, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0);
glBegin(GL_LINES);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(50.0f, 50.0f, 50.0f);
glEnd();
//glutWireSphere(20.0f, 20.0f, 20.0f);
glutSwapBuffers();
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-64.0, 64.0, -36.0, 36.0, 10, 10000.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(1280, 720);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
However, when I run the program, the performance drop significantly then after a few seconds, it stops responding (I have to run task manager and force quit the program). However, when I disable the line and draw the glutWireSphere (or a polygon), the performance is normal.
Is there a problem with my code? Or perhaps GL_LINES is deprecated?
Windows 10, 1070 MaxQ, Visual Studio

Distorted output when I apply projection OpenGL

I'm trying to implement camera functionality on a simple scene but the output is distored. I think it has something to do with perspective projection or maybe I'm using the gluLookAt() function wrong but I can't seem to pinpoint the problem. Whenever I press the arrow keys to more the camera the view keeps getting distorted. The camera code works fine in another example. I've used the exact same code with the display replaced for my scene. I have tried different arguments for gluLookAt() and even tried ortho projection but nothing seems to work.
Before camera implementation:
After camera implementation:
Code:
#include <Windows.h>
#include <math.h>
#include "glut.h"
float angle = 0.0f;
float lx = 0.0f, lz = -0.1f;
float x = 0.0f, z = 0.5f;
float deltaAngle = 0.0f;
float deltaMove = 0;
double rot = 0;
double doorAngle = 0;
double carMove = -0.75; //Initially car positioned at the start of road
void myInit(void)
{
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(1000, 480);
glutInitWindowPosition(100, 150);
glutCreateWindow(" project part1 ");
glClearColor(0.333, 0.725, 0.905, 0);
glColor3f(0.0f, 0.0f, 0.0f);
}
void reshape(int w, int h) {
if (h == 0)
h = 1;
float ratio = w* 1.0 / h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(45.0f, ratio, 0.1f, 20.0f);
glMatrixMode(GL_MODELVIEW);
}
void computePos(float deltaMove) //compute camera position
{
x += deltaMove * lx * 0.1f;
z += deltaMove * lz * 0.1f;
}
void computeDir(float deltaAngle)//compute camra direction
{
angle += deltaAngle;
lx = sin(angle);
lz = -cos(angle);
}
void display(void)
{
if (deltaMove)
computePos(deltaMove);
if (deltaAngle)
computeDir(deltaAngle);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(x, 0.0f, z, x + lx, 0.0f, z + lz, 0.0f, 1.0f, 0.0f);
//display quads road
glPushMatrix();
glLineWidth(3.0);
glColor3f(0.474, 0.552, 0.603);
glBegin(GL_QUADS);//grey road
glTexCoord2f(0.0, 0.0);
glVertex3f(-1, 0, 0);
glTexCoord2f(0.0, 1.0);
glVertex3f(1, 0, 0);
glTexCoord2f(1.0, 1.0);
glVertex3f(1, -1, 0);
glTexCoord2f(1.0, 0.0);
glVertex3f(-1, -1, 0);
glEnd();
//green grass above
glColor3f(0.305, 0.513, 0.341);
glBegin(GL_QUADS);
glVertex3f(-1, 0, 0);
glVertex3f(1, 0, 0);
glVertex3f(1, -0.1, 0);
glVertex3f(-1, -0.1, 0);
glEnd();
//green grass below
glColor3f(0.372, 0.407, 0.070);
glBegin(GL_QUADS);
glVertex3f(-1, -1, 0);
glVertex3f(1, -1, 0);
glVertex3f(1, -0.8, 0);
glVertex3f(-1, -0.8, 0);
glEnd();
//white lines on road
glColor3f(0.929, 0.850, 0.850);
glPointSize(5.0);
int factor = 10; GLushort pattern = 0x3333;
glEnable(GL_LINE_STIPPLE);
glLineStipple(factor, pattern);
glBegin(GL_LINES);
glVertex3f(1, -0.45, 0);
glVertex3f(-1, -0.45, 0);
glEnd();
glDisable(GL_LINE_STIPPLE);
glColor3f(0.929, 0.850, 0.850);
glPointSize(5.0);
glBegin(GL_LINES);
glVertex3f(1, -0.75, 0);
glVertex3f(-1, -0.75, 0);
glVertex3f(1, -0.15, 0);
glVertex3f(-1, -0.15, 0);
glEnd();
glPushMatrix();
glTranslatef(-0.8, 0.4, 0);
glScalef(0.5, 0.45, 0);
building(0, 0.17, 0.394);
glPopMatrix();
glPushMatrix();
glTranslatef(-0.35, 0.27, 0);
glScalef(0.55, 0.3, 0);
building(0.552, 0.266, 0.505);
glPopMatrix();
glPushMatrix();
//glLoadIdentity();
glTranslatef(0.2, 0.45, 0);
glScalef(1.2, 0.5, 0);
building(0.294, 0.337, 0.584);
glPopMatrix();
glPushMatrix();
glTranslatef(0.75, 0.27, 0);
glScalef(0.55, 0.3, 0);
building(0.309, 0.396, 0.427);
glPopMatrix();
//building bases
//car1
glPushMatrix();
glTranslatef(carMove, -0.2, 0);
glScalef(0.5, 0.5, 0.5);
car(0.65, 0, 0);
glPopMatrix();
glutSwapBuffers();
}
void pressKey(int key, int xx, int yy) {
switch (key) {
case GLUT_KEY_LEFT:
if (deltaAngle > 30)
break;
deltaAngle = -0.01f;
glutPostRedisplay();
break;
case GLUT_KEY_RIGHT: deltaAngle = 0.01f; break;
case GLUT_KEY_UP: deltaMove = 0.05f; break;
case GLUT_KEY_DOWN: deltaMove = -0.05f; break;
}
}
void releaseKey(int key, int x, int y) {
switch (key) {
case GLUT_KEY_LEFT:
case GLUT_KEY_RIGHT: deltaAngle = 0.0f; break;
case GLUT_KEY_UP:
case GLUT_KEY_DOWN: deltaMove = 0; break;
}
}
void main(int argc, char **argv)
{
glutInit(&argc, argv);
myInit();
glutDisplayFunc(display);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(display);
glutSpecialFunc(pressKey);
glutSpecialUpFunc(releaseKey);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
}
Note:
The texture mapping car and building code have been excluded for being too large but they work fine and I don't think that they're the problem. If you require the full working code then kindly let me know and I'll upload it. I've been stuck at this problem a while. Any help is appreciated
The issue is a Z-fighting issue.
To solve you issue you have to disable the Depth Test and draw the objects form the back to the front:
glEnable(GL_DEPTH_TEST)
Or you have to draw the object with a different z coordinates, which define the z order of the object.
Note, in view space the z axis points out of the viewport. So if the z coordinate of an object is greater than that of an other object, then the object is in front of the other object.
A perspective effect can only be achieved if the depth of the objects is different, so that object in the behind appear smaller, than that object which are closer to the point of view (eye position).
But you have to ensure that the objects are not clipped.
This mean the (view space) z distance of the object to the eye position (first 3 parameters of gluLookAt) has to be in between the near and far plane (last 2 parameters of gluPerspective).

How to display text over rectangle in OpenGL in C++?

My code looks like this Modification in this code will be appreciated. I tried, only rectangle appears not the text.
#include <GL/glut.h>
#include<bits/stdc++.h>
using namespace std;
void init2D(float r, float g, float b)
{
glClearColor(r, g, b, 0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 600.0, 0.0, 600.0);
}
void RenderToDisplay()
{
int l,lenghOfQuote, i;
char str[80];
strcpy(str,"Have courage and be kind");
cout<<str;
lenghOfQuote = (int)strlen(str);
for (i = 0; i < lenghOfQuote; i++)
{
glColor3f(1.0, 0.0, 0.0);
glutStrokeCharacter(GLUT_STROKE_ROMAN, str[i]);
}
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex3f(150.0f, 200.0f, 0.0f);
glColor3f(0.940, 0.37, 0.47);
glVertex3f(450.0f, 200.0f, 0.0f);
glColor3f(0.940, 0.37, 0.47);
glVertex3f(450.0f, 400.0f, 0.0f);
glColor3f(0.69, 0.27, 0.57);
glVertex3f(150.0f, 400.0f, 0.0f);
glColor3f(0.69, 0.27, 0.57);
glEnd();
RenderToDisplay();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(0,0);
glLineWidth(3);
glutCreateWindow("Assignment Q2");
init2D(0.0, 0.0, 0.0);
glutDisplayFunc(display);
glutMainLoop();
}
You could tell me the comments if you need to ask anything else. I used codeblocks to test this program.
Okay after a day I got it, I'm so dumb :')
#ifdef __APPLE_CC__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
void init2D(float r, float g, float b)
{
glClearColor(r, g, b, 0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 600.0, 0.0, 600.0);
}
void rectangle()
{
glBegin(GL_POLYGON);
glColor3f(0.4,0,0.8);
glVertex3f(150.0f, 200.0f, 0.0f);
glColor3f(0.4,0,0.8);
glVertex3f(450.0f, 200.0f, 0.0f);
glColor3f(0.6,0,0.6);
glVertex3f(450.0f, 400.0f, 0.0f);
glColor3f(0.6,0,0.6);
glVertex3f(150.0f, 400.0f, 0.0f);
glEnd();
}
void text()
{
char menu[80];
strcpy(menu,"Have courage and be kind");
int len;
len = strlen(menu);
glColor3f(1,1,1);
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
gluOrtho2D( 0, 600, 0, 600 );
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
glRasterPos2i(190, 300);
for ( int i = 0; i < len; ++i )
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, menu[i]);
}
glPopMatrix();
glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
rectangle();
text();
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(0, 0);
glutInitWindowSize(600, 600);
glutCreateWindow("Assignment 1 Question 2");
init2D(0.0f, 0.0f, 0.0f);
glutDisplayFunc(display);
glutMainLoop();
}

OpenGL show object on the screen

I just started learning OpenGL so I have problem with showing the object on the screen.
Display() contains this object and I want to show this one by glutDisplayFunc(Display); but it's not working, I have only grey screen after compiling. (Yeah, this object is wheel)
#include "stdafx.h"
#include <math.h>
#include <GL/freeglut.h>
GLint Width = 1024, Height = 640;
const int CubeSize = 500;
void Display (void) {
glClearColor (0.7, 0.7, 0.7, 1);
glClear (GL_COLOR_BUFFER_BIT);
glColor3ub (255, 200, 200);
int iTimeElapsed = glutGet(GLUT_ELAPSED_TIME);
float fRevolveScale1 = 0.2f;
float fRevolveScale2 = 0.4f;
long i;
// clear all pixels
glClear(GL_COLOR_BUFFER_BIT);
// push temp state
glPushMatrix();
// translate to center
glTranslatef(0.5f, 0.5f, 0.0);
// rotate around pivot
glRotatef(iTimeElapsed * fRevolveScale1, 0.0, 0.0, 1.0);
// translate to planet location
glTranslatef(0.25f, 0.25f, 0.0);
glRotatef(iTimeElapsed * fRevolveScale2, 0.0, 0.0, 1.0);
glColor3f(0.129412f, 0.129412f, 0.129412f);
glutSolidSphere(0.1f, 16, 16);
// five bolts, step 72 degree (72*5=360 degree)
glColor3f(1.0, 1.0, 1.0);
for (i = 0; i<5; ++i)
{
glPushMatrix();
glRotatef(72.0f*i, 0.0, 0.0, 1.0); // rotate coordinate 72 degree
glTranslatef(0.04f, 0.0, 0.0);// translate on the rotated coordinate
glutSolidSphere(0.01f, 16, 16);
glPopMatrix();
}
glTranslatef(0.0f, 0.0f, 0.0f);// translate on the rotated coordinate
glutSolidSphere(0.01, 16, 16);
// pop temp state
glPopMatrix();
glFlush();
glutPostRedisplay();
glFinish ();
}
void Reshape(GLint w, GLint h) {
Width = w, Height = h;
glViewport (0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity ();
glOrtho (0, w, 0, h, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity ();
}
void Keyboard(unsigned char key, int x, int y) {
const char ESCAPE = '\033 ';
if (key == ESCAPE) exit (0);
}
void main(int argc, char *argv []) {
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_RGB);
glutInitWindowSize (Width, Height);
glutCreateWindow("E X A M P L E");
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
glutKeyboardFunc(Keyboard);
glutMainLoop ();
}

OpenGL C++ Depth buffer not working

I've been testing with OpenGL for a while and have not been able to get the depth buffer to work, despite using GLUT_DEPTH as a parameter in glutInitDisplayMode and doing glClear(GL_DEPTH_BUFFER_BIT) at the start of the display function. I don't know what else I'm missing.
Below is a minimum working example and Figure 1 and 2. Comment out the parameters under Figure 1 and 2 when you want to view the other one.
Figure 1 (above blue):
Figure 2 (below red):
Example:
#include <vector>
#include <gl\glut.h>
typedef std::vector<float> floatvec;
// Figure 1 (above blue)
float posX = 8.00f;
float posY = 7.54f;
float posZ = -0.89f;
float angleX = 300.50f;
float angleY = 45.33f;
// Figure 2 (below red)
float posX = 4.12f;
float posY = -4.87f;
float posZ = -3.84f;
float angleX = 343.25f;
float angleY = -45.00f;
int screenW = 720;
int screenH = 540;
float fMin = 0.5;
float fMax = 100.0;
float alpha = 60.0;
// Draws a rectangle in 3D
void DrawQuad(floatvec c) {
glBegin(GL_QUADS);
glVertex3f(-c[0], -c[1], -c[2]);
glVertex3f(-c[3], -c[4], -c[5]);
glVertex3f(-c[6], -c[7], -c[8]);
glVertex3f(-c[9], -c[10], -c[11]);
glEnd();
}
void Display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
glRotatef(angleY, 1.0f, 0.0f, 0.0f);
glRotatef(angleX, 0.0f, 1.0f, 0.0f);
glRotatef(180.0, 0.0f, 0.0f, 1.0f);
glTranslatef(posX, posY, posZ);
// Draws the tiles
glColor3f(1.0, 0.0, 0.0); // Red
DrawQuad({ 0, 0, 0,
5, 0, 0,
5, 0, 5,
0, 0, 5 });
glColor3f(0.0, 0.0, 1.0); // Blue
DrawQuad({ 0, 3, 0,
5, 3, 0,
5, 3, 5,
0, 3, 5 });
glPopMatrix();
glutSwapBuffers();
}
void Reshape(int width, int height) {
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(alpha, (GLfloat)width / (GLfloat)height, fMin, fMax);
glMatrixMode(GL_MODELVIEW);
}
int main(int iArgc, char** cppArgv) {
glutInit(&iArgc, cppArgv);
glEnable(GL_DEPTH_TEST);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(screenW, screenH);
glutCreateWindow("Example");
glutDisplayFunc(Display);
glutIdleFunc(Display);
glutReshapeFunc(Reshape);
glutMainLoop();
return 0;
}
You just need to change where you call glEnable(GL_DEPTH_TEST);
Put it after glutCreateWindow and it will work fine.
Something like this:
int main(int iArgc, char** cppArgv) {
glutInit(&iArgc, cppArgv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(screenW, screenH);
glutCreateWindow("Example");
glEnable(GL_DEPTH_TEST);
glutDisplayFunc(Display);
glutIdleFunc(Display);
glutReshapeFunc(Reshape);
glutMainLoop();
return 0;
}
Just tested here and it worked.
I am a little bit rusty in OpenGL, but, putting the glEnable line in the Display function will make the trick.
#include <vector>
#include <GL/glut.h>
typedef std::vector<float> floatvec;
//Figure 1 (above blue)
//float posX = 8.00f;
//float posY = 7.54f;
//float posZ = -0.89f;
//float angleX = 300.50f;
//float angleY = 45.33f;
// Figure 2 (below red)
float posX = 4.12f;
float posY = -4.87f;
float posZ = -3.84f;
float angleX = 343.25f;
float angleY = -45.00f;
int screenW = 720;
int screenH = 540;
float fMin = 0.5;
float fMax = 100.0;
float alpha = 60.0;
// Draws a rectangle in 3D
void DrawQuad(floatvec c) {
glBegin(GL_QUADS);
glVertex3f(-c[0], -c[1], -c[2]);
glVertex3f(-c[3], -c[4], -c[5]);
glVertex3f(-c[6], -c[7], -c[8]);
glVertex3f(-c[9], -c[10], -c[11]);
glEnd();
}
void Display() {
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
glRotatef(angleY, 1.0f, 0.0f, 0.0f);
glRotatef(angleX, 0.0f, 1.0f, 0.0f);
glRotatef(180.0, 0.0f, 0.0f, 1.0f);
glTranslatef(posX, posY, posZ);
// Draws the tiles
glColor3f(1.0, 0.0, 0.0); // Red
DrawQuad({ 0, 0, 0,
5, 0, 0,
5, 0, 5,
0, 0, 5 });
glColor3f(0.0, 0.0, 1.0); // Blue
DrawQuad({ 0, 3, 0,
5, 3, 0,
5, 3, 5,
0, 3, 5 });
glPopMatrix();
glutSwapBuffers();
}
void Reshape(int width, int height) {
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(alpha, (GLfloat)width / (GLfloat)height, fMin, fMax);
glMatrixMode(GL_MODELVIEW);
}
int main(int iArgc, char** cppArgv) {
glutInit(&iArgc, cppArgv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(screenW, screenH);
glutCreateWindow("Example");
glutDisplayFunc(Display);
glutIdleFunc(Display);
glutReshapeFunc(Reshape);
glutMainLoop();
return 0;
}