# drawing sprites

## Recommended Posts

phil67rpg    443

	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

##### Share on other sites
Endurion    5412

Is there a question coming with this?

#### Share this post

##### Share on other sites
Khatharr    8812
Posted (edited)

Nope. This is bat country.

Edited by Khatharr

#### Share this post

##### Share on other sites
phil67rpg    443

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.

#### Share this post

##### Share on other sites
phil67rpg    443

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

#### Share this post

##### Share on other sites
Lactose    11471
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

##### Share on other sites
phil67rpg    443

lactose I am having a problem with the wait period

#### Share this post

##### Share on other sites
Lactose    11471
1 minute ago, phil67rpg said:

lactose I am having a problem with the wait period

Josh's reply covers that part.

#### Share this post

##### Share on other sites
phil67rpg    443
27 minutes ago, jpetrie said:

auto elapsed = timeStampNow - timeStampPrevious;

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

#### Share this post

##### Share on other sites
jpetrie    13162
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

##### Share on other sites
phil67rpg    443

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

##### Share on other sites
jpetrie    13162

Are you including the appropriate headers? What is the exact line of the error message and what is the exact error message?

#### Share this post

##### Share on other sites
phil67rpg    443

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

##### Share on other sites
jpetrie    13162

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

##### Share on other sites
phil67rpg    443
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

##### Share on other sites
Lactose    11471
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

##### Share on other sites
phil67rpg    443

	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

##### Share on other sites
Lactose    11471

That doesn't answer any of my questions.

#### Share this post

##### Share on other sites
phil67rpg    443

thanks jpetrie I finally figured out my problem. I had to do some research.

#### Share this post

##### Share on other sites
phil67rpg    443

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

##### Share on other sites
Kylotan    10012

You need to be more clear with the problem you're facing. What does the code you posted do? How does the output differ from what you expect?

#### Share this post

##### Share on other sites
LennyLen    5717

Have you ever considered using a library such as Allegro, SDL or SFML? They take care of how to do most of the things you ask about, which allows you to focus on what you want to do instead.

#### Share this post

##### Share on other sites
phil67rpg    443

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

##### Share on other sites
cout << elapsed

Would assume its that bit of code since its saying there << operator doesnt work with chrono types?

#### Share this post

##### Share on other sites
This topic is now closed to further replies.

• ## Partner Spotlight

• ### Similar Content

• I don't know why this is happening, in the image below you can see my current situation.
Basically I have an Utility.h header which contains wathever random stuff I think is useful at the time but don't yet deserves it's own separate file, so inside of it I've put a BaseFont class and defined it in place since I am not sure it will stay into Utility.h for long (Font is an alias for BaseFont because I wanted the internal variable name for the font to be Font, and that would collide with the class name, so that's why I have it setup like this) and right below this class, still in the header, I have a global object constructed from it so that I can use it everywhere for debug since pretty much all my .cpp #include "Utility.h". Now when I close the game I get an error that says "Breakout.exe stop working" and I tracked it down to the BaseFont destructor. On the right of the image you can see the local variable situation at that break point, which doesn't looks good...
I have some assumptions regarding the cause but I am not quite sure, can you tell me what its going wrong exactly?
FULL SIZE IMAGE

• Hi guys, I'm not quite sure how to achieve this
Here what I got so far, my GameMode class own an object of type Physics:
class Physics { private://variables GameMode* Game; public://constructors Physics(GameMode* gameRef); ~Physics(); public://methods bool IsColliding(Entity* current, ECollisionTest collisionTestType); private://methods bool BoxCollisionTest(const Rect& current, const Rect& other); }; And since all my entities have a pointer to the GameMode they can retrieve a pointer to the Physics object, so when they move they can query the Physics object to see if they collided with something, passing "this" as the object to control against all the Entities inside GameMode, like this:
//Collision Check if (PhysicsManager->IsColliding(this, ECollisionTest::EBoxCollisionTest)) { LogConsole("Collision"); } and IsColliding() goes like this:
bool Physics::IsColliding(Entity* current, ECollisionTest collisionTestType) { for (auto& E : Game->Entities) { if (current != E.get())//avoid self testing { switch (collisionTestType) { case ECollisionTest::EBoxCollisionTest: { if (BoxCollisionTest(current->GetCollisionBox(), E->GetCollisionBox())) { return true; } } break; } } } return false; } Now, there are two things I don't like about my current setup.
1) I am testing against all the entities. The paddle of the Breakout game can only move left and right, and hit either a ball or the left/right boundary, makes no sense to test it against 50 bricks at every update.
2)From inside the Paddle class I am calling "IsColliding(this, ECollisionTest::EBoxCollisionTest)" so there is the assumption that all the entities that can collide with this one require a box test. May not be the case, maybe I have a "worm" entity running on the screen and it requires another type of collision test, so the choosen function to run shouldn't relying on me explicitly saying which one is, but it should be called at runtime trough overload, based on the type of Entity being compared. So maybe the Paddle<->Ball comparison would do a BoxCollisionTest, while Paddle<->Worm comparison would do something else.
So how do I get it to work the way I want?
This is what I want:
1)Physics object is working with Entity*, and yet I need it to being able to distinguish between a Paddle* and or a Brick* or a Boundary* or a Ball* (all of this inherit from entity), a bit kind of like Unreal Engine BlueprintEditor Cast node, which allow me to say "Cast to Door" and if the thing was a door it return success, otherwise fails. Can you show me an example of how such mechanism is built, in code(C++)?
2)Physics object should just call a generic TestCollision() function between the "this" passed (the current colliding object) and all the other entities, and then the overload resolution calls the appropriate function based on the types. And yet this shouldn't fail to compile for pairs for which I don't explicitly overload, for instance I wouldn't overload for Paddle<->Brick because such comparison will never happen, so when Paddle<->Brick comparison is performed, it should just return false even though I never declared a TestCollision(Paddle* p, Brick* b).
How can this be achieved?

• By cozzie
Hi,
During the journey of creating my 2nd 3D engine, I'm basing quite some of the approaches on the Game Engine Architecture book (Jason Gregory). I've now arrived on the topic: IO.
In short, the target platforms for me are PC, XBone and PS4.
With this main assumption I thought of the following logics/ guidelines to follow:
- I can assume file/folder structures will work on all 3 platforms, when I use '/' as a folder separator
-- I will define 1 global with the base folder for the application, the rest will 'inherit' from there
(which can be anything, independent of the 'mount' or drive)
-- for now I'll create 1 subfolder with data/files that might need write access, so later on I only have to worry about 1 subfolder (settings, configs etc.).
- file extensions can be longer than 3 characters (in Linux based FreeBSD on PS4)
- all class members functions needing to load a file, shouldn't have to now about the file structure of the logical application, so they will all take a full filename string including path
(combining root + subfolder + filename and separators is then the responsibility of the caller/ calling code)
- some functions will need to be passed a folder, because contents in that folder need to be read OR I can simply define a small list of defined subfolders (under root/ base), because it won't be more then 5 to 10 folders in total (data/shaders, data/textures, data/objects, data/sound etc.)
My questions:
- what do you think about this approach?
- regarding the last point, which of the 2 options would you apply?
-- option 2 might work fine but feels a bit 'static', not very flexible (on the other hand, would you actually need flexibility here?)
Any input is appreciated, as always.
• By RubenRS
How do i open an image to use it as Texture2D information without D3DX11CreateShaderResourceViewFromFile? And how it works for different formats like (JPG, PNG, BMP, DDS,  etc.)?
I have an (512 x 512) image with font letters, also i have the position and texcoord of every letter. The main idea is that i want to obtain the image pixel info, use the position and texcoords to create a new texture with one letter and render it. Or am I wrong in something?

• this is super strange...
I have this function here:
template<typename TFirst, typename... TArgs> bool util::LogConsole(const TFirst& first, const TArgs&... rest) { std::cout << first << " "; return LogConsole(rest...); } bool util::LogConsole() { std::cout << std::endl; return false; } it's recursive, keep printing "first" and recursively sending the rest, until rest is empty and the overload taking no argument is called, which just print a newline. Ignore the bool return.
Anyway, now I have this code somewhere else:
for (auto& E : Entities) { float valx = E->GetPosition().x;//return 751 float valy = E->GetPosition().y;//return 838 LogConsole(valx, valy); } Entities is a vector<unique_ptr<Entity>> which currently only contains the derived from Entity player Paddle, so I access the Base class Entity method called GetPosition, which is the center pivot coordinates of the object.
I pass the variable to LogConsole which predictably prints:
But not I try to call LogConsole without those 2 variables inbetween, like this:
for (auto& E : Entities) { LogConsole(E->GetPosition().x, E->GetPosition().y); } and watch what kind of output I get! :
... the y value is an unreasonable value o_o
How is this even possible?! Since only the second value is being affected, my assumption is that there is some weird interplay with the second template parameter, the variadic argument...but I wasn't able to debug it even stepping trough it line by line...can anyone come with an explanation for this really strange behaviour?

• 9
• 11
• 9
• 10
• 14