OpenGL removing "objects" - how ?
-
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
-
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
This is just a wild guess because I can't see your code - are you missing a call to glClear in your render loop?
-
This is just a wild guess because I can't see your code - are you missing a call to glClear in your render loop?
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 postionfor (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}
-
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 postionfor (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}
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.
-
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.
-
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
-
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 postionfor (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}
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);
}