Recent

Author Topic: Port "voxel" DOS demo to Lazarus  (Read 10586 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2365
    • UVviewsoft
Port "voxel" DOS demo to Lazarus
« on: August 10, 2020, 09:58:24 am »
https://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/demo/modex/voxel.pp?view=markup&revision=3&root=fpcbuild

I need to know what to do with
procedure draw(xp,yp,dir:integer);
-it does this to clear data:   fillchar(scr^,64000,0);
-it puts data to some DOS memory:   Move(Scr^,mem[$A000:0],64000);

How to show this data (array with 64K size) on Lazarus canvas?


marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Port "voxel" DOS demo to Lazarus
« Reply #1 on: August 10, 2020, 09:59:34 am »
Draw every pixel. The whole idea of ModeX was that the screen was linear in 64kb memory as typically an 8-bit color paletted image.

 Maybe it is easiest to use opengl, and treat it as texture, with and 1D texture for lookup

AlexTP

  • Hero Member
  • *****
  • Posts: 2365
    • UVviewsoft
Re: Port "voxel" DOS demo to Lazarus
« Reply #2 on: August 10, 2020, 10:06:22 am »

AlexTP

  • Hero Member
  • *****
  • Posts: 2365
    • UVviewsoft
Re: Port "voxel" DOS demo to Lazarus
« Reply #3 on: August 10, 2020, 10:44:11 am »
I have now such picture-- is it like DOS one?
What is DOS look?

(Arrow keys work OK, but colors...)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Port "voxel" DOS demo to Lazarus
« Reply #4 on: August 10, 2020, 10:46:53 am »
It's long ago, but I don't remember those colors. Maybe bgr vs rgb ?

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Port "voxel" DOS demo to Lazarus
« Reply #5 on: August 10, 2020, 10:51:13 am »
That does not seem really to be modeX in the code. Rather a bitmap where each pixel is a bye index to a palette.

EDIT: Oh that is non planar modeX, ok.

You could create an TLazIntfImage with this data, then create the TBitmap and draw it.

Or update an RGBA bitmap with the color from the palette (using BGRABitmap, Graphics32, OpenGL etc.)
« Last Edit: August 10, 2020, 10:54:39 am by circular »
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Port "voxel" DOS demo to Lazarus
« Reply #6 on: August 10, 2020, 10:52:15 am »
I have now such picture-- is it like DOS one?
What is DOS look?

(Arrow keys work OK, but colors...)
The palette color values were sent via the Port. So it means that they are from 0 to 63 instead of 0 to 255.
Conscience is the debugger of the mind

AlexTP

  • Hero Member
  • *****
  • Posts: 2365
    • UVviewsoft
Re: Port "voxel" DOS demo to Lazarus
« Reply #7 on: August 10, 2020, 10:58:51 am »

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: Port "voxel" DOS demo to Lazarus
« Reply #8 on: August 10, 2020, 01:36:10 pm »
Not sure, how to do it in portable style, but on Windows it's better to draw on memory bitmap and then use SetDIBitsToDevice or StretchDIBits to draw it on canvas with hardware acceleration. Only thing to note - by default DI bitmap is upside-down. I guess, CreateDIBSection is also suitable for this purpose, but I haven't used it in my projects.
« Last Edit: August 10, 2020, 01:45:14 pm by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Port "voxel" DOS demo to Lazarus
« Reply #9 on: August 10, 2020, 04:07:46 pm »
You can use TBGRABitmap to implicitly use a DIB bitmap.

Though in this case, using an TLazIntfImage with a palette might be faster.
Conscience is the debugger of the mind

AlexTP

  • Hero Member
  • *****
  • Posts: 2365
    • UVviewsoft
Re: Port "voxel" DOS demo to Lazarus
« Reply #10 on: August 10, 2020, 04:28:20 pm »
I am done with porting, all on github. IMO change for LazIntfImage isn't needed.

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: Port "voxel" DOS demo to Lazarus
« Reply #11 on: August 10, 2020, 08:09:06 pm »
It's better to do it, as it's 100 times faster.

P.S. In CODE2 I've tried to avoid unnecessary extra Canvas.Draw.

P.P.S. And yeah. Original example doesn't actually use ModeX. It's just plain simple Mode13 with "software" double buffering, that is very reliable, as it doesn't require VSync (forced for VGA - page flip just can't occur in a middle of a frame), but at the same time very slow.
« Last Edit: August 10, 2020, 08:46:34 pm by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

AlexTP

  • Hero Member
  • *****
  • Posts: 2365
    • UVviewsoft
Re: Port "voxel" DOS demo to Lazarus
« Reply #12 on: August 10, 2020, 10:35:45 pm »
Applied to repo: with CODE1 define, to use it here on Linux.

You are good.

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Port "voxel" DOS demo to Lazarus
« Reply #13 on: August 10, 2020, 11:45:25 pm »
Nice @Mr.Madguy

One memory leak though: the Header is allocated each time.
Conscience is the debugger of the mind

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: Port "voxel" DOS demo to Lazarus
« Reply #14 on: August 11, 2020, 07:39:06 am »
Nice @Mr.Madguy

One memory leak though: the Header is allocated each time.
It's allocated in OnCreate, freed in OnDestroy and it's "local" form variable. It shouldn't be memory leak.

I have never used BGRABitmap or TLazIntfImage, so I couldn't implement it in portable fashion. But, I guess, this two use something like SetDIBitsToDevice internally anyway. I'll try to do it today.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

 

TinyPortal © 2005-2018