Hello,
I am quite new to opengl, and this is my first discussion on this forum, I hope to not ask silly things and that this is the right section for asking this kind of things.
I am using opengl with c++ and with visual studio pro 2008.
I have to develop a code that gives in sequence a cross and then a column that have to be filled untill a specific level. Unitil now I developed the column and using a for loop I filled it. I know also how to draw a cross, but my problem is how to display them in sequence (E.G. the cross for 3 seconds and the column for 5 seconds). The code is the sequent. Thanks to all in advance.
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <GL/glut.h>
static void resize(int width, int height)
{
const float ar = (float) width / (float) height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}
static void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
unsigned int rgba = 0xFFFFFFFF; // white
unsigned int rgba1 = 0x00000000; // black
unsigned int rgba2 = 0x00EA00FF; //green
unsigned int rgba3 = 0xFF0000FF; //red
double i;
for ( i = -2.7;i < 3.8;i+= 0.001)
{
//rectangle
glBegin(GL_QUADS);
//rectangle white
glColor4f(((rgba>>24)&0xff)/255.0f,
((rgba>>16)&0xff)/255.0f,
((rgba>>8)&0xff)/255.0f,
(rgba&0xff)/255.0f);
glVertex3f(-3,-3,-10);
glVertex3f(3,-3,-10);
glVertex3f(3,4,-10);
glVertex3f(-3,4,-10);
//rectangle black
glColor4f(((rgba1>>24)&0xff)/255.0f,
((rgba1>>16)&0xff)/255.0f,
((rgba1>>8)&0xff)/255.0f,
(rgba1&0xff)/255.0f);
glVertex3f(-2.9,-2.9,-10);
glVertex3f(2.9,-2.9,-10);
glVertex3f(2.9,3.9,-10);
glVertex3f(-2.9,3.9,-10);
//rectangle feedback(green/red)
if (i<=1.5)
{
glColor4f(((rgba2>>24)&0xff)/255.0f,
((rgba2>>16)&0xff)/255.0f,
((rgba2>>8)&0xff)/255.0f,
(rgba1&0xff)/255.0f);
glVertex3f(-2.7,-2.7,-10);
glVertex3f(2.7,-2.7,-10);
glVertex3f(2.7,(i),-10);
glVertex3f(-2.7,(i),-10);
}
else
{
glColor4f(((rgba2>>24)&0xff)/255.0f,
((rgba2>>16)&0xff)/255.0f,
((rgba2>>8)&0xff)/255.0f,
(rgba2&0xff)/255.0f);
glVertex3f(-2.7,-2.7,-10);
glVertex3f(2.7,-2.7,-10);
glVertex3f(2.7,1.5,-10);
glVertex3f(-2.7,1.5,-10);
glColor4f(((rgba3>>24)&0xff)/255.0f,
((rgba3>>16)&0xff)/255.0f,
((rgba3>>8)&0xff)/255.0f,
(rgba2&0xff)/255.0f);
glVertex3f(-2.7,2,-10);
glVertex3f(2.7,2,-10);
glVertex3f(2.7,(i),-10);
glVertex3f(-2.7,(i),-10);
}
//horizontal black bar
glColor4f(((rgba>>24)&0xff)/255.0f,
((rgba>>16)&0xff)/255.0f,
((rgba>>8)&0xff)/255.0f,
(rgba&0xff)/255.0f);
glVertex3f(-3,1.5,-10);
glVertex3f(3,1.5,-10);
glVertex3f(3,2,-10);
glVertex3f(-3,2,-10);
glEnd();
glColor4f(1, 1, 1, 1);
glutSwapBuffers();
glFlush();
}
}
static void key(unsigned char key, int x, int y)
{
switch (key)
{
case 27 :
case 'q':
exit(0);
break;
}
//glutPostRedisplay();
}
static void idle(void)
{
glutPostRedisplay();
}
/* Program entry point */
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(500,500);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("task");
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutIdleFunc(idle);
glClearColor(0,0,0,0);
glutMainLoop();
return EXIT_SUCCESS;
}