Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: rain_storm 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
-
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
-
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 :
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
-
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
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
void ptc_close(void);
int ptc_update(void *);
int ptc_open(char *, int,int);
...
Jim
-
Hi. I've just been messing around with this a bit, and I'm getting this error:
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?
-
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
-
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++
-
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:
-
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:
#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 :)
-
Awesome! Thanks man. :D
-
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
-
Thanks for picking this up rbz!
Dr_D: please post any problems you're having and we'll try to fix you up!
Jim
-
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:
libtinyptc_ext.a
libmmx.a
-luser32 -lgdi32
-
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:
#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;
}
-
"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:
#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;
}
-
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:
-
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.
-
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. :)
-
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).
-
ahhh... that's why it didn't work. :boxer:
-
In fact it's my fault :-\ I didn't make any manual for it, you can find some examples for commands here (http://dbfinteractive.com/index.php?topic=1382.0)