Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. OpenGL removing "objects" - how ?

OpenGL removing "objects" - how ?

Scheduled Pinned Locked Moved Graphics
questiongraphicsgame-dev
7 Posts 3 Posters 22 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    First - to avoid "confusion" - I am using term "object" to describe what is created in OpenGL in-between "new " and "end" loop code. I have a "text (object)" rendered (in OpenGL window) , I need to delete such text and replace it with another one. I do no want to translate , rotate etc. ... just delete and replace. What I have tried so far ALWAYS writes OVER the existing text and makes a mess. Is that possible in OpenGL? I think I'll try (a hack ) - moving / translating current(text) matrix off the screen.... Open to other ideas. Cheers

    G J 2 Replies Last reply
    0
    • V Vaclav_

      First - to avoid "confusion" - I am using term "object" to describe what is created in OpenGL in-between "new " and "end" loop code. I have a "text (object)" rendered (in OpenGL window) , I need to delete such text and replace it with another one. I do no want to translate , rotate etc. ... just delete and replace. What I have tried so far ALWAYS writes OVER the existing text and makes a mess. Is that possible in OpenGL? I think I'll try (a hack ) - moving / translating current(text) matrix off the screen.... Open to other ideas. Cheers

      G Offline
      G Offline
      Graham Breach
      wrote on last edited by
      #2

      This is just a wild guess because I can't see your code - are you missing a call to glClear in your render loop?

      V 1 Reply Last reply
      0
      • G Graham Breach

        This is just a wild guess because I can't see your code - are you missing a call to glClear in your render loop?

        V Offline
        V Offline
        Vaclav_
        wrote on last edited by
        #3

        As a general "rule" NOT to invite uncalled for criticism on my under construction code I am therefore very reluctant to post code. However, every rule has an exception so here is the latest implementation of "write text message" to OpenGL window. It writes the message, but in wrong position - irrelevant for now. (The disabled #ifdef / #endif code was added and that is why the message is written in wrong raster position.The raster position code must be in wrong place. ) It is my understanding that OpenGL keeps the data - bitmap in this case - in video card hardware. So to override / update the data I have to access that particular hardware . Or in another words - OpenGL "variable / object" cannot be just overwritten like C code. So I believe I need to keep track of "matrix" where the initial bitmap is written and then

        glLoadIdentity();

        should clear the entire matrix. Correct me if I am wrong, but glClear would not work SELECTIVELY , it would clear entire buffer.( I did neglected to add "selectively" to the post title )

        //display
        // normal parametrized function
        // passive
        void OpenGL_text(char *message, float x, float y, float z) {

        //#ifdef BYPASS
        printf("\nOPENGL TRACE OpenGL @function %s @line %i \n", __FUNCTION__,
        __LINE__);

        printf("\\nOPENGL TRACE STOP passed message %s @line %i\\n", message,
        \_\_LINE\_\_);
        

        //#endif passive

        char menu\[80\];
        strcpy(menu, message); // local copy ??
        int len;
        len = strlen(menu);
        glColor3f(1, 1, 1);    // white text
        

        //#ifdef BYPASS
        { // GL_PROJECTION block
        glMatrixMode( GL_PROJECTION); // ??
        glPushMatrix(); // there is only one (?)
        glLoadIdentity(); // clear projection matrix - why (?)

        	gluOrtho2D(0, 500, 0, 500);   // MN !!
        	{ // GL\_MODELVIEW block
        		glMatrixMode( GL\_MODELVIEW);
        		glPushMatrix();
        
        		glLoadIdentity();         // clear bitmap (?)
        

        //#endif
        glRasterPos3f(x, y, z); // wrong !! text start postion

        		for (int i = 0; i < len; ++i) {
        			glutBitmapCharacter(GLUT\_BITMAP\_HELVETICA\_18, menu\[i\]);
        		}
        

        //#ifdef BYPASS
        glPopMatrix(); // GL_MODELVIEW
        } // GL_MODELVIEW block
        glMatrixMode( GL_PROJECTION);
        glPopMatrix();
        } // GL_PROJECTION block
        glMatrixMode( GL_MODELVIEW);
        //#endif

        }

        G J 2 Replies Last reply
        0
        • V Vaclav_

          As a general "rule" NOT to invite uncalled for criticism on my under construction code I am therefore very reluctant to post code. However, every rule has an exception so here is the latest implementation of "write text message" to OpenGL window. It writes the message, but in wrong position - irrelevant for now. (The disabled #ifdef / #endif code was added and that is why the message is written in wrong raster position.The raster position code must be in wrong place. ) It is my understanding that OpenGL keeps the data - bitmap in this case - in video card hardware. So to override / update the data I have to access that particular hardware . Or in another words - OpenGL "variable / object" cannot be just overwritten like C code. So I believe I need to keep track of "matrix" where the initial bitmap is written and then

          glLoadIdentity();

          should clear the entire matrix. Correct me if I am wrong, but glClear would not work SELECTIVELY , it would clear entire buffer.( I did neglected to add "selectively" to the post title )

          //display
          // normal parametrized function
          // passive
          void OpenGL_text(char *message, float x, float y, float z) {

          //#ifdef BYPASS
          printf("\nOPENGL TRACE OpenGL @function %s @line %i \n", __FUNCTION__,
          __LINE__);

          printf("\\nOPENGL TRACE STOP passed message %s @line %i\\n", message,
          \_\_LINE\_\_);
          

          //#endif passive

          char menu\[80\];
          strcpy(menu, message); // local copy ??
          int len;
          len = strlen(menu);
          glColor3f(1, 1, 1);    // white text
          

          //#ifdef BYPASS
          { // GL_PROJECTION block
          glMatrixMode( GL_PROJECTION); // ??
          glPushMatrix(); // there is only one (?)
          glLoadIdentity(); // clear projection matrix - why (?)

          	gluOrtho2D(0, 500, 0, 500);   // MN !!
          	{ // GL\_MODELVIEW block
          		glMatrixMode( GL\_MODELVIEW);
          		glPushMatrix();
          
          		glLoadIdentity();         // clear bitmap (?)
          

          //#endif
          glRasterPos3f(x, y, z); // wrong !! text start postion

          		for (int i = 0; i < len; ++i) {
          			glutBitmapCharacter(GLUT\_BITMAP\_HELVETICA\_18, menu\[i\]);
          		}
          

          //#ifdef BYPASS
          glPopMatrix(); // GL_MODELVIEW
          } // GL_MODELVIEW block
          glMatrixMode( GL_PROJECTION);
          glPopMatrix();
          } // GL_PROJECTION block
          glMatrixMode( GL_MODELVIEW);
          //#endif

          }

          G Offline
          G Offline
          Graham Breach
          wrote on last edited by
          #4

          Yes, glClear does clear the whole viewport - you would then redraw all of the content for the next frame. Matrices only affect what you are going to render in the future, not what you have already sent to be rendered.

          V 1 Reply Last reply
          0
          • G Graham Breach

            Yes, glClear does clear the whole viewport - you would then redraw all of the content for the next frame. Matrices only affect what you are going to render in the future, not what you have already sent to be rendered.

            V Offline
            V Offline
            Vaclav_
            wrote on last edited by
            #5

            Since I just discover that push / pop matrix is "deprecated " clearing all maybe the only decent option anyway. Really not that hard since I keep system state... Bottom line OpenGL was not the best choise for my application. O well... Thanks

            1 Reply Last reply
            0
            • V Vaclav_

              First - to avoid "confusion" - I am using term "object" to describe what is created in OpenGL in-between "new " and "end" loop code. I have a "text (object)" rendered (in OpenGL window) , I need to delete such text and replace it with another one. I do no want to translate , rotate etc. ... just delete and replace. What I have tried so far ALWAYS writes OVER the existing text and makes a mess. Is that possible in OpenGL? I think I'll try (a hack ) - moving / translating current(text) matrix off the screen.... Open to other ideas. Cheers

              J Offline
              J Offline
              jhonaa
              wrote on last edited by
              #6

              Use bullets.erase(it);

              1 Reply Last reply
              0
              • V Vaclav_

                As a general "rule" NOT to invite uncalled for criticism on my under construction code I am therefore very reluctant to post code. However, every rule has an exception so here is the latest implementation of "write text message" to OpenGL window. It writes the message, but in wrong position - irrelevant for now. (The disabled #ifdef / #endif code was added and that is why the message is written in wrong raster position.The raster position code must be in wrong place. ) It is my understanding that OpenGL keeps the data - bitmap in this case - in video card hardware. So to override / update the data I have to access that particular hardware . Or in another words - OpenGL "variable / object" cannot be just overwritten like C code. So I believe I need to keep track of "matrix" where the initial bitmap is written and then

                glLoadIdentity();

                should clear the entire matrix. Correct me if I am wrong, but glClear would not work SELECTIVELY , it would clear entire buffer.( I did neglected to add "selectively" to the post title )

                //display
                // normal parametrized function
                // passive
                void OpenGL_text(char *message, float x, float y, float z) {

                //#ifdef BYPASS
                printf("\nOPENGL TRACE OpenGL @function %s @line %i \n", __FUNCTION__,
                __LINE__);

                printf("\\nOPENGL TRACE STOP passed message %s @line %i\\n", message,
                \_\_LINE\_\_);
                

                //#endif passive

                char menu\[80\];
                strcpy(menu, message); // local copy ??
                int len;
                len = strlen(menu);
                glColor3f(1, 1, 1);    // white text
                

                //#ifdef BYPASS
                { // GL_PROJECTION block
                glMatrixMode( GL_PROJECTION); // ??
                glPushMatrix(); // there is only one (?)
                glLoadIdentity(); // clear projection matrix - why (?)

                	gluOrtho2D(0, 500, 0, 500);   // MN !!
                	{ // GL\_MODELVIEW block
                		glMatrixMode( GL\_MODELVIEW);
                		glPushMatrix();
                
                		glLoadIdentity();         // clear bitmap (?)
                

                //#endif
                glRasterPos3f(x, y, z); // wrong !! text start postion

                		for (int i = 0; i < len; ++i) {
                			glutBitmapCharacter(GLUT\_BITMAP\_HELVETICA\_18, menu\[i\]);
                		}
                

                //#ifdef BYPASS
                glPopMatrix(); // GL_MODELVIEW
                } // GL_MODELVIEW block
                glMatrixMode( GL_PROJECTION);
                glPopMatrix();
                } // GL_PROJECTION block
                glMatrixMode( GL_MODELVIEW);
                //#endif

                }

                J Offline
                J Offline
                jhonaa
                wrote on last edited by
                #7

                Here is the class ->

                class bullet
                {
                private:
                public:
                void update();
                bool check()
                {
                if(y>=box_len/2)
                {
                return true;
                }
                return false;
                }
                void draw();
                };
                vector bullets;

                Here is the update function ->

                void update(int value)
                {
                for( typeof(bullets.begin()) it= bullets.begin(); it!= bullets.end();it++)
                {
                if((*it)!=NULL)
                {
                if(*it)->check())
                {
                delete *it;
                bullets.erase(it);
                }
                }
                }
                glutTimerFunc(10, update, 0);
                }

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups