• Welcome to Dark Bit Factory & Gravity.
 

Help with TinyPTC

Started by TinDragon, June 09, 2006

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

TinDragon

Hello, I am trying to get tinyptc working with a class I have made for buffers. Now the part I am stuck on is how to give the ptc_update(buffer) bit the actual buffer from my class ?

Here's the class setup code

class cBuffer
{
private:
int iXRES;
int iYRES;
int* iBuffer;
public:
//-- Constructor/Destructor
cBuffer(int iWidth,int iHeight);
~ cBuffer();
//-- Info Methods
int GetWidth(){return iXRES;}; // Return buffer width
int GetHeight(){return iYRES;}; // Return buffer width
//-- Drawing to buffer Methods
void WritePixel(int x,int y,int rgb);
void Cls(int rgb);
};


and the constructor so you can see how iBuffer is made

cBuffer::cBuffer(int iWidth,int iHeight)
{
iXRES=iWidth;
iYRES=iHeight;
iBuffer= new int[iXRES*iYRES];
}


Now I will need to add a method to get the iBuffer in such a way it matchs ptc_update's needs but I am not sure how ?

Cheers
Jon


relsoft

How about passing its addressf?

&cbuffer[0]

Challenge Trophies Won:

TinDragon

Yeah I tried a few things and think I need to pass the address of the start of the iBuffer array, if I were to pass cBuffer that would be the address of the class I think. I just dont seem to be able to get the iBuffer the way ptc_update wants, I get variuos errors but most common one has been int* from int or something like that which is I think means it wants a point but thats what I was returning so I got more confused, Been over a year since I did much c++ stuff and I aint to hot on it  :-\

Clyde

Is there anything on this in a Tiny PTC chm help file I wonder.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

TinDragon

Going to read a few chapters on pointers in C++ and see if I cant work out how to do it, I know I am close just cant get that last little bit right  >:(

parapete

hiya,

haven't used ptc in a while but if i remember right ptc_update takes an argument of type 'void pointer', so you just need to cast your integer pointer to a void pointer. ie.

ptc_update( (void*)iBuffer );

good luck.


TinDragon

Yes your right it does take a void pointer by the look of the source line for ptc_update(). I will have a go a bit later and see if I can get it working, my experience with pointers is rather limited which probably explains why I am having trouble but I have got some books with examples to have a read of and hopefully get a better understanding of pointers which are an important aspect of C++ coding   :)