Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Texture in sequence

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    3

    Texture in sequence

    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.

    Code :
    #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;
    }

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    You could split your display function into 2 procedures - one to draw the cross and one to draw the column. Based on a flag call one or the other procedure.
    If you need to display one for a certain number of seconds you will need to create a timer to control when to change the flag. You could put the timer check at the end of the display procedure.

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    3
    Quote Originally Posted by tonyo_au View Post
    You could split your display function into 2 procedures - one to draw the cross and one to draw the column. Based on a flag call one or the other procedure.
    If you need to display one for a certain number of seconds you will need to create a timer to control when to change the flag. You could put the timer check at the end of the display procedure.
    First of all thanks for you answer, I tried in a different way but I did'n succed now I am gonna try your solution.
    Anyway what i used before was the sequent code, if I use it with only 'if' and 'else' condition It seems to work but as soon I try with the ''else if'' the pc crasch, it could be a code problem or a notebook one? Thanks in advance.
    Code :
    static void display(void)
    {
    int time,timebase=0;   
        time=glutGet(GLUT_ELAPSED_TIME);
     
    if (time - timebase < 3000)
    {..CROSS INSTRUCTION..}
     
    else if ((time - timebase >= 5000) && (time - timebase <= 10000))
        {..EMPTY COLUMN WITH LEVEL INDICATOR...}
     
    else
                    {.FILLED COLUMN..}
    }

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Unless you are copying time to timebase, this code should show you the cross for 3 sec, the filled column for 2 sec, the unfilled col for 5 sec then the filled column from then on.

    I am not sure what would cause you to crash. Possible some thing wrong if the empty column code.

    By breaking the code into procedures you can test each procedure separately then once each works separately you put the time control logic in.

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    3
    Quote Originally Posted by tonyo_au View Post
    Unless you are copying time to timebase, this code should show you the cross for 3 sec, the filled column for 2 sec, the unfilled col for 5 sec then the filled column from then on.

    I am not sure what would cause you to crash. Possible some thing wrong if the empty column code.

    By breaking the code into procedures you can test each procedure separately then once each works separately you put the time control logic in.
    Thanks for the answer!
    I used the function Sleep(milliseconds) in order to show each image for a certain time and it seems to work. After this I tried to work with list but once again my pc crash
    This is the code, there is something wrong? Thanks againg to all.
    Code :
    #include <windows.h>
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <GL/glut.h>
    #include <time.h>
     
    const int cross=1;
    const int instruction=2;
    const int feedback=3;
    unsigned int rgba = 0xFFFFFFFF; // white
    unsigned int rgba1 = 0x00000000; // black
    unsigned int rgba2 = 0x00EA00FF; //green
    unsigned int rgba3 = 0xFF0000FF; //red
    int i;
     
    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);
    	glNewList(cross,GL_COMPILE);
    		glBegin(GL_QUADS);//oriz
    		         glColor4f(((rgba>>24)&0xff)/255.0f,
    				 ((rgba>>16)&0xff)/255.0f, 
    				 ((rgba>>8)&0xff)/255.0f,
    				 (rgba&0xff)/255.0f);
    				 glVertex3f(-0.2,-1,-10);
    				 glVertex3f(0.2,-1,-10);
    				 glVertex3f(0.2,1,-10); 
    				 glVertex3f(-0.2,1,-10);
    				 glBegin(GL_QUADS);   //verticale
    			 glColor4f(((rgba>>24)&0xff)/255.0f,
                 ((rgba>>16)&0xff)/255.0f, 
                 ((rgba>>8)&0xff)/255.0f,
                 (rgba&0xff)/255.0f);
                 glVertex3f(-1,-0.2,-10);
                 glVertex3f(1,-0.2,-10);
                 glVertex3f(1,0.2,-10); 
                 glVertex3f(-1,0.2,-10);
    				 glEnd();
    				 glColor4f(1, 1, 1, 1);
                     glutSwapBuffers();
    				 glFlush();
    		Sleep(3000);
    	glEndList();
    	glNewList(instruction,GL_COMPILE_AND_EXECUTE);
    		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);
    			 //horizontal white 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();
    				 Sleep(2000);
       	glEndList();
     
    	glNewList(instruction,GL_COMPILE_AND_EXECUTE);
    		glBegin(GL_QUADS);
    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)//green part
    				{
        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// green plus red part
    				{//green
    			 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);
                 //red part
    			 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 white 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);	 
    			 glColor4f(1, 1, 1, 1);
                     glutSwapBuffers();
    				 glFlush();
    	glEndList();
    }
    void display(void)
    {
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
       glLoadIdentity() ;
       glCallList(cross);    
       glCallList(instruction);    
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •