My OGL Render Class

Started by
13 comments, last by Endar 18 years, 5 months ago
Main goals are as follows: Switch to tri's, make it so AddBasicTriToRenderer takes a tri object, instead of 80 parameters, and fix ptemp de-allocation
----------------------------------------------------------Rating me down will only make me stronger.----------------------------------------------------------
Advertisement
Looks good. As you gain more experience, you'll find different and better ways of doing things, but that's pretty good for a start up. [smile]
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
So like this :D

#include <vector>#include "Vector3.h"using namespace std;struct	BasicTri{	Vector3 P1, P2, P3;	int	Texture;	BasicTri(const BasicTri& t)	{		P1 = t.P1;		P2 = t.P2;		P3 = t.P3;		Texture = t.Texture;	}	BasicTri& operator=(const BasicTri& t)	{		if( &t != this ){			P1 = t.P1;			P2 = t.P2;			P3 = t.P3;			Texture = t.Texture;		}		return *this;	}};std::vector<BasicTri*>	mBasicTri;void	AddBasicTriToRenderer(const BasicTri& t){	BasicTri *pData = new BasicTri(t);	// then add to the vector	mBasicTri.push_back(pData);}
----------------------------------------------------------Rating me down will only make me stronger.----------------------------------------------------------
Founda few unoptimized issues with your code, replaced it with...

#include <vector>#include "Vector3.h"using namespace std;struct	BasicTri{	Vector3 P1, P2, P3;	int	Texture;	BasicTri(const BasicTri& t)	{		P1 = t.P1;		P2 = t.P2;		P3 = t.P3;		Texture = t.Texture;	}	BasicTri& operator=(const BasicTri& t)	{		if( &t != this ){			P1 = t.P1;			P2 = t.P2;			P3 = t.P3;			Texture = t.Texture;		}		return *this;	}};std::vector<BasicTri*>	mBasicTri;void	AddBasicTriToRenderer(BasicTri* t){	// then add to the vector	mBasicTri.push_back(t);}


With your AddBasicTriToRenderer function you created a new triangle when you didnt need to.. i'll show you

void	AddBasicTriToRenderer(const BasicTri& t){	BasicTri *pData = new BasicTri(t);	// then add to the vector	mBasicTri.push_back(pData);}


Is now this
void	AddBasicTriToRenderer(BasicTri* t){	// then add to the vector	mBasicTri.push_back(t);}




----------------------------------------------------------Rating me down will only make me stronger.----------------------------------------------------------
Quote:Original post by Shamino
void	AddBasicTriToRenderer(const BasicTri& t){	BasicTri *pData = new BasicTri(t);	// then add to the vector	mBasicTri.push_back(pData);}


Is now this
void	AddBasicTriToRenderer(BasicTri* t){	// then add to the vector	mBasicTri.push_back(t);}


Fair enough, if you want to do it that way, but that means that you have to pay attention and every time you add a tri to the list, you need to make sure that you create it on the heap before passing the pointer to the function. If you forget, and you pass in an address from the stack, you'll have problems when that memory is overwritten and used for something else in your program, or when you delete all the list elements, you'll get a very strange error that basically means that you tried to delete some stack memory. But, if you think you can remember to create a new one in memory before passing the point in, I have absolutely no issue with it. [smile]
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper

This topic is closed to new replies.

Advertisement