Well it looks like you are in console mode which is not going to work. If you could get a small DirectX startup module working you could plot pixels via DirectX and pointers to your double buffer and primary surfaces.
The only way in console mode is to plot periods - which looks dumb and which is reverse of graphics. Text is in row,col which is actually y,x - also the values I used in the starfield program are much too large for text mode.
For DOS users this code will complete the program. Note that I used some assembly - but you do not have to. For flipping the back buffer to the screen you could memcpy() and for clearing the screen use memset(). Please no stupid comments about the code not being portable, only for DOS, blah, blah, blah....
Because this code can be used inside of a DirectX framework as well as D3D - but in D3D would be a bit different. The DirectX version of this code only lacks the back buffer and primary surface code (locking, unlocking, etc)- as well as the startup section.
Code:
//y*320+x - most compilers should turn this into the following
#define XYTOMEM((y<<8)+(y<<6)+(x))
//BYTE typedef
typedef unsigned char BYTE;
//Real-mode pointers to double buffer and screen
BYTE far *Screen;
BYTE far *Buffer;
//Prototypes
void Init(void);
void CLS(BYTE far *tBuffer,BYTE color);
void Flip(void);
void PlotPixel(int x,int y,BYTE color);
//Init screen mode and pointers
void Init(void)
{
REGS regs;
regs.x.ax=0x0013;
int86(0x10,& regs,& regs);
Screen=(BYTE far *)MK_FP(0xa000,0);
Buffer=new BYTE[64000L];
//Should check for Buffer validity here, but didn't
}
//Clears any 64000 byte buffer to the set color
void CLS(BYTE far *tBuffer,BYTE color)
{
asm {
les di,[tBuffer]
mov cx,07D00h //32000 words
mov ah,[color]
mov al,[color]
rep stosw
}
}
//Copies memory - uses words, not bytes
//Copies back buffer to video memory
void Flip(void)
{
asm {
push ds
lds si,[Buffer]
les di,[Screen]
mov cx,07D00h
rep movsw
pop ds
}
}
//Plots a pixel - do not call this - place this in DrawStars() as is
//Calling this inside of the draw loop slows the program down
void PlotPixel(int x,int y,BYTE color)
{
Buffer[XYTOMEM(x,y)]=color;
}
Here is the new main:
Code:
int main(void)
{
double MySpeed=.5;
CreateStars();
while (!kbhit())
{
CLS(Buffer,0);
MoveStars(MySpeed);
ProjectStars();
DrawStars();
Flip();
}
return(0);
}
Here is the new DrawStars()
Code:
void DrawStars()
{
for (int i=0;i<NUMSTARS;i++)
{
int x=Stars[i].Screen.x;
int y=Stars[i].Screen.y;
if (x>0 && x<320)
{
if (y>0 && y<200)
{
Buffer[XYTOMEM(x,y)]=WHITE;
}
}
}
}