Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


lordimmortal2

Member Since 29 Jan 2011
Offline Last Active Nov 22 2014 08:25 PM

Topics I've Started

Scissor Test Per Draw

11 October 2013 - 08:45 AM

Recently I've been finishing up clipping for my GUI, which is just now being tested. To clip something, I've been trying to use the scissor test in DX9, and I would need it to be applied per draw call (both for something passed to the sprite interface and for text). While messing around with this, I've deduced that DX9 doesn't apply the scissor test every draw call, instead it applies it when its rendering ends or is told to render everything it has. 

 

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. 

 

Is there an easier way to get the scissor test to work per-draw and if so how? If not, are there any replacements?


Updating a GUI

11 September 2013 - 12:40 AM

I'm developing a GUI system for my game and I've been in the process of redoing all of the positional information for widgets and I've run into a problem. 

 

All widgets derive from a base class - GuiObject - that contains all positional information needed for an object: widths, heights, points, bounds, etc. Whenever you modify one of these attributes, the function that changes it calls another function - Update - to make sure everything stays in sync.

 

The problem comes in when trying to extend this to the widgets themselves. A widget sometimes needs to update itself as well - maybe it needs to move a child widget around or adjust its own size based upon some children widgets. My question would be how to handle this as elegantly as possible.

 

If I were to override the Update function in my derived widget classes like so:

void Widget::Update()
{
    GuiObject::Update(); // Update the underlying GuiObject
    // Do updating of the widget itself here
}

And I tried to put a GuiObject's modification function in this overridden function, like trying to change the size of the underlying GuiObject, then it'll get stuck in an infinite loop and crash from a stack overflow:

void Widget::Update()
{
    GuiObject::Update(); // Update the underlying GuiObject
    
    SetSize(100, 100); // Set width and height to 100
}

SetSize will set the width and height of the base GuiObject, and then call Update, which resolves to the Widget::Update overridden function, which calls SetSize, which calls Update, etc.

 

I've tried various things, like splitting up the implementation of GuiObject::Update, setting a new pure virtual function in GuiObject to call at the end of Update to allow derived classes to put in specialized updating logic, but they all result in the end at an infinite loop. 

 

My current thought would be to make new functions in GuiObject that are versions of the functions that you can use to modify a GuiObject with public access, make them protected, give them a new name, not include the GuiObject::Update() call from their public counterparts, and then only call them from within the Update function of derived widget classes; but that doesn't seem very appealing because it'd be very easy to mess up (calling the public version in a derived class' Update function would result in the infinite loop) and it'd essentially double the amount of functions GuiObject has to maintain.

 

So what I'm wondering, for everyone who has made it through this moderate wall of text, is there a better way to handle automatic updating of a widget derived from a GuiObject? The least error prone way to do it would be to somehow update the widget whenever a modifying function from the GuiObject is called and I can't seem to figure out anyway to elegantly break the infinite loop.

 

Thanks for reading and I appreciate any and all replies.


Drawing Overlapped Sprites

11 September 2012 - 02:12 PM

I'm currently working with DirectX 9 (specifically the 2D portion of it) and would like to draw sprites in front of each other in a particular order.
I have tried drawing sprites from bottom to top and also using the Z coordinate of the draw function, but still nothing.

I'm probably missing something simple, but anyway you can do it with DX9 would be appreciated. Thanks for reading and any replies.

Question About Vectors

10 May 2012 - 11:49 PM

In addition to my ignorance on templates, I am also pretty dumb on std::vector =P. I can't figure this bug out as I'm not quite sure why it's not working.

TileContainer.cpp:

void TileHandler::AddTile(int row, int column, int rowSpr, int colSpr)
{
	 Tile *tile = new Tile;
	 tile->rowPos = row;
	 tile->colPos = column;
	 tile->rowSpr = rowSpr;
	 tile->colSpr = colSpr;
	 TileContainer.push_back(tile);
}

TileContainer is of type:
typedef std::vector<Tile> TileContainer;

And the error is:
Posted Image

First thought was to mess around and make tile a double pointer, and things of this nature, but nothing worked. If anyone knows what's wrong with it, your answer is very appreciated.

Template Travesty

10 May 2012 - 08:53 PM

I have some code that tries to create a linked list out of vectors and using templates for the first time I guess it's inevitable that it'll be wrong =P.

The relevance (LinkedList.h):

#pragma once
#include <vector>
#include "Main.h"
template <typename T>
int FindEmptyID(std::vector<T*> &vector)
{
if(list.empty())
	{
		return DEFAULT_ID;
	}
	else
	{
		typename std::list<T*>::iterator i = list.begin();
		int previousId = (*i)->ID();
		i++;
		for(; i != list.end(); i++)
		{
   int currentId = (*i)->ID();
			if(currentId - previousId > 1)
			{
	return previousId + 1;
			}
   previousId = currentId;
		}
  return previousId + 1;
}
}
template <typename T>
T * cLinkedList <T>::ScanListPrevious(std::vector<T*> &vector, int ID)
{
T *previous = 0;
for(typename std::list<T*>::iterator i = list.begin() ; i != list.end() ; ++i)
	{
		T *object = *i;
		if(object->ID() == ID)
		{
			return previous;
		}
		previous = object;
}
  
return 0;
}
template <typename T>
T * cLinkedList <T>::ScanList(std::vector<T*> &vector, int ID)
{
for(typename std::list<T *>::iterator i = list.begin(); i != list.end(); ++i)
	{
		T *object = *i;
		if(object->ID() == ID)
		{
			return object;
		}
	}
	return 0;
}

LinkedList.h gets called in (and used only in) TileContainer.h where it's used to typecast some things.

TileContainer.h:

#pragma once
#include "LinkedList.h"
#include "sSprite.h"

class LayerContainer
{
public:
	 int ID;
	 LayerContainer();
	 ~LayerContainer();
private:
	 LayerContainer* layers;
};

class TileContainer
{
public:
	 sSprite background, middle, foreground; // Graphical rendering of the tile
	 int rowPos, colPos; // Position of the tile
	 int rowSpr, colSpr; // Position of the sprite from the sprite sheet to render
	 int ID;
	 int layerNum;

// Function declarations
	 TileContainer();
	 ~TileContainer();
	 void AddTile(int row, int column, int size, int rowSpr, int colSpr);
	 void ChangeTileSprite(sSprite sprite, int depth, int ID);
	 void AddTileLayer(sSprite sprite, int row, int col);
	 void AddTileLayer(sSprite sprite, int ID);
private:
	 TileContainer* tiles;
};

typedef std::vector<LayerContainer> LayerContainer;
typedef std::vector<TileContainer> TileContainer;


The errors:

Posted Image

I'm not quite sure what's wrong with it and the errors don't really help me (perhaps if I knew more about templates), so if anyone could point me in the right direction it'd me much appreciated.

PARTNERS