Simple Draw Function, not working!

This topic is 4451 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Okay, so we have our draw function, it calls getrenderdata from everything in a vector, then draws it according to that data... Not working... First, I'll give you an example of something the vector would hold
#ifndef OBJECT_H
#define OBJECT_H
#include "MS3D.h"
#include "ObjectFactory.h"
#include "ResourceManager.h"

enum OBJECTS
{
SHIP_OBJECT
};

class Object
{
public:
virtual ~Object() {}
float locx, locy, locz;
bool MarkedForDeletion;

virtual MS3DModel *GetRenderInformation() = 0;
virtual void GetPhysicsInformation() = 0;
virtual void GetSoundInformation() = 0;
virtual void Update() = 0;

};

class Ship : public Object
{
public:

Ship(float x, float y, float z)
{
x = locx;
y = locy;
z = locz;
}

virtual MS3DModel *GetRenderInformation()
{
MS3DModel * Obj;
Obj = Models.Model1;
return Obj;
}

virtual void GetPhysicsInformation()
{

}

virtual void GetSoundInformation()
{

}

virtual void Update()
{

}

protected:

// Cross specific functions go here

};

#endif

Okay, notice how we have a GetRenderInformation() function, that houses a pointer to an MS3D model, and sets it Equal to Obj before returning it.... (this way we can do Obj->DrawMS3DModels() in our render loop) Here is an example of the Draw Function
void GLRenderer::DrawSceneObjects()
{
for (int i = 0; i<Scene_Objects.size(); i++)
{
Scene_Objects->GetRenderInformation();
Obj->DrawMS3DModels();
}
}

Simple as that, unfortunately, I get these errors...
c:\documents and settings\jonathan\desktop\renderengine\renderer.cpp(53) : error C2065: 'Obj' : undeclared identifier
c:\documents and settings\jonathan\desktop\renderengine\renderer.cpp(53) : error C2227: left of '->DrawMS3DModels' must point to class/struct/union

Now I know its something silly, any info?

Share on other sites
Try this:

void GLRenderer::DrawSceneObjects()
{
MS3DModel * Obj;
for (int i = 0; i<Scene_Objects.size(); i++)
{
Scene_Objects->GetRenderInformation();
Obj->DrawMS3DModels();
}
}

Share on other sites
c:\documents and settings\jonathan\desktop\renderengine\renderer.cpp(54) : warning C4700: local variable 'Obj' used without having been initialized

It doesn't understand that I'm setting returning a filled Obj with my GetRenderInformation function.... why?

Share on other sites
you must assigb your return value to variable

MS3DModel *Obj;
Obj = Scene_Objects->GetRenderInformation();

Share on other sites
Okay, that warning goes away, but I got no picture....

Arhg!

Share on other sites
the dirty solution ist to allocate the obj with new every time you want to get the object

MS3DModel *Obj = new MS3DModel;

Share on other sites
Now I got this
	virtual MS3DModel *GetRenderInformation()	{		return Models.Model1; // returns a pointer to a model	}

void GLRenderer::DrawSceneObjects(){	MS3DModel * Obj;	for (int i = 0; i<Scene_Objects.size(); i++)	{		Scene_Objects->GetRenderInformation();		Obj = Scene_Objects->GetRenderInformation();		Obj->DrawMS3DModels();	}}

Share on other sites
Well, could I delete it right after it is drawn so we don't have that new anymore?

Share on other sites

if you want to delete then delteit with

delete Obj;

but i don't know how your code manage the objects
I use atm linked lists so i have the objectss dinamically