Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Clyde on August 14, 2009

Title: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 14, 2009
Thanks to the dudes who've got me this far! ;)

As I'm learning how to use Pointers & Type in FreeBASIC with TinyPtc_ext, I'd like to also continue this with my semi colon adventures in the world of CPP.

And I wonder if you could spare some time and help me sort out my initial steps, im working with a class in replace of a type, I think I've got the method of casting a pointer variable for the class, im stuck on allocating the correct amount of space for the class & pointer.

Firstly here's the FreeBASIC source / method

Code: [Select]
type gfx_buffer
    wwidth as integer
    height as integer

    pixels as uinteger pointer

end type

dim as gfx_buffer ptr screen_buffer

screen_buffer=create_gfx_buffer( 640, 480 )


function create_gfx_buffer(byval wwidth as integer,_
                            byval height as integer )as gfx_buffer pointer
    
    dim as gfx_buffer pointer buffer
    
    buffer=callocate(len(gfx_buffer)+len(uinteger)*wwidth*height)
    

    buffer->wwidth=wwidth
    buffer->height=height
    
    buffer->pixels=cast(uinteger pointer,cast(byte pointer,buffer)+len(gfx_buffer))
  
    return buffer

end function

C++ Source:
Code: [Select]
#include <windows.h>

// remember ( ALT+F7) to add linker -> input -> dependencies 'libmmx.lib' & 'libtinyptc_ext.lib'
#include <tinyptc_ext.h>


const int XRES=640;
const int YRES=480;
const int ARES=XRES*YRES;

class gfx_buffer {
public:
int wwidth, height, wwidth2, height2;
unsigned int *pixels;
};

static gfx_buffer* screen_buffer;

// functions.
int set_graphics( int wwidth, int height );
gfx_buffer* create_gfx_buffer( int wwidth, int height );

screen_buffer=create_gfx_buffer( 640, 480 )

int main()
{
set_graphics( XRES, YRES );

while (1)
{
// clear screen.

// render to the screen buffer.
ptc_update( screen_buffer->pixels[0] );
}
// wend.
}

gfx_buffer* create_gfx_buffer( int wwidth, int height )
{
gfx_buffer* buffer=callocate
}


int set_graphics( int wwidth, int height )
{
ptc_allowclose(1);
ptc_setflip(1);

ptc_setdialog(1,"Would You Prefer Fullscreen Dude?",1,0);

    if (!ptc_open("mOnKeY bUiSnEsS 1",XRES,YRES)) return 1;

return 0;

}

It's the calallocate and length thats probably my main problem, providing the rest of the class and variables as pointer are correct.

Here's a link to the MSVC version of tinyptc_ext courtesy of rbz: http://www.dbfinteractive.com/forum/index.php?action=dlattach;topic=3981.0;attach=4574


Cheers and hugest of thanks,
Clyde
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 14, 2009
The equivalent of callocate is malloc().  You need to #include <stdlib.h> to use it.
Since you're using a class, you can't pull the same trick that you do in FB of allocating the structure and the framebuffer at the same time.  To allocate classes you use the 'new' operator.
You could do something like:
Code: [Select]
gfx_buffer *screen_buffer = new gfx_buffer;
screen_buffer->pixels = new unsigned int [width * height];
Even better, your class should do this in its constructor:
Code: [Select]
class gfx_buffer
{
private:
int width, height;
unsigned int *pixels;

public:
//constructor
gfx_buffer(int w, int h)
{
  width = w;
  height = h;
  pixels = new unsigned int [w*h];
}

//destructor
~gfx_buffer()
{
  delete [] pixels;
}

// getters
int get_width() { return width; }
int get_height() { return height; }
unsigned int *get_pixels() { return pixels; }

//other methods, eg.

void setpixel(int x, int y, unsigned int colour)
{
if (x>=0 && x < width && y>=0 && y < height)
  pixels[x+y*width] = colour;
}

void plotsprite(int x, int y, gfx_buffer *sprite)
{
//draw sprite into this gfx_buffer at x,y
}

}

Then, in your main() function, you can create lots of images with no work:
Code: [Select]
gfx_buffer *screen = new gfx_buffer(640,480);
gfx_buffer *sprite = new gfx_buffer(64,64);
...
//and the code you're looking for
ptc_update(screen->get_pixels());


Then you can extend the methods in the gfx_buffer class.

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 14, 2009
Bingo & Cool!!

For maloc, and the way I did similar in FB i'd need to do a struct-ure then dude?
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 14, 2009
Yes, typedef/struct:
Code: [Select]
typedef struct
{
int x, y;
unsigned int *pixels;
} gfx_buffer;
...
gfx_buffer *screen = (gfx_buffer *)malloc(sizeof *screen + 640*480*sizeof(unsigned int));
screen->pixels = (unsigned int *)(((char *)screen)+sizeof *screen);
But this is NASTY!  The C++ in my previous post is WAY WAY WAY better coding style.

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 14, 2009
Thanks again Jim :)
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 14, 2009
Whilst im still up, hows about a conversion of this routine in FB for loading an image from a file / binary.



Code: [Select]

#include "raw_data.bi"
#include "pal_data.bi"

dim as gfx_buffer ptr image1
image1=load_image_8bit(32,32,@raw_variable_name_ubyte(0),@pal_variable_name_ubyte(0))

function Load_Image_8bit( byval image as ubyte pointer,byval palet as ubyte pointer,byval wwidth as integer,byval height as integer )as gfx_buffer pointer
    
    while ((wwidth mod 4) <> 0)
        wwidth += 1
    wend
    
    dim as gfx_buffer pointer buffer=create_gfx_buffer(wwidth,height)
    dim as uinteger pal(0 to 255), col
    dim as integer a,x,y
    
    for a=0 to 255
        pal(a)=(palet[a*3] shl 16)or(palet[a*3+1] shl 8)or(palet[a*3+2]) 'or &HFF000000
    next    
    
    for y=0 to height-1
        for x=0 to wwidth-1
            buffer->pixels[ x+y*wwidth ]=pal(image[x+(y*wwidth)])
        next
    next
    
    return buffer

end function

I have yet to find a bmp2raw for C++, and also Binary2... ( i presume either a header or cpp file, or infact a .bi ) but it would be awesome for a conversion of the above. the weekend i will be doing my first ever intro in CPP.

Cheers and thanks again dudes,
Clyde.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: hellfire on August 15, 2009
Quote
hows about this routine in FB for loading an image from a file / binary.
I'm not quite sure what your question is, or if there is any ;)

Quote
I have yet to find a bmp2raw for C++, and also Binary2...
The binary version would be something like this (http://www.programmersheaven.com/download/713/4/ZipView.aspx) but you've got a resource-manager in Visual Studio, so you can include your images as jpeg or png and let Windows do the decoding for you.
There's no need to apply colour-reduction and the result is still much smaller.
Code can be found here (http://www.codeproject.com/KB/GDI-plus/cgdiplusbitmap.aspx?display=PrintAll&fid=14113&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=76).

Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 15, 2009
thanks for the links they'll sure come in handy.

I'd like to keep it if pos, with a similar approach to the above; where the raw data and colour data is in a file. as im more familiar with it, I have just modified  the post as i'd left some bits out. Once im more comfortable with CPP, I'll look into resources.

Cheers and hugest of thanks,
Clyde.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 15, 2009
You can keep using bmp2raw and bin2bas, just take the .bas files and replace '&H' with '0x', remove the '_' at the line ends, and replace the headers with
Code: [Select]
unsigned char picture_pal[] =
unsigned char picture_raw[] =

Then the loader looks a bit like:
Code: [Select]
gfx_buffer *load_image(unsigned char *pal, unsigned char *raw, int width, int height)
{
  //round width up to next multiple of 4
  width += (4-(width&3))&3;

  //create a new image
  gfx_buffer *gfx = new gfx_buffer(width, height);

  //convert the palette to 32bit
  unsigned int palette[256];
  for (int i=0; i < 256; i++)
     palette[i] = 0xff000000 | (pal[i*3]<<16) | (pal[i*3+1] << 8) | pal[i*3+2];

  //convert the pixels
  unsigned int *pix = gfx->get_pixels();
  for (int j=0; j<width*height; j++)
     *pix++ = palette[*raw++];

  return gfx;
}

If you are feeling brave, you could make this a second constructor for your gfx_buffer class.

Finally, rename the .bas files to .cpp and add them to your project in the solution browser in Visual Studio.
In your main cpp file, at the top after the includes, add
Code: [Select]
extern unsigned char picture_pal[];
extern unsigned char picture_raw[];
That will tell the main cpp file where to find the picture data - you'd need this for each picture.

Jim

Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 15, 2009
Muchos Gracias!
( thanks very much )
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 15, 2009
No Problemo!
(No Problem)

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: TinDragon on August 15, 2009
lol
(lol)

 :clap:
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Shockwave on August 15, 2009
¿Dónde están los sanitarios?
(Where is the toilet?)
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 15, 2009
el baño es sólo para niñas

I've tried doing this with having the setup and creation functions out of the class; just so I can have a practise. but am running into a few probs.

Code: [Select]
#include <windows.h>
#include <tinyptc_ext.h> // remember ( ALT+F7) to add linker -> input -> dependencies 'libmmx.lib' & 'libtinyptc_ext.lib'


const int XRES=640;
const int YRES=480;
const int ARES=XRES*YRES;


class gfx_buffer
{
private:
int wwidth, height;
int wwidth2, height2;
unsigned int *pixels;

}


// funksters.
//void draw_gfx_buffer( gfx_buffer *dest, gfx_buffer *srce, int x, int y );

gfx_buffer* create_gfx_buffer( int wwidth, int height );

int set_graphics( int wwidth, int height );

gfx_buffer *screen_buffer=create_gfx_buffer( XRES, YRES );

//screen_buffer=create_gfx_buffer( 640, 480 );

int main()
{
set_graphics( XRES, YRES );

while (1)
{
// clear screen.

// render to the screen buffer.
ptc_update( screen_buffer->pixels[0] );

} // wend.
} // end function.


gfx_buffer *create_gfx_buffer( int wwidth, int height )
{
gfx_buffer *buffer = new gfx_buffer;

buffer->pixels = new unsigned int [ wwidth * height ];

buffer->wwidth=wwidth;
buffer->height=height;

buffer->wwidth2=wwidth/2;
buffer->height2=height/2;

return buffer;
}

//void set_pixel()
//{

//}



int set_graphics( int wwidth, int height )
{
ptc_allowclose(1);
ptc_setflip(1);

ptc_setdialog(1,"Would You Prefer Fullscreen Dude?",1,0);

    if (!ptc_open("mOnKeY bUiSnEsS 1",wwidth,height)) return 1;

return 0;

}

Many thanks in advance,
Clyde.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 15, 2009
a) What problems?
b) Why not use the code I've given you so far?

<edit> hard to say, because the code is already becoming a jumble, but you might just need to change
Code: [Select]
ptc_update( screen_buffer->pixels[0] );
to
ptc_update( &screen_buffer->pixels[0] );

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Shockwave on August 15, 2009
No lo sé
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 15, 2009
Sole reason Jim, I want to try it with the functions out side the class.
I have used the method you gave me btw. thanks :)

here's the compile output:

Code: [Select]
Compiling...
Main1-2.cpp
.\Main1-2.cpp(23) : error C2143: syntax error : missing ';' before '*'
.\Main1-2.cpp(23) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\Main1-2.cpp(27) : error C2143: syntax error : missing ';' before '*'
.\Main1-2.cpp(27) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\Main1-2.cpp(27) : error C2371: 'gfx_buffer' : redefinition; different basic types
        .\Main1-2.cpp(23) : see declaration of 'gfx_buffer'
.\Main1-2.cpp(27) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\Main1-2.cpp(40) : error C2227: left of '->pixels' must point to class/struct/union/generic type
        type is 'int *'
.\Main1-2.cpp(46) : error C2143: syntax error : missing ';' before '*'
.\Main1-2.cpp(46) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\Main1-2.cpp(46) : error C2371: 'gfx_buffer' : redefinition; different basic types
        .\Main1-2.cpp(23) : see declaration of 'gfx_buffer'
.\Main1-2.cpp(47) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\Main1-2.cpp(48) : error C2065: 'buffer' : undeclared identifier
.\Main1-2.cpp(48) : error C2061: syntax error : identifier 'gfx_buffer'
.\Main1-2.cpp(50) : error C2065: 'buffer' : undeclared identifier
.\Main1-2.cpp(50) : error C2227: left of '->pixels' must point to class/struct/union/generic type
        type is ''unknown-type''
.\Main1-2.cpp(52) : error C2065: 'buffer' : undeclared identifier
.\Main1-2.cpp(52) : error C2227: left of '->wwidth' must point to class/struct/union/generic type
        type is ''unknown-type''
.\Main1-2.cpp(53) : error C2065: 'buffer' : undeclared identifier
.\Main1-2.cpp(53) : error C2227: left of '->height' must point to class/struct/union/generic type
        type is ''unknown-type''
.\Main1-2.cpp(55) : error C2065: 'buffer' : undeclared identifier
.\Main1-2.cpp(55) : error C2227: left of '->wwidth2' must point to class/struct/union/generic type
        type is ''unknown-type''
.\Main1-2.cpp(56) : error C2065: 'buffer' : undeclared identifier
.\Main1-2.cpp(56) : error C2227: left of '->height2' must point to class/struct/union/generic type
        type is ''unknown-type''
.\Main1-2.cpp(58) : error C2065: 'buffer' : undeclared identifier
Semi Colon Adventures 1 - 24 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: TinDragon on August 15, 2009
[edited] first response not really a good one.

Clyde the compiler is giving you hints at whats wrong
'gfx_buffer' : redefinition; different basic types .\Main1-2.cpp(23) : see declaration of 'gfx_buffer'
this line is giving you the biggest clue, if you have read anything about the c++ langauge you should know why this is failing, you have been doing something in freebasic with the DECLARE keyword that does what you are missing here ;)
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 15, 2009
There are 3 things causing all those errors:
1) There should be a ';' after the closing '}' on your class, on line 21
2) Because you're accessing all the properties of gfx_buffer outside of the class, you must change them to 'public' instead of 'private' (or use the code I gave you, whatever).
3) You need this fix
ptc_update( &screen_buffer->pixels[0] );
which you have ignored.

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 16, 2009
Thanks mate.

I get in the build log ( F5 - release ):
CIL library( CIL module) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators

plus:

Unhandled exception at 0x0019103a in Semi Colon Adventures 1.exe: 0xC0000005: Access violation reading location 0x00000004.

Code: [Select]
//
// includes.
// remember ( ALT+F7) to add linker -> input -> dependencies 'libmmx.lib' & 'libtinyptc_ext.lib'
//
#include <windows.h>
#include <tinyptc_ext.h>

//
// classes.
//
class gfx_buffer
{
public:
int wwidth, height;
int wwidth2, height2;
unsigned int *pixels;

};

//
// functions.
//
int set_graphics( int wwidth, int height );


gfx_buffer *create_gfx_buffer( int width, int height);




//
// variables.
//
//unsigned int screen_buffer[ ARES ];
gfx_buffer *screen_buffer=create_gfx_buffer( 640, 480 );


int main()
{
// initializing.
set_graphics( XRES, YRES );


// main program loop.
while (1)
{
// clear screen.
for( int index=0; index<(screen_buffer->wwidth*screen_buffer->height); index++)
screen_buffer->pixels[index]=0x000000;

// render to the screen buffer.
ptc_update( &screen_buffer->pixels[0] );

} // wend.

} // end function main()



int set_graphics( int wwidth, int height )
{
ptc_allowclose(1);
ptc_setflip(1);

ptc_setdialog(1,"Would You Prefer Full Screen Dude?",1,0);

    if (!ptc_open("sEmI cOl0n AdVeNtUrEs",wwidth,height))
return 1;
else
return 0;
// end if.

}


gfx_buffer *create_gfx_buffer( int wwidth, int height )
{
gfx_buffer *buffer = new gfx_buffer;

buffer->pixels = new unsigned int [wwidth*height];

buffer->wwidth = wwidth;
buffer->height = height;

buffer->wwidth2=wwidth/2;
buffer->height2=height/2;

return buffer;

}

Muchos Gracias Amigas ;) ,
Senior Clyde.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 16, 2009
Move this line
gfx_buffer *screen_buffer=create_gfx_buffer( 640, 480 );
inside main(), before set_graphics().
We can talk about static initialisers later.  Nothing 'before' main gets run.  It's not like FB where it starts at the top, it starts by running main().

Please change to 'Debug' configuration while we work out the problems.

Jim

Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 17, 2009
Cheers! :)

how do I use the load_image function dude? Ive tried &, @ and * allready before the array names.

gfx_buffer *my_image=load_image( cool_raw(0), cool_pal(0), 480, 92 );
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 17, 2009
gfx_buffer *my_image=load_image( cool_raw(0), cool_pal(0), 480, 92 );

In C, arrays use [] brackets, where in FB it was ().
So, cool_raw[0] would be the first byte in in the raw data.
But, you want to pass the address of the first byte, and in C that is &, where in FB it was @.
So that would be
&cool_raw[0]
which will work OK.
But even more simply, arrays are already the address of the first element, so just
cool_raw
will work.
Plus you have the arguments round the wrong way :P
So either
Code: [Select]
gfx_buffer *my_image=load_image( &cool_pal[0], &cool_raw[0], 480, 92 );
or
gfx_buffer *my_image=load_image( cool_pal, cool_raw, 480, 92 );

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 17, 2009
Ah Doh! All fixed up now thanks dude.

A few questions on what I've been shown and learnt so far.

1) what does extern (external) actually do? Couldn't I use #include "raw_image.cpp" ?

2) I've tried using #include <string.h> but I can't use the string scope.

3) I notice there isnt a MOD command, how is the calc for rounding width in the load function work?

4) I can't find much on using IF, i've found else, what Im looking for is using and ( logical And && ) instead of this long process of elimination:

Code: [Select]
// basic lingo example: if (x>0) and (x<wwidth-1) then

if (x>0)
if (x<width)
if (y>0)
if (y<height)
insert_clever_code_here();

Thanks a million for helping a CPP / Visual Studio newb out!
Cheers Clyde.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 17, 2009
Quote
what does extern (external) actually do? Couldn't I use #include "raw_image.cpp" ?
extern is just an external reference which tells the compiler everything is OK and the linker will fix it up later.  You *could* rename raw_image.cpp to raw_image.h and #include it, but the problem with that is it will get build every single time you compile.  If you leave it as a separate file it only gets rebuilt if it changes.  Using extern is way better.

Quote
I've tried using #include <string.h> but I can't use the string scope.
After all your #includes add the line
Code: [Select]
using namespace std;

Quote
I notice there isnt a MOD command, how is the calc for rounding width in the load function work?
The MOD command for integer types is %.  So 10%7=3.
& is bitwise AND.   &3 is the same as doing MOD 4.
If you think about it, all numbers that are divisible by 4 in binary don't have the lower two bits set (the 1 bit and the 2 bit).  So what I want to do is remove them and round up if there were any.  So

so if we look at the numbers, if it ends in 00b then I want to leave width alone, since it's already divisible by 4, 01b then I want to add 3, 10b add 2, 11b add 1.

00&3=0 (want to add 0)
01&3=1 (want to add 3)
10&3=2 (want to add 2)
11&3=3 (want to add 1)

4-(00&3)=4 (wrong)  4 is 100b
4-(01&3)=3 (right)    3 is 011b
4-(10&3)=2 (right)    2 is 010b
4-(11&3)=1 (right)    1 is 001b

100&3=0 (right)
011&3=3 (right)
010&3=2 (right)
001&3=1 (right)

So, ((4-(width&3)&3)
gives me the number I want to add.  Magic eh?

Quote
I can't find much on using IF, i've found else
You should be able to find these on any good C++ website.
&& (logical and)
|| (logical or)
<
>
== (equals - You MUST use a double ==)
<=
>=
!= (not equals, same as < > in FB)

The format is something like
Code: [Select]
if (a>b)
{
//something
}
else if (b>c)
{
//something else
}
else
{
//otherwise
}


Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 18, 2009
Cheers for the explanations dude! Magic :)

One other Class and pointer help, this time using a pointer pointer, called anim_buffer, basically this is a way or recording what frame_number links with a particular image frame as a gfx_buffer pointer pointer. I dont want to use a system of arrays of types sort of thang, as each tiled image will have different sizes depending on what it's of, i'd like it to follow more or less the way i've been upto things in FreeBASIC and pointers.

An example of how it's drawn: anim_buffer_1->frame[ 6 ] ( frame being told to draw frame 6 which is a gfx_buffer pointer.

here's the freeBASIC type.

Code: [Select]
type anim_image
    total_frames as integer
    frame_Width As Integer
    frame_Height As Integer
    frame as gfx_buffer pointer pointer
end type


function create_anim_images(byval srce As gfx_buffer Pointer,_
                            byval wwidth        As Integer,_
                            byval height        As Integer) As anim_image pointer

    dim as integer framesw=srce_buffer->wwidth\wwidth
    dim as integer framesh=srce_buffer->height\height

    dim as anim_image pointer image=callocate(len(anim_image))
    image->frame        =callocate(len(gfx_buffer pointer)*framesw*framesh)
   
    dim as integer frame_number,x,y
    for y=0 to (framesh-1)*height step height
        for x=0 to (framesw-1)*wwidth step wwidth
           
            image->frame[frame_number]=create_gfx_buffer(wwidth,height)
            draw_image(image->frame[frame_number],srce,-x,-y)
           
            frame_number+=1
           
        next
    next
   
    //;delete_gfx_buffer(srce)
   
    image->frame_wwidth=wwidth
    image->frame_height=height
    image->total_frames=framesw*framesh
   
    return image

End function

I've made a start on the class setup in c++, but am a little baffled and would love a hand sorting out the rest of the puzzle.

CPP class.
Code: [Select]
class anim_buffer
{
public:
int total_frames;
int frame_wwidth, frame_height;
gfx_buffer **frame;
};

Thankyou so much,
Clyde.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 18, 2009
We should think this whole thing out again for C++.  The FB code is terrible and isn't worth porting unless there's a really good reason.  What's the spec?  Where is the data coming from, what is the intended use?  What kind of interface (what functions) would you like to be able to use?

How's it going, by the way?  Have you managed to plot a sprite yet?  Or (gasp!) a pixel with this new framework?

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 18, 2009
gfx_buffer **frame;
To allocate this, first you need to allocate space for the pointers:
Code: [Select]
frame = new gfx_buffer *[num_frames];
then you need to allocate the frames
Code: [Select]
for (int i=0; i<num_frames; i++)
  frame[i] = new gfx_buffer(...);

If I were doing this, my anim_buffer class would inherit from and extend my gfx_buffer class.

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 19, 2009
Yeah I can draw images which is wicked ;)
Im running into problems in how to use sin / cos, as in the <math.h> there's 3 types of overloaded functions.

if i use sin( formula ) i then get told to use one of the three available, in this example im after the float sin one, but if i put float sin in, im then told float unexpected.


With regards to the bitmap font splitter / animation frames.

1 ) a gfx buffer is loaded which is the full size image that contains all the letters.

2 ) through the create_anim_buffer, frame[ frame_number ] corresponds to the individual list of individual images, to make them they are drawn to a newly created gfx_buffer, as in my examples above.

3) then in the draw_anim_image() routine, it would go someting like this:
void draw_anim_image( gfx_buffer *dest, anim_image *srce, int x, int y, int frame );
...
draw_gfx_buffer( screen_buffer, srce->frame[ frame ], pos_x, pos_y );

using bitmap fonts is going to be a big bonus.

Many thanks,
Clyde.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 19, 2009
Try sinf() instead of sin() for float.  All the math.h functions use double, normally.

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 19, 2009
Before going onto the bitmap font routine, i want to sort out the sin problems im having.
You may remember my neighbour Trantor using this in a code help topic for FB.

When I run this, all i get is one pixel doing a sinus motion up and down.

I get warnings of possible loss of data and some other bits, which I'll post under the c++ code. Hopefully you wont need the raw and palette image files.

Code: [Select]
//
// includes.
//
#include <windows.h>
#include <tinyptc_ext.h>
#include <math.h>

extern unsigned char gb_pal[];
extern unsigned char gb_raw[];

extern unsigned char sca_pal[];
extern unsigned char sca_raw[];


#define PI 3.141593f
#define DEGREES (PI/180.00f)


//
// classes.
//
class gfx_buffer
{
public:
int wwidth, height;
int wwidth2, height2;
unsigned int *pixels;

};

//
// function declarations.
//
int set_graphics( char *title, int wwidth, int height );

gfx_buffer *create_gfx_buffer( int wwidth, int height);
gfx_buffer *load_gfx_buffer( unsigned char *pal, unsigned char *raw, int wwidth, int height);

//
// sub routines.
//
void draw_buffer_rect( gfx_buffer *dest, gfx_buffer *srce, int pos_x, int pos_y, int rect_x, int rect_y, int rect_wwidth, int rect_height );
void draw_gfx_buffer( gfx_buffer *dest, gfx_buffer *srce, int pos_x, int pos_y );

int main()
{
//
// initializing.
//
gfx_buffer *screen_buffer=create_gfx_buffer( 640, 480 );
gfx_buffer *gravity_image=load_gfx_buffer( gb_raw, gb_pal, 300, 300 );

set_graphics( ".:wIgGlE jIgGlE:.", 640, 480 );

int x=0,y=0;
int sin_y=0;
int cos_x=0;
int sin_height=24;
int angle1=0;

//
// main program loop.
//
while(1)
{
//
// clear screen_buffer.
//
for( int index=0; index<(screen_buffer->wwidth*screen_buffer->height); index++)
screen_buffer->pixels[ index ]=0x000000;

//
// wiggle it.
//
for ( x=0; x<gravity_image->wwidth; x++)
{
sin_y=sin_height * sin( (angle1+x)*(DEGREES));

draw_buffer_rect( screen_buffer, gravity_image, x, sin_y, x, 0, 1, gravity_image->height );
}   
 
angle1+=1;

//
// render to the screen_buffer.
//
ptc_update( &screen_buffer->pixels[0] );

}
}


int set_graphics( char *title, int wwidth, int height )
{
ptc_allowclose(1);
ptc_setflip(1);

ptc_setdialog(1,"Would You Prefer Full Screen Dude?",1,0);

if (!ptc_open( title,wwidth,height))
return 1;
else
return 0;

}


gfx_buffer *create_gfx_buffer( int wwidth, int height )
{
gfx_buffer *buffer = new gfx_buffer;

buffer->pixels = new unsigned int [wwidth*height];

buffer->wwidth = wwidth;
buffer->height = height;

buffer->wwidth2=wwidth/2;
buffer->height2=height/2;

return buffer;
}


void draw_gfx_buffer( gfx_buffer *dest, gfx_buffer *srce, int pos_x, int pos_y )
{
for (int y=0; y<srce->height; y++)
for (int x=0; x<srce->wwidth; x++)
dest->pixels[ (x+pos_x)+(y+pos_y) * dest->wwidth ]=srce->pixels[ x+y*srce->wwidth ];
}


void draw_buffer_rect( gfx_buffer *dest, gfx_buffer *srce, int pos_x, int pos_y, int rect_x, int rect_y, int rect_wwidth, int rect_height )
{                   

    unsigned int col;
    int x,y;

    for ( y=0; y<rect_height; y++)
        for ( x=0; x<rect_wwidth; x++)
           
            if (x+rect_x>0) 
if (x+rect_x<srce->wwidth-1)
if (y+rect_y>0)
if (y+rect_y<srce->height-1)
col=srce->pixels[ (x+rect_x) + (y+rect_y) * srce->wwidth ];
            end if
           
            if (x+pos_x>0)
if (x+pos_x<dest->wwidth-1)
if(y+pos_y>0)
if(y+pos_y<dest->height-1)
//if(col>0)
dest->pixels[ (x+pos_x) + (y+pos_y) * dest->wwidth ]=col;
}


gfx_buffer *load_gfx_buffer(unsigned char *raw, unsigned char *pal, int wwidth, int height)
{
//
// round width up to next multiple of 4.
//
wwidth += ( 4-( wwidth&3 )) & 3;

//
// create a new image.
//
gfx_buffer *buffer = create_gfx_buffer( wwidth, height );
   
//
// convert the palette to 32 bit ( requires alpha channel set )
//
unsigned int palette[256];
int index;

for ( index=0; index < 256; index++ )
palette[ index ] = 0xff000000 | ( pal[ index*3 ] << 16) | ( pal[ index*3+1 ] << 8) | pal[ index*3+2 ];

//
// convert the pixels.
//
for ( index=0; index<(wwidth*height); index++)
buffer->pixels[ index ] = palette[ *raw++ ];

return buffer;
}

Compiler Warnings:
Compiling...
wiggle it 1-1.cpp
.\wiggle it 1-1.cpp(81) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
Linking...
Generating code
Finished generating code
MSVCRT.lib(cpu_disp.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
Embedding manifest...

Semi Colon Adventures 1 - 0 error(s), 2 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========


Cheers and all the very best,
Clyde.

Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 19, 2009
In draw_buffer_rect() you have two for loops.  The middle for loop is supposed to contain an 'if' that gets the colour AND and 'if' that sets the colour.  You need to tell the compiler that:
Code: [Select]
for (y...)
  for (x...)
  {//need this bracket
     if ()
      ...
     if ()
      ...
  }//and this bracket
The curly braces group expressions together.  Otherwise only the first expression after the control expression is used.  I often use {} even when I don't need to to make the grouping more clear. eg. in the code above, I'd have {} belonging to the (for y) going round the whole thing, just for clarity.

You also have a stray 'end if' in there.

Your other 'loss of data' problem:
One MAJOR difference between C++ and FB or C is that C++ is a strongly typed language.  When you say something is an 'int' it MEANS IT!  When you say something is 'double' it MEANS IT!
If you 'accidentally' assign something of one type to an object of another type then in FB or C it would just do it.  In C++ you need to tell the compiler that you know what you are doing.
The 'loss of data' warning is because sin() return a double, but you are assigning it to an int.  The compiler is telling you there's something wrong.
eg.
Code: [Select]
double a=0.5;
int b=a;
will give you the same warning.  You have 'lost' data because b==0 now.
If you intend to do this, you need to tell the compiler you mean it:
Code: [Select]
double a=0.5;
int b=(int)a;
The 'type cast' operator turns one object into another in a meaningful way.

Sometimes not having the type cast is an error, not just a warning and you must put one it to make it compile.  This is GOOD in my opinion, and is one of the major benefits of strongly-typed languages over BASIC and C.

Absurdly, you will get the 'loss of data' even if you do this
Code: [Select]
int a=5;
float b=a;
Even though a float can hold much bigger numbers than an int, it's not possible to exactly represent every int as a float.
eg. try this
Code: [Select]
int a=2147483647;
float b=a;
a=b;
and display the value of a. (hint: it's NOT 2147483647)

This code won't give a warning though:
Code: [Select]
int a=5;
double b=a;
a double can hold all integer values.

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 20, 2009
Huge thanks Jim :)

I have one other question before bed.
how would one do the equivalent of for a=0 to 320 step 32 ?
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 20, 2009
Code: [Select]
for (int a=0; a < 320; a+=32)

a+=32
is C/C++ shorthand for
a=a+32

You can put any expression in there, including one that doesn't include a.
You can even do stuff like
Code: [Select]
int a,b;
for (a=0,b=0; a < 320; a+=32, b+=1)

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 20, 2009
Ok here's my font assembling routine which deals with variable width fonts, which I'd love if you could correct if for me; as i've been trying allsorts over the past few days and going in circles.

Presently im getting wierd results, every image frame, comes out as a green rectangle, which in itself is odd as there isnt any green in the bitmap font data what so ever.

Code: [Select]
//
// includes.
//
#include <windows.h>
#include <tinyptc_ext.h>

extern unsigned char font64_pal[];
extern unsigned char font64_raw[];


#define PI 3.141593
#define DEGREES (PI/180.00f)


//
// classes.
//
class gfx_buffer
{
public:
int wwidth, height;
int wwidth2, height2;
unsigned int *pixels;

};

class anim_image
{
public:
int frame_wwidth, frame_height;
int total_frames;
gfx_buffer **images;
};

//
// function declarations.
//
int set_graphics( char *title, int wwidth, int height );

gfx_buffer *create_gfx_buffer( int wwidth, int height);
gfx_buffer *load_gfx_buffer( unsigned char *pal, unsigned char *raw, int wwidth, int height);

anim_image *create_anim_images( gfx_buffer *srce, int wwidth, int height, int blank_wwidth, int min_wwidth, int spacing );

//
// sub routines.
//
void draw_gfx_buffer( gfx_buffer *dest, gfx_buffer *srce, int pos_x, int pos_y );

int main()
{
//
// initializing.
//
gfx_buffer *screen_buffer=create_gfx_buffer( 640, 480 );

gfx_buffer *font_image=load_gfx_buffer( font64_raw, font64_pal, 512, 512 );
anim_image *font_one=create_anim_images( font_image, 64, 64, 32, 32, 1 );

set_graphics( "gRaPhIcS aNtIcS", 640, 480 );



// main program loop.
while(1)
{
// clear screen.
for( int index=0; index<(screen_buffer->wwidth*screen_buffer->height); index++)
screen_buffer->pixels[index]=0x000000;
// next index

draw_gfx_buffer( screen_buffer, font_one->images[19], 0, 0 );
//draw_gfx_buffer( screen_buffer, font_image,0,0);


// render to the screen buffer.
ptc_update( &screen_buffer->pixels[0] );

} // wend.

} // end function main()



int set_graphics( char *title, int wwidth, int height )
{
ptc_allowclose(1);
ptc_setflip(1);

ptc_setdialog(1,"Would You Prefer Full Screen Dude?",1,0);

if (!ptc_open( title,wwidth,height))
return 1;
else
return 0;
// end if.

}


gfx_buffer *create_gfx_buffer( int wwidth, int height )
{
gfx_buffer *buffer = new gfx_buffer;

buffer->pixels = new unsigned int [wwidth*height];

buffer->wwidth = wwidth;
buffer->height = height;

buffer->wwidth2=wwidth/2;
buffer->height2=height/2;

return buffer;

}


void draw_gfx_buffer( gfx_buffer *dest, gfx_buffer *srce, int pos_x, int pos_y )
{
for (int y=0; y<srce->height; y++)
for (int x=0; x<srce->wwidth; x++)

if (x+pos_x>0)
if (x+pos_x<dest->wwidth-1)
if (y+pos_y>0)
if (y+pos_y<dest->height-1)

dest->pixels[ (x+pos_x)+(y+pos_y) * dest->wwidth ]=srce->pixels[ x+y*srce->wwidth ];
// next x.
//next y
}




gfx_buffer *load_gfx_buffer(unsigned char *raw, unsigned char *pal, int wwidth, int height)
{
//
// round width up to next multiple of 4.
//
wwidth += ( 4-( wwidth&3 )) & 3;

//
// create a new image.
//
gfx_buffer *buffer = create_gfx_buffer( wwidth, height );
   
//
// convert the palette to 32 bit.
//
unsigned int palette[256];
int index;

for ( index=0; index < 256; index++ )
palette[ index ] = 0xff000000 | ( pal[ index*3 ] << 16) | ( pal[ index*3+1 ] << 8) | pal[ index*3+2 ];
// next index

//convert the pixels
for ( index=0; index<(wwidth*height); index++)
buffer->pixels[ index ] = palette[ *raw++ ];
// next index

return buffer;
}

anim_image *create_anim_images( gfx_buffer *srce, int wwidth, int height, int blank_wwidth, int min_wwidth, int spacing )
{
int frame_w= srce->wwidth / wwidth;
int frame_h= srce->height / height;
int total_frames= frame_w * frame_h;

anim_image *anim_buffer = new anim_image;

anim_buffer->images=new gfx_buffer *[ total_frames ];

if (blank_wwidth==0)
blank_wwidth=wwidth;
   
if (min_wwidth>wwidth)
min_wwidth=wwidth;

int frame_number=0, x=0, y=0, test_l=0, test_r=0, x_test=0, y_test=0;

for (y=0; y<(frame_h-1)*height; y+=height )
{
for (x=0; x<(frame_w-1)*wwidth; x+=wwidth )
{
//
// test x.
//
test_r=x;
           
for ( x_test=x; x_test<(x+wwidth-1); x_test+=1 )
{
for ( y_test=y; y_test<(y+height-1); y_test+=1 )
{
if (srce->pixels[ (x_test)+(y_test) * srce->wwidth]!=0xff000000)
test_r=x_test;
} // next y_test.
} //next x_test.


//
// test l.
//
test_l=x+wwidth-1;
           
for ( x_test=x+wwidth-1; x_test<x; x_test-=1 )
{
                for ( y_test=y; y_test<(y+height-1); y_test=+1)
{
if (srce->pixels[ (x_test)+(y_test)*srce->wwidth]!=0xff000000)
test_l=x_test;
}
// next y_test.
} // next x_test.


//
// bob the builder time! :)
//
if (test_r>=test_l)
{   
test_l-=spacing >> 1;
                test_r+=spacing-(spacing >> 1);
               
if ((test_r-test_l)<min_wwidth)
{
x_test=min_wwidth-(test_r-test_l);
                    test_r+=x_test >> 1 ;
                    test_l-=x_test-(x_test >> 1);
} //end if
               
if (test_r>x+wwidth-1)
test_r=x+wwidth-1;


if (test_l<x)
{
test_l=x;
anim_buffer->images[frame_number]=create_gfx_buffer(test_r-test_l+1,height);
draw_gfx_buffer( anim_buffer->images[frame_number],srce,-test_l,-y);
}
}
else
{
anim_buffer->images[frame_number]=create_gfx_buffer(blank_wwidth,height);
} // end if

frame_number+=1;

} // next x
}// next y

anim_buffer->frame_wwidth = frame_w;
anim_buffer->frame_height = frame_h;
anim_buffer->total_frames = total_frames;

return anim_buffer;
}

freebasic equivalent function and types.
Code: [Select]
type gfx_buffer
    wwidth as integer
    height as integer
    pixels as uinteger pointer
end type

type anim_image
    total_frames as integer
    FrameWWidth As Integer
    FrameHeight As Integer
    frame as gfx_buffer pointer pointer
end type

function create_anim_images(byval source_buffer As gfx_buffer Pointer,_
                    byval wwidth        As Integer,_
                    byval height        As Integer,_
                    byval blank_wwidth as integer=0,_
                    byval min_wwidth as integer=0,_
                    byval spacing as integer=1) As anim_image pointer

    dim as integer framesw=source_buffer->wwidth\wwidth
    dim as integer framesh=source_buffer->height\height
   
    if blank_wwidth=0 then blank_wwidth=wwidth
    if min_wwidth>wwidth then min_wwidth=wwidth
   
    dim as anim_image pointer image=callocate(len(anim_image))
    image->frame=callocate(len(gfx_buffer pointer)*framesw*framesh)

   
    dim as integer frame_number,x,y,test_l,test_r,x_test,y_test
    for y=0 to (framesh-1)*height step height
        for x=0 to (framesw-1)*wwidth step wwidth
           
            test_r=x
            for x_test=x to x+wwidth-1
                for y_test=y to y+height-1
                    if source_buffer->pixels[x_test+y_test*source_buffer->wwidth]<>0 then test_r=x_test
                next
            next
           
            test_l=x+wwidth-1
            for x_test=x+wwidth-1 to x step-1
                for y_test=y to y+height-1
                    if source_buffer->pixels[x_test+y_test*source_buffer->wwidth]<>0 then test_l=x_test
                next
            next
           
            if test_r>=test_l then
                test_l-=spacing shr 1
                test_r+=spacing-(spacing shr 1)
                if (test_r-test_l)<min_wwidth then
                    x_test=min_wwidth-(test_r-test_l)
                    test_r+=x_test shr 1
                    test_l-=x_test-(x_test shr 1)
                end if
                if test_r>x+wwidth-1 then test_r=x+wwidth-1
                if test_l<x then test_l=x
                image->frame[frame_number]=create_gfx_buffer(test_r-test_l+1,height)
                draw_image(image->frame[frame_number],source_buffer,-test_l,-y)
            else
                image->frame[frame_number]=create_gfx_buffer(blank_wwidth,height)
            end if

            frame_number+=1
           
        next
    next
   
    delete_gfx_buffer(source_buffer)
   
    image->FrameWWidth=WWidth
    image->FrameHeight=Height
    image->total_frames=framesw*framesh
   
    return image

End function

Thanks so much in advance,
Clyde.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 20, 2009
This won't work
Code: [Select]
for ( x_test=x+wwidth-1; x_test<x; x_test-=1 )
You write the equivalent of
Code: [Select]
For x=10 To 0 Step -1
as
Code: [Select]
for (x = 10; x >=0; x-=1)
Mostly you just need to change the < to a >= when you are counting downwards.

Looks like you've made a mistake here:
Code: [Select]
if (test_l<x)
{
test_l=x;
anim_buffer->images[frame_number]=create_gfx_buffer(test_r-test_l+1,height);
draw_gfx_buffer( anim_buffer->images[frame_number],srce,-test_l,-y);
}
should be
Code: [Select]
if (test_l<x)
test_l=x;
anim_buffer->images[frame_number]=create_gfx_buffer(test_r-test_l+1,height);
draw_gfx_buffer( anim_buffer->images[frame_number],srce,-test_l,-y);

Jim

Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 20, 2009
so those braces weren't needed.

for the step -1 bit?
Code: [Select]
for ( x_test=x+wwidth-1; x_test>=x; x_test-=1 )

For some reason now, it builds but the program doesnt run. before hand I had the dialog box for fullscreen... [yes] [no]
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 21, 2009
I think (but you can correct me if I'm wrong) you put braces in the wrong place.  I think with braces, it should have been:
Code: [Select]
if (test_l<x)
{
test_l=x;
}
anim_buffer->images[frame_number]=create_gfx_buffer(test_r-test_l+1,height);
draw_gfx_buffer( anim_buffer->images[frame_number],srce,-test_l,-y);

For loop?  Yes, that looks OK.

Dialog box missing? It must be stuck in an infinite loop creating the font, so it never gets there.

Jim

Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 22, 2009
Im puzzled, it's not going to plan as in the Freebasic comparison version.
So I'll have to come up with a completely different way.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 22, 2009
Don't be silly.  There's just some simple bug that needs fixing.  Can you post the *actual* code you're building and the test file and I will try to fix it up for you.

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 22, 2009
Sure thing dude, and that's really swell of you.

[ ed 209 ] i've included a zip archive of the individual files used including the tinyptc MSVC lib, and thanks for your time in this matter. [ / ed209 ]

Very cool and cheers,
Clyde.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Shockwave on August 22, 2009
Off topic:

Quote
Sure thing dude, and that's really swell of you.

Do you talk like that in real life?

On Topic:

Thanks for not giving with it Clyde and Jim, good luck.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: hellfire on August 22, 2009
Clyde, you just have a typo in create_anim_images:
Code: [Select]
for ( y_test=y; y_test<(y+height-1); y_test=+1)should be:
Code: [Select]
for ( y_test=y; y_test<(y+height-1); y_test+=1)
It's easy to find such stuff by simply stepping through the code with the debugger.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: TinDragon on August 22, 2009
Also in your main loop you have one as well
Code: [Select]
draw_gfx_buffer( screen_buffer, font_one->images[19], 0, 0 );

Should be
Code: [Select]
draw_gfx_buffer( screen_buffer, font_one->frame[19], 0, 0 );
Since you dont have an "images" in that class, which should be an error when trying to compile. BTW displays a 5 on screen but has some white lines like its offcentre, probably your sizes are slightly out ;)

[edit]god i made typo's giving you the info  :D
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 23, 2009
My guess is that part of the problem is in the display code
Code: [Select]
if (x+pos_x>0)
if (x+pos_x<dest->wwidth-1)
if (y+pos_y>0)
if (y+pos_y<dest->height-1)
and that we have a selection of 'off by one' errors here
Code: [Select]
if (x+pos_x>=0)
if (x+pos_x<dest->wwidth)
if (y+pos_y>=0)
if (y+pos_y<dest->height)
With those fixed you can now draw on the first and last scanlines and first and last pixels of every scanline.

I think there are similar problems in the code that's copying the characters out of the big sprite into the small ones, causing the offset.
Clyde, in C++ all arrays count from 0 and finish one index sooner than in FB. So,
int number[3];
has 3 ints in it.  number[0], number[1], number[2].  It's a bad error to use number[3].
Also, in FB the For loops go for one more iteration
For a=0 To 3
a=0, a=1, a=2, a=3
Where in C++
for (int a=0; a < 3; a++)
a=0, a=1, a=2

It looks like you've adjusted for this in most places, but I think there are still some problems.  Worth just doing a quick compare with the FB and C++ for all the If and For to check.

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 23, 2009
Thanks all for the info, will have a gander in a mo, need to switch to the other OS that has VS C++ on it.

JC2K: I forgot I had changed that, when I was collecting the files for zipping, I missed one when spring cleaning it.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 23, 2009
Awesome!! with a capital A :)
I owe you all a pint of what ever takes your fancy! :)

Thanks so much dudes!!!!!,
Clyde.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 23, 2009
With this print_text function, it doesnt draw the correct letters, it always draws from the first ( 0 ) frame upto how ever long it is, but not the corresponding letter for example:

text="CLYDE"
output:
[space] ! " £ $ %

Code: [Select]
void print_text( gfx_buffer *dest, anim_image *font, int pos_x, int pos_y, char *message )
{
int len=strlen( message ); //length of the message text.

for ( int a=0; a<len; a++)
{
char frame=message[a]-32; //splits message into appropriate letter.

if (frame>=0 )
if ( frame<=font->total_frames-1 )
{
draw_gfx_buffer( dest, font->frame[a], pos_x, pos_y );
pos_x+=font->frame[a]->wwidth;
}

} // next a

} // end function
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: hellfire on August 23, 2009
Quote
Code: [Select]
draw_gfx_buffer( dest, font->frame[a], pos_x, pos_y );
You don't want to draw character "a" (which counts the letters in your string) but "frame".
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 23, 2009
lol! Thanks for pointing that out dude! :)
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 24, 2009
I thought all was ok, but it's not taking the correct widths per frame into account, they're all 64x64, when they should be ( width upto 64 + space )  * 64.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 24, 2009
Problem is here (in two places):
Code: [Select]
if (srce->pixels[ (x_test)+(y_test) * srce->wwidth]!=0)
should be
Code: [Select]
if (srce->pixels[ (x_test)+(y_test) * srce->wwidth]!=0xff000000)
That fixes most of the width-based stuff, though there's still something else wrong

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 24, 2009
Tidied up some more off-by-ones in the for loops.  Here's the whole thing working:
Code: [Select]
//
// includes.
//
#include <windows.h>
#include "tinyptc_ext.h"

extern unsigned char us64_pal[]; // 64 distinguishes a variable font based around max width of 64, height == 64
extern unsigned char us64_raw[]; // i am unsure if this font is 8*8, or 8*16 ( including upper and lower case characters )

//
// classes.
//
class gfx_buffer
{
public:
int wwidth, height;
int wwidth2, height2;
unsigned int *pixels;

};

class anim_image
{
public:
int frame_wwidth, frame_height;
int total_frames;

gfx_buffer **frame;
};

//
// function declarations.
//
int set_graphics( char *title, int wwidth, int height );

gfx_buffer *create_gfx_buffer( int wwidth, int height);
gfx_buffer *load_gfx_buffer( unsigned char *pal, unsigned char *raw, int wwidth, int height);

anim_image *create_anim_images( gfx_buffer *srce, int wwidth, int height, int blank_wwidth, int min_wwidth, int spacing );
anim_image *create_anim_images2( gfx_buffer *srce, int wwidth, int height );
//
// sub routines.
//
void draw_gfx_buffer( gfx_buffer *dest, gfx_buffer *srce, int pos_x, int pos_y );
void print_text( gfx_buffer *dest, anim_image *font, int pos_x, int pos_y, char *message );

int main()
{
//
// initializing.
//
gfx_buffer *screen_buffer=create_gfx_buffer( 640, 480 );

gfx_buffer *font_image=load_gfx_buffer( us64_raw, us64_pal, 512, 512 );
anim_image *font_one=create_anim_images( font_image, 64, 64, 32, 2, 1 );

set_graphics( "gRaPhIcS aNtIcS", 640, 480 );


// main program loop.
while (1)
{
// clear screen.
for( int index=0; index<(screen_buffer->wwidth*screen_buffer->height); index++)
screen_buffer->pixels[index]=0x000000;
// next index

// remove remarks to test the image has been loaded successfully.
//draw_gfx_buffer( screen_buffer, font_one->frame[19], 0, 0 );
//draw_gfx_buffer( screen_buffer, font_image, 0, 0 );

print_text(screen_buffer, font_one, 10,10, "HELLO");

// render to the screen buffer.
ptc_update( &screen_buffer->pixels[0] );

} // wend.

} // end function main()

void print_text( gfx_buffer *dest, anim_image *font, int pos_x, int pos_y, char *message )
{
int len=strlen( message ); //length of the message text.

for ( int a=0; a<len; a++)
{
char frame=message[a]-32; //splits message into appropriate letter.

if (frame>=0 )
if ( frame<=font->total_frames-1 )
{
draw_gfx_buffer( dest, font->frame[frame], pos_x, pos_y );
pos_x+=font->frame[frame]->wwidth;
}

} // next a

} // end function

int set_graphics( char *title, int wwidth, int height )
{
ptc_allowclose(1);
ptc_setflip(1);

ptc_setdialog(1,"Would You Prefer Full Screen Dude?",1,0);

if (!ptc_open( title,wwidth,height))
return 1;
else
return 0;
// end if.

}


gfx_buffer *create_gfx_buffer( int wwidth, int height )
{
gfx_buffer *buffer = new gfx_buffer;

buffer->pixels = new unsigned int [wwidth*height];

buffer->wwidth = wwidth;
buffer->height = height;

buffer->wwidth2=wwidth/2;
buffer->height2=height/2;

return buffer;

}


void draw_gfx_buffer( gfx_buffer *dest, gfx_buffer *srce, int pos_x, int pos_y )
{
for (int y=0; y<srce->height; y++)
for (int x=0; x<srce->wwidth; x++)

if (x+pos_x>=0)
if (x+pos_x<dest->wwidth)
if (y+pos_y>=0)
if (y+pos_y<dest->height)

dest->pixels[ (x+pos_x)+(y+pos_y) * dest->wwidth ]=srce->pixels[ x+y*srce->wwidth ];
// next x.
//next y
}




gfx_buffer *load_gfx_buffer(unsigned char *raw, unsigned char *pal, int wwidth, int height)
{
//
// round width up to next multiple of 4.
//
wwidth += ( 4-( wwidth&3 )) & 3;

//
// create a new image.
//
gfx_buffer *buffer = create_gfx_buffer( wwidth, height );

//
// convert the palette to 32 bit.
//
unsigned int palette[256];
int index;

for ( index=0; index < 256; index++ )
palette[ index ] = 0xff000000 | ( pal[ index*3 ] << 16) | ( pal[ index*3+1 ] << 8) | pal[ index*3+2 ];
// next index

//convert the pixels
for ( index=0; index<(wwidth*height); index++)
buffer->pixels[ index ] = palette[ *raw++ ];
// next index

return buffer;
}

anim_image *create_anim_images( gfx_buffer *srce, int wwidth, int height, int blank_wwidth, int min_wwidth, int spacing )
{
int frame_w= srce->wwidth / wwidth;
int frame_h= srce->height / height;
int total_frames= frame_w * frame_h;

anim_image *anim_buffer = new anim_image;

anim_buffer->frame=new gfx_buffer *[ total_frames ];

if (blank_wwidth==0)
blank_wwidth=wwidth;

if (min_wwidth>wwidth)
min_wwidth=wwidth;

int frame_number=0, x=0, y=0, test_l=0, test_r=0, x_test=0, y_test=0;

for (y=0; y<frame_h*height; y+=height )
{
for (x=0; x<frame_w*wwidth; x+=wwidth )
{
//
// test x.
//
test_r=x;

for ( x_test=x; x_test<(x+wwidth); x_test+=1 )
{
for ( y_test=y; y_test<(y+height); y_test+=1 )
{
if (srce->pixels[ (x_test)+(y_test) * srce->wwidth]!=0xff000000)
test_r=x_test;
} // next y_test.
} //next x_test.


//
// test l.
//
test_l=x+wwidth-1;

for ( x_test=x+wwidth-1; x_test>=x; x_test-=1 )
{
for ( y_test=y; y_test<y+height; y_test+=1)
{
if (srce->pixels[ (x_test)+(y_test)*srce->wwidth]!=0xff000000)
test_l=x_test;

}// next y_test.
}// next x_test.


//
// bob the builder time! :)
//
if (test_r>=test_l)
{   
test_l-=spacing >> 1;
test_r+=spacing-(spacing >> 1);

if (test_r-test_l<min_wwidth)
{
x_test=min_wwidth-(test_r-test_l);
test_r+=x_test >> 1 ;
test_l-=x_test-(x_test >> 1);
} //end if

if (test_r>x+wwidth-1) //then
test_r=x+wwidth-1;
// end if



if (test_l<x) // then
test_l=x;
// end if

anim_buffer->frame[frame_number]=create_gfx_buffer(test_r-test_l+1,height);
draw_gfx_buffer( anim_buffer->frame[frame_number],srce,-test_l,-y);




}
else
{
anim_buffer->frame[frame_number]=create_gfx_buffer(blank_wwidth,height);
} // end if

frame_number+=1;

} // next x
} // next y

anim_buffer->frame_wwidth = frame_w;
anim_buffer->frame_height = frame_h;
anim_buffer->total_frames = total_frames;

return anim_buffer;
}

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 25, 2009
Thats just perfect, a great pressie! :D
So you need to be exact with your value checking!

Cheers,
Clyde.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 25, 2009
you may of noticed me using this slow method of clearing the screen, any ideas on how to improve upon it?

Code: [Select]
for( int index=0; index<(screen_buffer->wwidth*screen_buffer->height); index++)
screen_buffer->pixels[index]=0x000000;

Cheers,
Clyde.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 26, 2009
Make sure you have
Code: [Select]
#include <string.h>
at the top, then replace the for loop with
Code: [Select]
memset(screen_buffer->pixels, 0, screen_buffer->wwidth*screen_buffer->height * sizeof(unsigned int));

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 26, 2009
Cheers Jim! :)

I get the following when ever I use sin / cos. Im wondering if this is telling me to add MSVCRT.lib or something else to the linker?

MSVCRT.lib(cpu_disp.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators

how i use sin to avoid conversion warnings / loss of data errors:

mockup example:
Code: [Select]
float sinx;
int sinxx;

sinx=(float) sin( [i]insert_formula[/i] );
sinxx=(int) sinx;
draw( sinxx, 200, 0xFFFF0000 ); // ( usage - posx as int, posy as int, colour as unsigned int )
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 26, 2009
To use sin() etc. you should
Code: [Select]
#include <math.h>
You can ignore the warnings.  I have already explained to you in this thread about the loss of precision warnings.

The .CRT warning is some problem in your project settings.  It's just a warning.  I don't know what's triggering it.  Can you post a zip of all your files again?

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: TinDragon on August 26, 2009
Code: [Select]
sinx=(float) sin( [i]insert_formula[/i] );
I would think that should be "float sin(float whatever);" which is only available in C++ if the compiler help is correct. TBH if your using float values then use sinf() which expects a float in and gives a float out, which Jim mentioned earlier in this very thread, sin() works with doubles so will likely give the warning double to float conversion or something similiar, which you can ignore but it is better to fix imho.



Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: hellfire on August 26, 2009
Generally VC++ is a bit picky with double/float conversions by default which results in a store and reload of every intermediary result.
To get around this you can set the fpu-precision to "fast" in the C++ settings.
But keep in mind that "missing" rounding leads to different results.

A simple example:
Code: [Select]
  float sum= 0.0f;
   for (float x=0.0f;x<10.0f;x+=0.1f)
   {
      float y= sin(x);
      sum+=y;
   }
   printf("result: %f \n", sum);
disassembly with fpu-precision "fast"
Code: [Select]
00401006  fldz            
00401008  fld         st(0)
0040100A  fld         dword ptr [402100h]
00401010  fld         dword ptr [4020FCh]
00401016  jmp         main+1Ah (40101Ah)
00401018  fxch        st(3)
0040101A  fld         st(3)
0040101C  fsin            
0040101E  faddp       st(3),st
00401020  fxch        st(3)
00401022  fadd        st,st(1)
00401024  fcom        st(3)
00401026  fnstsw      ax  
00401028  test        ah,5
0040102B  jnp         401018h
result: 18.647397
...and "precise"
Code: [Select]
00401009  fldz            
0040100B  fst         dword ptr [esp+38h]
0040100F  fstp        dword ptr [esp+34h]
00401013  fld         dword ptr [esp+34h]
00401017  call        _CIsin (401870h)
0040101C  fstp        dword ptr [esp+3Ch]
00401020  fld         dword ptr [esp+3Ch]
00401024  fadd        dword ptr [esp+38h]
00401028  fstp        dword ptr [esp+38h]
0040102C  fld         dword ptr [esp+34h]
00401030  fadd        qword ptr [402100h]
00401036  fstp        dword ptr [esp+34h]
0040103A  fld         dword ptr [4020FCh]
00401040  fld         dword ptr [esp+34h]
00401044  fcom        st(1)
00401046  fnstsw      ax  
00401048  fstp        st(1)
0040104A  test        ah,5
0040104D  jnp         main+17h (401017h)
result: 18.647362

Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 26, 2009
@All: thank you so much.

@Jim: it might be to do with the the tiny ptc lib. my files havent really changed except for the addition of sin and the <maths.h>
http://www.dbfinteractive.com/forum/index.php?action=dlattach;topic=4329.0;attach=5098
if you really need the source with the sin in, I'll zip that up for ya.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 26, 2009
The problem is probably in your project settings file (the .vcproj file) which you haven't posted.

Adding to what Hellfire says:

10 is an int
10.0 is a double
10.0f is a float (i.e. put an f at the end to make constant floats).

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 27, 2009
Cool! :)

Here's my vc project file.

Cheers,
Clyde.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on August 27, 2009
That project file is for whatever demo you are working on, not what we are working on here.  If I put in our source code there is no warning.

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on August 29, 2009
You must have something set that I dont, as everytime I use:

float a_float=1.23f;
int x_int=(int) a_float;
or: int x_int=(int) (a_float+0.5f);

alongside sin / cos, #include <math.h>

I revieve the l "LNK4210, "msvcrt.lib(cpu_disp.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators"

Taken from: http://social.msdn.microsoft.com/Forums/en-US/windowsdirectshowdevelopment/thread/5d33a142-b3a3-4ce4-ad71-91f896ab4d62

Another common reason that you would get LNK4210, "msvcrt.lib(cpu_disp.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators" is if you are building DEBUG and not including the debug version of the MSVCRT(msvcrtd.dll).
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: hellfire on August 29, 2009
I've never seen such an error but it sounds like you want to set "Configuration Properties -> C/C++ -> Code Generation -> Runtime Library" to either "Multi-threaded Debug" or "Multi-threaded Debug DLL"
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 07, 2009
Thanks dude, Im not entirely sure if I found the right place for the configuration properties, is there a short cut? I tried altering but i got more errors and sometimes the programs wouldnt run, im a bit baffled at present.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 24, 2009
ive just started a new win32 empty project via the wizard, for an updated version of a previous source, i now get the following and a blank screen. exactly the same code too which i could see the effect.

1> CIL library( CIL module) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators

1>MSVCRT.lib(cpu_disp.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on September 24, 2009
You've mentioned this before, but none of us can replicate it because you haven't posted a complete project that will build that has the problem.  Can you post a complete buildable project, (libs, source, vcproj file) that shows the problem?

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 24, 2009
I will have a stab at it, as im not completley sure what to include, the release and debug directories, plus the same for the tinyptc lib?
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 24, 2009
here's whats in my project folder.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on September 24, 2009
You need to send all the files that end in:
.cpp, .c, .h, .lib, .vcproj

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 25, 2009
Somethings definatly a miss, as that's what i had in the projects directory.
I did notice that it hasnt included the tinyptc libs and headers ( libmmx.lib and tinyptc_ext.lib )

What is the correct process for creating a new windows 32 project without the console window? I opted for empty Win32 for the project thats uploaded, and added existing files for the bitmap1-4.cpp and graphics files.

Cheers,
Clyde
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: hellfire on September 25, 2009
Here (http://msdn.microsoft.com/en-ca/library/3awe4781%28VS.80%29.aspx) is a short description of all the different files that are floating around in your project-folder.
The "debug" and "release" folders contain only temporary files which just waste space when sharing your sources.
The only really relevant one has the suffix .vcproj and contains all your project settings and attached files.
If you want someone else to compile your project you need to include all source-, header- and library-files.
If the resulting program loads any auxiliary data from your hard-disc you should include that, too.
Here it seems that your source-files aren't stored in your project-folder but somewhere else on your disc.
That can be quite useful actually, but I doubt this happened intentionally ;)

Quote
What is the correct process for creating a new windows 32 project without the console window? I opted for empty Win32 for the project thats uploaded, and added existing files for the bitmap1-4.cpp and graphics files.
Copy all relevant source-files into your new project-folder before you're adding them to your new project.
Otherwise you'll end up in a complete mess.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 25, 2009
Cheers Hell Fire :)

I dont know why my first 3 projects work and display as should be, but any new ones come up with those two error messages about cil and cpu object; they do build sucessfully but dont display anything what so ever.

I've tried about 12 times now with new projects. And ive not changed a single thing, in regards to libs, headers, filenames, or directory names. I've done what you've suggested in copying via Windows Explorer the source / .cpp files over to the new one, and adding them to the project via the solution explorer.

Im wondering if I need to try modify / repairing the installation of VC express 08. Or infact there are bugs with Visual Studio CPP. Or infact do a clean installation.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: hellfire on September 25, 2009
You've mentioned this before, but none of us can replicate it because you haven't posted a complete project that will build that has the problem. 
Can you post a complete buildable project, (libs, source, vcproj file) that shows the problem?
You need to send all the files that end in: .cpp, .c, .h, .lib, .vcproj
Please follow the orders ;)
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 25, 2009
That Zip above is with everything that's been generated with the new troublesome priojects.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: hellfire on September 25, 2009
The archive above doesn't contain any source-files which makes it a little bit difficult to compile.
And that's why Jim told you which files to include.

Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Shockwave on September 25, 2009
Maybe Clyde is scared that someone will rip his routines :p
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 25, 2009
The project ive uploaded is nothing to fancy pants, also im having major problems now in creating new projects which is stopping any progression.

I can upload the projects that do work ( which have alot more content ) instead of the problems im having with the latest projects that contain just like you mentioned not very much; but that's kind of defeating my query; as what im getting I think is that those files arent being put into the current project for some bug or other reason with building in release / win32.

I had this similar senario when I tried using CPP when it used the net framework, vc 2005.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on September 25, 2009
Mate, the file you uploaded has *nothing* in it!

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 25, 2009
How strange it was about 2megs. I'll reupload it.
Just downloaded it again, all of the stuff has gone into the debug folder of Axium. it should be in the release as thats what build i opted for.

Axium - > Axium -> Debug
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on September 25, 2009
NOOO!  Upload a file with the source code in!
Directory Listing of what you uploaded
Code: [Select]
C:\Users\Jim\Desktop\Axium\Axium
C:\Users\Jim\Desktop\Axium\op.txt
C:\Users\Jim\Desktop\Axium\Axium\Axium
C:\Users\Jim\Desktop\Axium\Axium\Axium.ncb
C:\Users\Jim\Desktop\Axium\Axium\Axium.sln
C:\Users\Jim\Desktop\Axium\Axium\Debug
C:\Users\Jim\Desktop\Axium\Axium\Release
C:\Users\Jim\Desktop\Axium\Axium\Axium\Axium.vcproj
C:\Users\Jim\Desktop\Axium\Axium\Axium\Axium.vcproj.MIKES-GATEWAY.Mike Furlong.user
C:\Users\Jim\Desktop\Axium\Axium\Axium\Debug
C:\Users\Jim\Desktop\Axium\Axium\Axium\Release
C:\Users\Jim\Desktop\Axium\Axium\Axium\Debug\Axium.exe.embed.manifest
C:\Users\Jim\Desktop\Axium\Axium\Axium\Debug\Axium.exe.embed.manifest.res
C:\Users\Jim\Desktop\Axium\Axium\Axium\Debug\Axium.exe.intermediate.manifest
C:\Users\Jim\Desktop\Axium\Axium\Axium\Debug\bitmap scroller 1-4.obj
C:\Users\Jim\Desktop\Axium\Axium\Axium\Debug\BuildLog.htm
C:\Users\Jim\Desktop\Axium\Axium\Axium\Debug\us64x64_pal.obj
C:\Users\Jim\Desktop\Axium\Axium\Axium\Debug\us64x64_raw.obj
C:\Users\Jim\Desktop\Axium\Axium\Axium\Debug\vc90.idb
C:\Users\Jim\Desktop\Axium\Axium\Axium\Debug\vc90.pdb
C:\Users\Jim\Desktop\Axium\Axium\Axium\Release\Axium.exe.intermediate.manifest
C:\Users\Jim\Desktop\Axium\Axium\Axium\Release\bitmap scroller 1-4.obj
C:\Users\Jim\Desktop\Axium\Axium\Axium\Release\BuildLog.htm
C:\Users\Jim\Desktop\Axium\Axium\Axium\Release\mt.dep
C:\Users\Jim\Desktop\Axium\Axium\Axium\Release\us64x64_pal.obj
C:\Users\Jim\Desktop\Axium\Axium\Axium\Release\us64x64_raw.obj
C:\Users\Jim\Desktop\Axium\Axium\Axium\Release\vc90.idb
C:\Users\Jim\Desktop\Axium\Axium\Axium\Release\vc90.pdb
C:\Users\Jim\Desktop\Axium\Axium\Debug\Axium.pdb
C:\Users\Jim\Desktop\Axium\Axium\Release\Axium.exe
C:\Users\Jim\Desktop\Axium\Axium\Release\Axium.pdb

No C or CPP or LIB files.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Rbz on September 25, 2009
NOOO!  Upload a file with the source code in!
hehe  :)

@Clyde: please search these missing files:
Quote
..\..\Bitmap Scroller 1-1\Bitmap Scroller 1-1\bitmap scroller 1-4.cpp
..\..\graphics\us64x64_pal.cpp
..\..\graphics\us64x64_raw.cpp



Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 26, 2009
Ok here I go again with project_x :)
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 26, 2009
And here are the external bits.

which i have added to the options part that has the locations of the includes and headers etc.

thanks for your help,
Clyde.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 26, 2009
I know this has gone a bit a stray, but i promise it will get back to classes. ;)
And sorry if i've messed people about.

What I think I should do is go back to basics of generating a project / starting VS C++ 2008 express a fresh.

1/ What's the difference between a console application and a win32 application ( both of which I choose the empty option )?

As I can run console projects, still get that annoying warning of crt cpu.object. And I was under the impression that win32 app is a program that does away with the black dos window. Do I need to change main?

presently, in a console app: void main()
And I use the same for a Win32 app, but as you know these do not work properly, and tell me about CIL.


Thank you for your patience, time and help getting me through these, I can almost smell the secret of success! ;)

Clyde.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on September 26, 2009
A console application opens a command window by default (like some FB programs do), it can use this for logging and console input.  A windows program doesn't do that.
A console application has the entry point:
int main(void)
{
...your program
}

A win32 program has the entry point:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
...your program
}

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on September 26, 2009
In the new zip files we're still missing some of the code files.  The ones that have us64_pal etc. in them.  Please don't post the .ncb file, it's 2Mb and isn't any use to anyone.

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 26, 2009
Here's a link for the media for the font.
http://www.dbfinteractive.com/forum/index.php?action=dlattach;topic=4361.0;attach=5236
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on September 26, 2009
You're still not posting the actual code you're having the problem with, because this project file (vcproj) doesn't even have a reference to the tinyptc library in it!  I really don't understand why you can't just post all the .cpp, .c, .h, and .vcproj files, and only those files, how hard is that to do?

However, I think the solution to your warnings is
Project->Properties->Configuration Properties->C++->Code Generation
and change Runtime Library to be
Multi-threaded Debug (/MTd)
you'll need to change it in the Release configuration as well, to
Multi-threaded (/MT)

<edit>
You'll also need to set it back to Console mode or fix your main to be WinMain for it to do anything.

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 27, 2009
Thankyou will try that out.

with the includes / libs and headers, i have those added at the VC++ directories, where you'd have the platform sdk / direct sdk, etc. I did this as i thought it be easier than having to constantly add them to a new project. I did include all that i have, plus extras thats got the external stuff.

So that might explain why they arent in the project_x project.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 27, 2009
I have done a fresh install of VS C++ Express 08.

I keep getting with a win32 project:
1>libtinyptc_ext.lib(tinyptc.obj) : error LNK2001: unresolved external symbol _main

this is what i have as my main:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: hellfire on September 27, 2009
Quote
error LNK2001: unresolved external symbol _main
In your project properties (that's what appears when you press Alt+F7) there's a tree on the left.
Under "Configuration Properties" there's an entry "Linker", under "Linker" there's an entry "System" - select it.
On the right a couple of options appear.
In the option "SubSystem" you can select either "Console" or "Windows".

"Console" assumes a function called "main" which should be defines as
Code: [Select]
int main(int argc, char *argv[])
{
}

"Windows" assumes a function called "WinMain" defined as
Code: [Select]
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
}

if you use "Console" (and the associated main(...) function), a console windows opens automatically when your application starts. That's because C++ originates from unix development and expects some sort of textual output device.
This is quite useful as long as you're in development to print all sorts of debug-infos.

For "Windows" applications (with the associated WinMain(...) function) this is usually undesired as there's some sort of gui.

Please recapitulate what I wrote earlier about storing project- and source-files in a single place to avoid mess-up.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on September 27, 2009
Actually, I couldn't make this work either.  I think libtinyptc_ext.lib already defines WinMain or WinMainCRTStartup and itself it calls main.  Something to do with how it works in FB.
That's a bit odd, but it means that Clyde should use
int main(void)
{
}
even when he has his linker set to WINDOWS, but only when using libtinyptc_ext.
Maybe rbz can confirm?

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 28, 2009
Ah so it seems there's something a foot in tinyptc.
I wonder if there is anything similar that I can use temporarily?
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on September 28, 2009
You should be OK to use libtinyptc_ext and set it to
SUBSYSTEM:WINDOWS
and use
int main()
{
...my code
}

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Rbz on September 28, 2009
Actually, I couldn't make this work either.  I think libtinyptc_ext.lib already defines WinMain or WinMainCRTStartup and itself it calls main.  Something to do with how it works in FB.
That's a bit odd, but it means that Clyde should use
int main(void)
{
}
even when he has his linker set to WINDOWS, but only when using libtinyptc_ext.
Maybe rbz can confirm?

Jim
Yes, that's how Gaffer did it
Code: [Select]
#ifdef __PTC_WINMAIN_CRT__

    extern int main();
    void WinMainCRTStartup()
    {
        main();
    }

#endif

Here's a little fix for building console and windows projects without producing crt warnings, just go to "Project/Properties" and add "WinMainCRTStartup" to the entry point.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 29, 2009
Extreme thanks to all :)

Now it's not running the program after pressing F5.
in console option it works with not using WinMainCRTStartup, and in windows option neither work.

Is it ok to add what I call libraries that I more often than not use on a regular basis to the projects and solutions info? Stuff like tinyptc, and my work in progress 2d lib. Or should I be copying them over into the headers and source code parts of a project?

As im trying to work out the problems im having, as its funny how the first few projects worked in linker -> system -> subsystem -> Windows (/SUBSYSTEM:WINDOWS) ( btw there is a windowsce )

As im thinking maybe some files get corrupted or something, not entirely sure.

<edit> I had to revert back from mt multi threaded back to the multithreaded dll. I also used the entry point fix, but i still got the errors back.
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 29, 2009
Righty here's the last of my adventures with MSVC. as i cant even get a program to run properly.

Is this causing me grief and is it needed?
Code: [Select]
#ifdef __PTC_WINMAIN_CRT__

    extern int main();
    void WinMainCRTStartup()
    {
        main();
    }

#endif

Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on September 29, 2009
I don't know why it is needed.  It means you can never make SYSTEM:WINDOWS programs with libtinyptc_ext unless they don't use any built-in functions as it stops the runtime being initialized (hence why your programs just drop out).

You're stuck doing SYSTEM:CONSOLE, not that that's a bad thing - you just end up with a cmd window, everything else is the same.

SYSTEM:WINDOWSCE is Windows CE, a cut down embedded Windows for phones and PDAs.

<edit>Just found a way round it.
Set it back to SYSTEM:WINDOWS
Set it back to Multithreaded
Set the option rbz mentioned (entry point) to mainCRTStartup
Use main() instead of WinMain in your program.

That will force it to init the runtime and bypass the libtinyptc_ext wierdness.

<edit2>attached is what I think is your project working with SYSTEM:WINDOWS

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 30, 2009
Absolutely Awesome!
Thanks so much Jim :)

Are the .a files equivalents of a .lib ?
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on September 30, 2009
Quote
Absolutely Awesome!
I can't let you give up!  I want to see a Gravity C++ demo!

Quote
Are the .a files equivalents of a .lib ?
Yes, I think it will work with either.

Jim
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Clyde on September 30, 2009
Work has allready begun dude!
And thanks again Gym Sure, sorry there dude I've been waiting ages to type that. ;)

btw, where or how did you do the tinyptc_ext.a and mmx.a files?
Title: Re: [C++] Converting FreeBASIC Pointer Types into a Class
Post by: Jim on September 30, 2009
Can't remember - from the Freebasic ptc thread?