Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 11 Jul 2010
Offline Last Active May 05 2015 11:07 AM

#4946827 Help about design a Render Class

Posted by on 06 June 2012 - 12:17 PM

I did something similiar what you have proposing to do, but at time i had some issues about Text class, because of some specifics attributes and implementations.

Thinking now, i can solve some problems, for example, implementing SetText for preparing data of model object, and passing that object for Video class to render.

Implementing this way, can solve most of problems: dependency, virtual methods, and separated implementation for each type.
Concentrated implementation i think will more easy to make some 'Sprite' (now treated as Model) Batch by texture.

So now i can have class Model like this.
class Model
		 vector<Position> position; // x y
		  vector<Position> text_cord; // u v
		  vector<Color> color;  
		  Texture* texture;

	 	 //Or make some Vertex class with each of this attributes and create vector<Vertex> object here

class Text
		 Model model;
	 	 Font* font; //Font class have pointer for Texture
		 void SetText( String text )
				//acesssing object model atributes for preparing data to pass to vertex buffer in future,
				//based on each char of text
	 	 const Model& GetModel(); //to pass to Video
//So in my Video (or Render) class everything will be handled like a model
class Video
	 	 vector<Model*> models; //Reference of all models objects to be rendered
	 	 void AddToDraw(const Model& model) //Or simply call this 'Draw' not 'AddToDraw'
	 	 //At end of loop i call
	 	 void Render()
	 	 	 //1º >> Calculate the size of Vertex e Index Buffer here(i using one BIG dynamic for both) based on size of Models
	 	 	 //check for current size, if necessary recreate Vertex Buffer and Index Buffer with incresed size - One time by Loop

	 	 	 //2º >> Pass geometry data to Vertex and Index Buffer using Lock in both - One time by Loop
	 	 	 //there is some problem locking both at same time, to iterate over models one time, not two separately for each Buffer?
	 	 	 //3º >> The actual code for rendering models: process matrix, check for texture will be used
	 	 	 //Vertex Buffer position (SetStreamSource) and Vertex Declaration, shader etc...
	 	 	 //Clean Model List for next loop

int main()
	 //Loading model geometry