My OGL Render Class
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
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]
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);}
Founda few unoptimized issues with your code, replaced it with...
With your AddBasicTriToRenderer function you created a new triangle when you didnt need to.. i'll show you
Is now this
#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);}
Quote:Original post by Shaminovoid AddBasicTriToRenderer(const BasicTri& t){ BasicTri *pData = new BasicTri(t); // then add to the vector mBasicTri.push_back(pData);}
Is now thisvoid 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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement