Stupid newbie problem:vertex moving
I feel really, really stupid for asking this, but...
I have a program which is supposed to draw a couple of boxes and move them around. I use glVertex3f to draw the boxes. The coordinates of each vertex are global variables which are changed to make the boxes move. For example:
glVertex3f(x,y,z);
x+=0.05f;
This works fine, except that when the box moves, there''s a ghost image of it behind it. For example, if I move the box up 1.0f it shows correctly in it''s new position, but also shows in its former position. I''m sure all the vertices are being moved (you can actually see the line between the real box and the "ghost image").
Why is this and what can I do to stop it from happening? I use glClear with every new frame but it doesn''t help.
Any help appreciated.
you should show the gl code, and the code controlong the globals. My question is: are the ghost boxes behind the authentic box "ghostlike," transparent images or are they as solid and true as the actual box?
I would have to say that if they look as real as the actual box, then you are actually rendering these boxes each fram to the buffer before each swap. If the image is transparent, then is is hardware related, or you have a state in the gl state machine turned on which enforces this effect. Im not sure if there is such an effect.
My advice is to try the exe on another computer. That and take a NeHe example file of adequate complexity to render your scene, and paste ONLY THE GL CODE into the NeHe example Src, then compile that.
By process of illimintation you will find your problem i wuold think, just a matter of time as I always tell myself.
Good luck.
I would have to say that if they look as real as the actual box, then you are actually rendering these boxes each fram to the buffer before each swap. If the image is transparent, then is is hardware related, or you have a state in the gl state machine turned on which enforces this effect. Im not sure if there is such an effect.
My advice is to try the exe on another computer. That and take a NeHe example file of adequate complexity to render your scene, and paste ONLY THE GL CODE into the NeHe example Src, then compile that.
By process of illimintation you will find your problem i wuold think, just a matter of time as I always tell myself.
Good luck.
If it can be remediedWhy be unhappy about that?If it cannot be remediedWhat is the use of being unhappy about that?It's time to put a stop to this procrastination, later. Do, or do not; there is no try.
Just had a thought.
You should mail BOTH your exe and the Src to me and I will compile and run my exe and run your exe, then we will see if it is hardware based, and If not, i might notice the flaw in the code.
Just a thought....
mail: nihil@iprimus.com.au
Man muss die Welt nicht verstehen - man muss sich darin nur zurechtfinden. - Albert Einstein
You should mail BOTH your exe and the Src to me and I will compile and run my exe and run your exe, then we will see if it is hardware based, and If not, i might notice the flaw in the code.
Just a thought....
mail: nihil@iprimus.com.au
Man muss die Welt nicht verstehen - man muss sich darin nur zurechtfinden. - Albert Einstein
If it can be remediedWhy be unhappy about that?If it cannot be remediedWhat is the use of being unhappy about that?It's time to put a stop to this procrastination, later. Do, or do not; there is no try.
I know one should always include the source when asking a question, but unfortunately I don't have an internet connection right now.
I got the source on a floppy, though, so here goes:
GLfloat ylareuna=2.0f;
GLfloat alareuna=-2.0f;
/* This is the way I introduced the variables.
They're global, and they change the way they're supposed to
Sorry for the finnish variable name
*/
glVertex3f(-4.7f,ylareuna,0.0f);
// ...
glVertex3f(-4.7f-0.5f,alareuna,0.0f);
/* Then in DrawGLScene, I draw a box like this. Basically, the
whole program is just Tutorial 5 (hope I got the number right;
it's the first one about making a 3D-object */
if(keys[VK_UP])
{
keys[VK_UP]=FALSE;
if (ylareuna < 4.0f)
{
ylareuna+=0.05f;
alareuna+=0.05f;
}
}
/* This is done in WinMain, right after checking for quit messages and ESC-key (as in NeHe's tutorials) */
Everything else in the program is exactly the way it is in the tutorials and it seems to work, except for the "ghosting". It's not actual ghosting - e.g. it's not transparent nor does it fade. It just is there and looks like the rest of the box, except that it's single-color while the actual box is smooth-shaded.
mertz: I'll e-mail the full source (the commentaries are in finnish (sorry!), but as I said, it's basically the NeHe tutorial) and the exe. I appreciate your effort.
[edited by - dEpression on September 20, 2002 12:31:40 PM]
I got the source on a floppy, though, so here goes:
GLfloat ylareuna=2.0f;
GLfloat alareuna=-2.0f;
/* This is the way I introduced the variables.
They're global, and they change the way they're supposed to
Sorry for the finnish variable name

glVertex3f(-4.7f,ylareuna,0.0f);
// ...
glVertex3f(-4.7f-0.5f,alareuna,0.0f);
/* Then in DrawGLScene, I draw a box like this. Basically, the
whole program is just Tutorial 5 (hope I got the number right;
it's the first one about making a 3D-object */
if(keys[VK_UP])
{
keys[VK_UP]=FALSE;
if (ylareuna < 4.0f)
{
ylareuna+=0.05f;
alareuna+=0.05f;
}
}
/* This is done in WinMain, right after checking for quit messages and ESC-key (as in NeHe's tutorials) */
Everything else in the program is exactly the way it is in the tutorials and it seems to work, except for the "ghosting". It's not actual ghosting - e.g. it's not transparent nor does it fade. It just is there and looks like the rest of the box, except that it's single-color while the actual box is smooth-shaded.
mertz: I'll e-mail the full source (the commentaries are in finnish (sorry!), but as I said, it's basically the NeHe tutorial) and the exe. I appreciate your effort.
[edited by - dEpression on September 20, 2002 12:31:40 PM]
I still don''t completely get what you try to explain, but...
1) Are you drawing two cube without clearing the first one. I mean, the problem still exists if you do this...
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//1st cube
glVertex3f(x,y,z);
......
......
......
//2nd cube
glVertex3f(x+4,y,z);
......
......
......
2) Maybe "glTranslatef" is more proper than moving every vertex.
GLfloat YPosition;
if(keys[VK_UP])
{
YPosition++;
}
draw() {
glTranslatef(0,YPosition,0);
//Draw Your Cube
}
(I can have a look at your code, too.. (varokasp@hotmail.com))
1) Are you drawing two cube without clearing the first one. I mean, the problem still exists if you do this...
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//1st cube
glVertex3f(x,y,z);
......
......
......
//2nd cube
glVertex3f(x+4,y,z);
......
......
......
2) Maybe "glTranslatef" is more proper than moving every vertex.
GLfloat YPosition;
if(keys[VK_UP])
{
YPosition++;
}
draw() {
glTranslatef(0,YPosition,0);
//Draw Your Cube
}
(I can have a look at your code, too.. (varokasp@hotmail.com))
I would say thats an obvious glClear problem...
Perhaps you''re running glClear at the wrong time..?
It should be the first thing you do in your DrawScene() function or whatever you call it...
Perhaps you''re running glClear at the wrong time..?
It should be the first thing you do in your DrawScene() function or whatever you call it...
Thanks to everyone for the ideas, I''ll try them out as soon as I can (I''m writing this in a sort of a hurry).
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); is the first line in my Draw-function. I tried using glTranslatef, because I thought it would be simpler, too, but couldn''t get it to work. I did it the way varokasp suggested (a global GLfloat-variable which defines the Y-position, then glTranslatef(0.0f,yposition,-10.0f); before drawing the cube. The problem with this was that the changes made to the yposition variable in WinMain didn''t have any effect on the actual scene (the cube didn''t move). The debugger showed that the variable''s value did change, the changes just didn''t reflect on the behavior of the program. At this point I was getting a bit frustrated, so maybe I missed something. I''ll try it again later.
As I said before, I don''t have an internet connection at home right now, so it''s sort of hard to try all your tips, but it shouldn''t take too long for the ADSL-guys to come and hook me up. I''ll let you know as soon as I''ve tried everything.
Thanks again for the help.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); is the first line in my Draw-function. I tried using glTranslatef, because I thought it would be simpler, too, but couldn''t get it to work. I did it the way varokasp suggested (a global GLfloat-variable which defines the Y-position, then glTranslatef(0.0f,yposition,-10.0f); before drawing the cube. The problem with this was that the changes made to the yposition variable in WinMain didn''t have any effect on the actual scene (the cube didn''t move). The debugger showed that the variable''s value did change, the changes just didn''t reflect on the behavior of the program. At this point I was getting a bit frustrated, so maybe I missed something. I''ll try it again later.
As I said before, I don''t have an internet connection at home right now, so it''s sort of hard to try all your tips, but it shouldn''t take too long for the ADSL-guys to come and hook me up. I''ll let you know as soon as I''ve tried everything.
Thanks again for the help.
Then, you should send us your code.... or post it, in details 
P.S. If glTranslatef is not working properly. See that you''re using the ModelView Matrix. I forgot to change it back one time , and the result was not very nice.
(To make sure, call glMatrixMode(GL_MODELVIEW); even before glClear(); But it is not recommended to be a permanent place )

P.S. If glTranslatef is not working properly. See that you''re using the ModelView Matrix. I forgot to change it back one time , and the result was not very nice.
(To make sure, call glMatrixMode(GL_MODELVIEW); even before glClear(); But it is not recommended to be a permanent place )
i have a similar problem....
i want to draw 100 lines and move them around.now how do i move them.
1. redraw them with black and then draw another one.
2. refresh the whole screen.
refreshing leads to flickering.
i tried to redraw with black and run it on solaris.it leaves a trail behind.but when i run on p4(linux) it is ok.how do i solve the problem.....
i want to draw 100 lines and move them around.now how do i move them.
1. redraw them with black and then draw another one.
2. refresh the whole screen.
refreshing leads to flickering.
i tried to redraw with black and run it on solaris.it leaves a trail behind.but when i run on p4(linux) it is ok.how do i solve the problem.....
Gigo:
Get 2 buffers. front and back. Clear buffer to black, Draw 100 lines, flush GL pipeline, swap buffers, repeat everything into infinity. Never any flickering anymore.
Sander Maréchal
[Lone Wolves Production][Articles][GD Emporium][E-mail]
Get 2 buffers. front and back. Clear buffer to black, Draw 100 lines, flush GL pipeline, swap buffers, repeat everything into infinity. Never any flickering anymore.
Sander Maréchal
[Lone Wolves Production][Articles][GD Emporium][E-mail]
<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement