Author Topic: Help with TinyPTC  (Read 5066 times)

0 Members and 1 Guest are viewing this topic.

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Help with TinyPTC
« on: June 09, 2006 »
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
Code: [Select]
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
Code: [Select]
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


Offline relsoft

  • DBF Aficionado
  • ******
  • Posts: 3303
  • Karma: 47
    • View Profile
Re: Help with TinyPTC
« Reply #1 on: June 10, 2006 »
How about passing its addressf?

&cbuffer[0]

Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: Help with TinyPTC
« Reply #2 on: June 10, 2006 »
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  :-\

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Help with TinyPTC
« Reply #3 on: June 10, 2006 »
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:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: Help with TinyPTC
« Reply #4 on: June 10, 2006 »
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  >:(

Offline parapete

  • ZX 81
  • *
  • Posts: 6
  • Karma: 2
    • View Profile
Re: Help with TinyPTC
« Reply #5 on: June 11, 2006 »
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.


Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: Help with TinyPTC
« Reply #6 on: June 11, 2006 »
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   :)