Jump to content

  • Log In with Google      Sign In   
  • Create Account

lordimmortal2

Member Since 29 Jan 2011
Offline Last Active Dec 04 2014 08:56 PM

Posts I've Made

In Topic: Scissor Test Per Draw

11 October 2013 - 07:19 PM

 


So, the only way I've gotten the scissor test to work is by calling flush immediately after I draw the sprite, but this wouldn't work with my text objects (on account of the ID3DXFont interface not allowing you to prematurely flush the text to the screen, unless there's something I'm missing), so this isn't a sufficient solution.

 

From what I recall, you can pass in a ID3DXSprite-Pointer to the ID3DXFonts draw method, in which case flushing the text will be drawn in respect to the sprite - you'd want to do that anyway, since it will speed up text rendering, and it should also fix your issue. Unfortunately there really is no other way then to flush whenever you change the clip rect. The only way around it would be to implement your own sprite renderer with a software clip rect, but this tends to be slightly slower than the hardware-equivalent. Yet, if doing so enables you to draw ALL sprites like from your gui in one draw call instead of multiple ones needed in case of the ID3DXSprite, the price might be well worth paying and can actually result in a speedup.

 

Oh wow. I was already passing in a ID3DXSprite pointer to the ID3DXFonts draw. I guess I didn't put two and two together and realize that it was doing that to actually draw the text =P. I guess I'll just flush every time I need to scissor clip these things. Thanks for the answer, it's working now.


In Topic: Updating a GUI

11 September 2013 - 07:36 AM

 

 

Your problem lies in the fact that SetSize calls Update, so if you use these in each other then you have created an infinte loop and the only way to break that is to not call one of them.

 

It is best to not call Update from SetSize and let Update deal with these changes on the next frame, you won't notice a 1-2 frame delay on 30FPS.

That would indeed work. What would be the best way to do this? Push the object into a container to be iterated through next frame with its changes marked somehow?

 

Just mark the object as dirty and look for that in the update function, if it is dirty it might also need to check the children. Reset the flag after that update iteration and continue on as usual.

 

Done. And it works. Thanks a bunch for the help.


In Topic: Updating a GUI

11 September 2013 - 03:02 AM

Your problem lies in the fact that SetSize calls Update, so if you use these in each other then you have created an infinte loop and the only way to break that is to not call one of them.

 

It is best to not call Update from SetSize and let Update deal with these changes on the next frame, you won't notice a 1-2 frame delay on 30FPS.

That would indeed work. What would be the best way to do this? Push the object into a container to be iterated through next frame with its changes marked somehow?


In Topic: Drawing Overlapped Sprites

12 September 2012 - 07:03 PM

Which functions are you using to draw?
DrawPrimitive ?

Are you using any Dx9 wrappers or just raw directx?


There's always something I'm not clear enough on. This is specifically just a 2D game, and I'm using the sprite method of DirectX along with the draw function. I'm not drawing with textured quads.

As for if I'm using any DX9 wrappers or just raw DirectX, if I understand you correctly it's the latter. I've created everything besides the calls to the DX and Windows APIs.

Please elaborate on what "nothing" means: none of the sprites show up, or their order is incorrect?
Can you get a single sprite to show up?


I'm sorry that was really horribly worded. To elaborate - I can get things to draw, and sometimes they draw in the correct order but other times they don't. Right now, just for test purposes I have a background sprite draw behind all the GUI elements I need to draw for the main menu, but when I try to draw my options menu within the actual game, it gets drawn behind everything else. I'm drawing everything in the order of bottom to top, from the main menu to the game.

Specifically what I'm looking for is just a simplistic list of what you're supposed to do to get this to work, ideally with the z-coordinate.

If you disable reading/checking the depth buffer, and draw your sprites far-to-near, you're doing what you intend to. I would also like to know what you mean by "nothing"
And, not to nitpick, but there really is no "2D portion of DX9". It typically depends on the projection matrix how things are displayed, though. I understand what you're saying...


Again, really horribly worded. I'm not using textured quads to render any of this stuff, just draw calls to a "LPD3DXSPRITE". And by "nothing" I meant "it's not doing what I want it to do, IE drawing things behind something I don't want it to." I need to work on my choice of words.

In Topic: Question About Vectors

11 May 2012 - 10:00 PM

This looks like basic mistake.
TileContainer is a class, not variable, and you cannot store objects in a class, they're stored in an object.

I think you want to do this:

TileContainer myTileContainer; // probably should be member of TileHandler, not local variable
myTileContainer.push_back(tile);


I believe this fixed it (at least it compiled correctly when I changed it to something like this). Thank you for your help =).

You've got a vector of Tile, but you're trying to push_back a Tile* (pointer to Tile).

Perhaps try changing your code to:

Tile tile;
tile.rowPos = row;
tile.colPos = column;
tile.rowSpr = rowSpr;
tile.colSpr = colSpr;
TileContainer.push_back(tile);

The whole point of vector is so that you don't have to use pointers and new/delete to store things in an array. All of the heap memory is automatically allocated/deallocated for you by the vector class. Perhaps I'm misreading what you're trying to do, but it doesn't seem like pointers are at all necessary here.


This is for adding a new tile for my engine to render. The way I'm at least attempting to do it right now is create a new struct of a tile, pushing that into a vector, and then iterating along the vector to render all tiles.

Posted Imagetaby, on 11 May 2012 - 12:07 AM, said:

You've got a vector of Tile, but you're trying to push_back a Tile* (pointer to Tile).

Perhaps try changing your code to:

Tile tile;
tile.rowPos = row;
tile.colPos = column;
tile.rowSpr = rowSpr;
tile.colSpr = colSpr;
TileContainer.push_back(tile);

The whole point of vector is so that you don't have to use pointers and new/delete to store things in an array. All of the heap memory is automatically allocated/deallocated for you by the vector class. Perhaps I'm misreading what you're trying to do, but it doesn't seem like pointers are at all necessary here.

That is part of the problem yes and the cause of the compile error but as soon as the compile error is fixed another one should pop up informing you that you are using a class definition as a variable. To fix that one have a look at the Ripiz post above as that solution will fix your next problem.

For all STL containers, the object value you are trying to put into the container must match the type definition of the container, eg:
std::vector<int> m_intVector; //This can only hold variable of type int
std::vector<int*> m_intPointerVector; //This will only hold variables of type int*

Be carefull with deep and shallow copies of data you push into the vector as the vector will actual make a copy of the object you pass in to push_back and store that in the vector.


So can I assume that I'm doing something else wrong more so than trying to use a data type as an object of this data type? =P

First thing:

TileContainer
is just a redefinition of
std::vector<Tile>
. So you need to create a TileContainer:
TileContainer tileContainer;

Second thing:

you declare TileContainer to hold a Tile. You then declare a Tile pointer (Tile*) and then dynamically allocate memory for a Tile (new Tile()). Your vector container does not store Tile*, so you would need to need to either do:

Tile tile;
...
...
tileContainer.push_back(tile);

or do:
tileContainer.push_back(*tile); // dereference the pointer to put a copy of the object into the vector
delete tile;


Thanks for the catch, really would be bad to have that memory leak in there =P.

Posted Imagetaby, on 11 May 2012 - 02:49 PM, said:

Clearly I missed something here, because everyone is talking about TileContainer being a class and not a variable? Where was the class defined? What the?

The typedef enables the alternative name TileContainer to be used instead of the more verbose std::vector<Tile*>:

typedef std::vector<Tile> TileContainer;

So either the OP intended to declare a variable but mistakenly added the typedef keyword, or he/she forgot to declare a (member) variable of type TileContainer (or std:vector<Tile*>) alltogether.


It was the latter. Stared at this for 20 minutes and nothing popped into my head about what was wrong...been so long since I've programmed last.

Thanks everyone for your help I really appreciate it =). I'll post again if I have anymore questions.

PARTNERS