I made a simple starfield example in C using Tinyptc. It's maybe not the most impressive example but it shows how simple pixel drawing can be done and should hopefully be fairly easy to follow. If you downloaded either of the DevCPP Tinyptc setups I post you can replace test.c with this code and recompile to see it in action. Anyone who has VC++, the code should also work if you have Tinyptc setup, I have tested in VC++.net 2003.
//
// TinyPTC Starfield
// Joncom2000 of TTD
//
// A little example of plotting some stars
#include "tinyptc.h"
#include <stdlib.h>
// Setuo screen
#define WIDTH 640
#define HEIGHT 480
#define SIZE WIDTH*HEIGHT
// Setup a buffer for our reading and writing
static int buffer[SIZE];
// Function declares
void Cls(int rgb);
void WritePixel(int x,int y,int rgb);
// Starfield variables
int starx[600];
int stary[600];
int main()
{
int i; //For loops
int speed; //For speed calcs
// Open our window/screen
if (!ptc_open("Stars_TTD by Joncom2000",WIDTH,HEIGHT)) return 1;
// setup stars
for (i=0; i<600; i++)
{
starx[i]=rand() % WIDTH;
stary[i]=rand() % HEIGHT;
}
// main loop exit
while (1)
{
Cls(0);
for (i=0; i<600; i++)
{
speed=1+(i % 3);
starx[i]=starx[i]+speed;
if (starx[i]>=WIDTH)
{
starx[i]=0;
}
WritePixel(starx[i],stary[i],((85*speed<<16)|(85*speed<<8)|85*speed));
}
ptc_update(buffer);
}
}
//-----------------------------------------------------------------
// Our Functions
//-----------------------------------------------------------------
void Cls(int rgb)
{
int x;
int y;
//Do cls stuff
for (y=0; y<HEIGHT; y++)
{
for (x=0; x<WIDTH; x++)
{
buffer[(y*WIDTH+x)] =rgb;
}
}
}
void WritePixel(int x,int y,int rgb)
{
//Do write pixel
if(x>-1)
{
if(x<WIDTH)
{
if(y>-1)
{
if(y<HEIGHT)
{
buffer[(y*WIDTH+x)] =rgb;
}
}
}
}
}
Any questions, problems please post and I will try to help.
Cheers
Jon