Well I have a peculiar problem. When I set my global variable screen=0.0f and I put my drawcollision_one() function in my display function it only draws a static collision sprite. However when I set my screen=0.0001f and I put my drawcollision_one() in my display function it draws an animated collision sprite. Also when I use my screen=-0.0f variable and I put my drawcollision_one() function in my collision detection function it draws a static collision sprite. However when I use my screen=0.0001f variable it does not draw anything when the drawcollision_one() function is in my collision detection function. What I want is to draw the animated collision sprite when the collision detection function is used. Let me know if you need further explanation.I am using freeglut 3.0.0 and SOIL in my program.
You’re just saying your program doesn’t do what you want it to (and what you want it to do isn’t clear), instead of asking a question about how a particular GL call works or why it’s throwing an error.
I’d suggest you cut back your program until it works consistently (e.g. disconnect the collision and timer pieces and just wire up your drawcollision function directly to your display function). Build-up gradually. If you find some behavior you don’t understand and it relates to an OpenGL call, then ask that specific question.
That doesn’t really work very well, because to animate it, you need to redraw the screen over some period of time with an updated collision appearance. And what about any other animations you might have going at the time --do they just freeze while “that” collision is being animated?
For this reason and others, I would suggest separating these two concerns: 1) detect a collision, and 2) render the collision animation. When your collision detection function detects a collision, have it create a “collision event” with the relevant state about that collision (location, time, etc.). Then, elsewhere, inside your display function, loop through the active collision events, and render the appearance of each collision event appropriate for that frame.
This has a number of advantages, including your collision detection processing need not happen in a routine called by your display() function.
It’s just a packet of state (think struct) that collects any data about the collision that you’ll need elsewhere (e.g. in your display function when displaying the animated collision sprite).
#include <iostream>
using namespace std;
int main()
{
float screen = 0.001f;
for (int i = 1; i <= 6; i++)
{
screen += 0.1667f;
cout << screen << endl;
}
system("pause");
return 0;
}
when I set the screen variable to 0.001f the collision animation works ok, but when I set the screen variable to 0.0f the collision sprite only draws the first collision sprite. when I change the screen variable in my stubbed out code I get almost the same values, I just don’t see where the problem is.
While your code uses OpenGL, you’re not asking an OpenGL question.
Rather than asking “how does this OpenGL concept work” or “why is this OpenGL API working the way it is”, you’re asking folks to figure out why your code doesn’t work.
You need to understand how your code works. If you’re unsure, step through it in a debugger and/or add print statements to show what’s going on with key values (e.g. screen in your case). Once you boil your question down to confusion with how an OpenGL API or concept works, and you aren’t able resolve this question by reading tutorials or the spec, feel free to post your question here!