Sign in to follow this  
phil67rpg

drawing sprites

Recommended Posts

	void TimerFunction(int value)
{
 glutPostRedisplay();
 glutTimerFunc(1000, TimerFunction, 1);
}
	void drawScene() {
 glClear(GL_COLOR_BUFFER_BIT);
     drawScene_bug();
 TimerFunction(1);
 eraseScene_bug();
// drawScene_bug_two();
// eraseScene_bug_two();
	drawScene_ship();
	drawScene_bullet();
 glutSwapBuffers();
}
	

Share this post


Link to post
Share on other sites
10 minutes ago, phil67rpg said:

sorry but the question is how do I draw a sprite and then wait for  a period of time and then draw another sprite over it.

Which part(s) of what you said are you having problems with?

1) Drawing the sprite.

2) Waiting for a period of time.

3) Drawing another sprite on top of it?

5 minutes ago, phil67rpg said:

also I want to erase the sprite after I draw it.

This was explained to you in a previous thread you made. Was the explanation not clear? If so, what was unclear about it?

Share this post


Link to post
Share on other sites
27 minutes ago, phil67rpg said:

I get an error with the minus sign(-) no operand matches these operators

You're going to have to provide more information about the actual code you wrote, and the exact text of the error, if anybody's going to be able to help you with that. If you are using chrono like I suggested, you should look at the example code for now() usage.

You can subtract two time_point's, which is what now() returns, and you'll get a duration. It's possible you aren't including the correct headers to use those types. Or it's also possible your compiler doesn't support C++11, in which case unfortunately chrono won't be available to you and  you'll have to use something platform-specific like QueryPerformanceCounter on Windows.

Share this post


Link to post
Share on other sites

here is the code I am using



void drawScene() {
 glClear(GL_COLOR_BUFFER_BIT);
    drawScene_bug();
 auto timeStampNow = chrono::high_resolution_clock::now();
 auto elapsed = timeStampPrevious - timeStampNow;
 eraseScene_bug();
// drawScene_bug_two();
// eraseScene_bug_two();
 drawScene_ship();
 drawScene_bullet();
 auto timeStampPrevious = timeStampNow;
 glutSwapBuffers();
}
[code]

sorry

void drawScene() {
 glClear(GL_COLOR_BUFFER_BIT);
    drawScene_bug();
 auto timeStampNow = chrono::high_resolution_clock::now();
 auto elapsed = timeStampPrevious - timeStampNow;
 eraseScene_bug();
// drawScene_bug_two();
// eraseScene_bug_two();
 drawScene_ship();
 drawScene_bullet();
 auto timeStampPrevious = timeStampNow;
 glutSwapBuffers();
}

Share this post


Link to post
Share on other sites

I am using #include <chrono> which seems to be working.

this is the error:

 8 IntelliSense: no operator "-" matches these operands
            operand types are: int - std::chrono::time_point<std::chrono::system_clock, std::chrono::system_clock::duration> c:\Users\phil6_000\Desktop\main.cpp 644 35 space5
 

Share this post


Link to post
Share on other sites

You're trying to subtract an integer (int) and a std::time_point<>. You can't. You have to subtract two time_points. "timeStampPrevious" sounds like it is an int, and it shouldn't be. It should be of type std::chono::time_point<std::chono_high_resolution_clock>, which is the return type of now().

As shown in the documentation you've been linked several times.

Share this post


Link to post
Share on other sites
Spoiler

 

auto timeStampPrevious=chrono::time_point<chrono_high_resolution_clock>;

the above code has an error of typename is not allowed. I am almost figured out this piece of code. thanks jpetrie. I am really trying to figure out this problem. I am going to do more research on this problem.

Just now, phil67rpg said:

chrono_high_resolution_clock

here is where the error is

1 minute ago, phil67rpg said:

chrono::time_point

sorry the error is also here as well

Share this post


Link to post
Share on other sites
  1. Do you know how "auto" works?
  2. Where is the "auto timeStampPrevious=chrono::time_point<chrono_high_resolution_clock>;" line located?
  3. Where did Josh tell you timeStampPrevious variable should be?

Share this post


Link to post
Share on other sites

	chrono::high_resolution_clock::time_point previous = chrono::high_resolution_clock::now();
	auto timeStampPrevious = previous;
	auto timeStampNow = chrono::high_resolution_clock::now();
	auto elapsed = timeStampPrevious - timeStampNow;
	

Share this post


Link to post
Share on other sites

I did some research on auto but I am still confused on how to output the elapsed variable to the screen. I am trying to cout the elapsed variable.

	chrono::high_resolution_clock::time_point previous = chrono::high_resolution_clock::now();
	auto timeStampPrevious = previous;
	auto timeStampNow = chrono::high_resolution_clock::now();
	auto elapsed = timeStampPrevious - timeStampNow;
	cout << elapsed << endl;
	

Share this post


Link to post
Share on other sites

here is my error

 1 IntelliSense: no operator "<<" matches these operands
            operand types are: std::ostream << std::chrono::duration<std::chrono::system_clock::rep, std::chrono::system_clock::period> c:\Users\phil6_000\Desktop\cpp24a\cpp24a\cpp24a.cpp 14 7 cpp24a
I am getting variable type conflict, the << operator does not work with chrono types.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this