Author Topic: How to link to tinyptc?  (Read 10229 times)

0 Members and 1 Guest are viewing this topic.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
How to link to tinyptc?
« on: October 14, 2007 »
I am hitting a brickwall here with this library I cant seem to build the .lib file from the files that came with tinyptc, I tried to link to a static library but the compiler complains that tinyptc doesnt exist, I even tried including the library directly in the project itself, still no joy. Has anyone got a precompiled tinyptc.lib that I could use or perhaps some info explaining how to link to it as a static library

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: How to link to tinyptc?
« Reply #1 on: October 14, 2007 »
You can take the freebasic library and rename it from .a to .lib, or you can use any of the ones posted here that have .lib at the end.
You didn't say what compiler you're using.
In Visual Studio, go to
Project->Properties->Configuration Properties->Linker->Input->Additional Dependencies
and in the box you add in the libraryname, eg. libtinyptc.a or tinyptc.lib or whatever your file is called.  If you need more than one lib in there, separate them with ';'.  Put the lib in with your source code.
In devc++, go to
Project->Project Options->Parameters->Add Library or Objects
and then browse to the library file you want to add.

Jim
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: How to link to tinyptc?
« Reply #2 on: October 15, 2007 »
I tried these settings for both Visual Studio and DevC++ before I posted and Im still getting link errors. I even got a link error saying ddraw.h not found (there is no ddraw.h supplied with tinyptc) but I mostly get errors like this in Visual Studio :
Code: [Select]
unresolved external symbol "void __cdecl ptc_close(void)" (?ptc_close@@YAXXZ) referenced in function _main
unresolved external symbol "int __cdecl ptc_update(void *)" (?ptc_update@@YAHPAX@Z) referenced in function _main
unresolved external symbol "int __cdecl ptc_open(char *,int,int)" (?ptc_open@@YAHPADHH@Z) referenced in function _main
in DevC++ there are far more link errors in addition to the above the list is actually so long I wont post it. the code I am testing the library with is test.cpp the same unedited one that came with the library. Im using the windows version of tinyptc v8.0

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: How to link to tinyptc?
« Reply #3 on: October 16, 2007 »
If you use the lib, you don't need any of the ptc source files (.c, .cpp, .h) - you just need the .lib (or the .a).  Basically, ddraw.h is part of DirectX that's used inside the library.  So get rid of that lot.
If you are coding in C++, then you will need to add something like
Code: [Select]
extern "C" void ptc_close(void);
extern "C" int ptc_update(void *);
extern "C" int ptc_open(char *, int,int);
...
to the top of the file you're using them in.
If you're coding in C, it's enough to do
Code: [Select]
void ptc_close(void);
int ptc_update(void *);
int ptc_open(char *, int,int);
...

Jim
Challenge Trophies Won:

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
Re: How to link to tinyptc?
« Reply #4 on: May 04, 2008 »
Hi. I've just been messing around with this a bit, and I'm getting this error:

Quote
11 C:\Dev-Cpp\include\tinyptc.h `__int32' does not name a type

I haven't messed with C++ much, so I really don't understand what that error means. I'm using DevC++. Since I couldn't find an object file in the 0.8 tinyptc package, I just copied the .a lib file from the FreeBASIC directory and the header from the tinyptc archive. Will that even work?
The Dr. is INsane!!!

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: How to link to tinyptc?
« Reply #5 on: May 04, 2008 »
It's probably easier if you find a pre-compiled one...and rbz's tinyptc_ext is far better than that one.  Right now I'm just off to work so I can't fix that up for you, but maybe rbz, or someone else has something handy?

Jim
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: How to link to tinyptc?
« Reply #6 on: May 04, 2008 »
Definately agree with Jim.. Gaffer's tinyptc has some problems, there is no vsync and has not got mmx support. I'm guessing that rbz has a version of this that can be quite easily used with C++
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
Re: How to link to tinyptc?
« Reply #7 on: May 04, 2008 »
Cool. Since I started playing around with glsl, I've kind of learned some C++ by accident... doesn't seem so hard after all. :p Anyway, I just wanted to make some exact duplicate demos with mingw and fbc to see what kind of speed differences there are. 

rbz: If you read this, could you link me up with something please? Thanks!

:cheers:
The Dr. is INsane!!!

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: How to link to tinyptc?
« Reply #8 on: May 05, 2008 »
Quote
11 C:\Dev-Cpp\include\tinyptc.h `__int32' does not name a type
Since you are using dev-cpp you need to define it yourself, just add this line:
Code: [Select]
#define __int32 int
rbz: If you read this, could you link me up with something please? Thanks!
Yes, you can use tinyptc_ext with dev-cpp, I've attached an example for you :)



Challenge Trophies Won:

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
Re: How to link to tinyptc?
« Reply #9 on: May 05, 2008 »
Awesome! Thanks man. :D
The Dr. is INsane!!!

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
Re: How to link to tinyptc?
« Reply #10 on: May 06, 2008 »
Man, I still can't get it to work. I guess I need to learn more about devcpp because loading your example program without loading that project file causes undef-ref errors. If I load your project and compile, all I get is the object file. Any advice? Thanks again. :)

EDIT: n/m I got it going. I guess you have to link to the files manually. I'l have to get used to that. :p
« Last Edit: May 06, 2008 by Dr_D »
The Dr. is INsane!!!

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: How to link to tinyptc?
« Reply #11 on: May 06, 2008 »
Thanks for picking this up rbz!
Dr_D: please post any problems you're having and we'll try to fix you up!

Jim
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: How to link to tinyptc?
« Reply #12 on: May 06, 2008 »
Cheers Jim

@Dr_D: To compile this file, you need to open "test.dev" project and just press "Control + F11" to create your exe file.

If you want start a new dev-cpp project you will need to manually add "Linker" libraries:
Code: [Select]
libtinyptc_ext.a
libmmx.a
-luser32 -lgdi32

Challenge Trophies Won:

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
Re: How to link to tinyptc?
« Reply #13 on: May 06, 2008 »
Well, I'm just doing some simple testing right now, and I can't figure out why this is so slow. Am I doing something stupid?  :xmas:

Code: [Select]
#include "windows.h"
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
#include "math.h"
#include "tinyptc_ext.h"
#include "time.h"

#define XRES 640
#define YRES 480

int buffer[XRES*YRES];

int main(int argc, char *argv[])
{   
    ptc_setdialog(1,"Full Screen ?",1,0);

    ptc_allowclose(1);

    if(ptc_open( "C++/PTC test", XRES, YRES ) == 0 ) return -1;

    float r = 0;
    float g = 0;
    float b = 0;
    time_t a = 0;

    while(!GetAsyncKeyState(VK_ESCAPE))
    {
        a = time (NULL);
       
        for(int y=0; y<YRES; y++)
        {
            for(int x=0; x<XRES; x++)
            {
                r = 127.5 + 127.5 * sin(a);
                buffer[ y*XRES+x] = RGB( r, g, b );
            }
        }

        ptc_update(&buffer);

    }

    return 0;
}
The Dr. is INsane!!!

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: How to link to tinyptc?
« Reply #14 on: May 07, 2008 »
"time(NULL)" command will return calendar time in seconds, so it will change every second, for faster flashing effect you will need to use "GetTickCount()". And since you are using rgb float's you will need to use "sinf".

check this out:

Code: [Select]
#include "windows.h"
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
#include "math.h"
#include "tinyptc_ext.h"
#include "time.h"

#define XRES 640
#define YRES 480

int buffer[XRES*YRES];

int main(int argc, char *argv[])
{   
    ptc_setdialog(1,"Full Screen ?",1,0);

    ptc_allowclose(1);

    if(ptc_open( "C++/PTC test", XRES, YRES ) == 0 ) return -1;

    float r = 0;
    float g = 0;
    float b = 0;
    DWORD a = 0;

    while(!GetAsyncKeyState(VK_ESCAPE))
    {
        a = GetTickCount();
       
        for(int y=0; y<YRES; y++)
        {
            for(int x=0; x<XRES; x++)
            {
                r = 127.5f + 127.5f * sinf((float)a);
                buffer[ y*XRES+x] = RGB( b, g, r );
            }
        }

        ptc_update(&buffer);

    }

    return 0;
}



Challenge Trophies Won:

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
Re: How to link to tinyptc?
« Reply #15 on: May 07, 2008 »
Thanks. I have a lot to learn. This might seem silly, but one of the things I'd really like to do is translate the vector/matrix stuff I did for fbext to C++, make an optimized library and link back to it in FB.  :stirrer:
The Dr. is INsane!!!

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: How to link to tinyptc?
« Reply #16 on: May 07, 2008 »
One of the problems with C/C++ is that you need to be carefully when working with variable types (int, float, etc...), FB are more "flexible" with that.

Challenge Trophies Won:

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
Re: How to link to tinyptc?
« Reply #17 on: May 07, 2008 »
Yeah, it seems so. Is there anything I can do to avoid casting each variable? Imagine a plasma, for instance. You would likely have lots of calls to trig functions. Do I have to use float(variable) for each element? Also, is there a way to enable vsync? I didn't see anything in the header, except: ptc_setflip(int interval); That doesn't seem to do it, but maybe I'm just using it wrong? From the looks of it, I assumed it would set the page-swapping interval in milliseconds? Thanks again. :)
The Dr. is INsane!!!

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: How to link to tinyptc?
« Reply #18 on: May 07, 2008 »
Use ptc_setflip(0); to disable vsync and ptc_setflip(1); to enable, but you need execute it a before openning your window (ptc_open).


Challenge Trophies Won:

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
Re: How to link to tinyptc?
« Reply #19 on: May 07, 2008 »
ahhh... that's why it didn't work.  :boxer:
The Dr. is INsane!!!