flat assembler
Message board for the users of flat assembler.

Index > Windows > plotting pixels to the screen

Author
Thread Post new topic Reply to topic
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 25 Jul 2009, 22:48
I'm trying to program a plotter that can animate plots in real time. I've looked at the Julia/Mandelbrot examples which are similar to what I want to do, but have not been able to figure out how to do the following:

1: set screen to 1024 by 768 mode
2: plot a given color at a given pixel coordinate
3: clear the whole screen (to black)
4: plot another point
5: exit upon key press

Would anyone who knows how to do this mind showing me how to code the above into a win32 program? Also, are 2 and 4 as simple as writting the color to a memory location?
Post 25 Jul 2009, 22:48
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 26 Jul 2009, 04:44
There are 3 popular ways to render in windows.
(You cant write directly to video memory)

1) GDI
2) DirectX
3) OpenGL

What is this application for, a game?
I have many demos, maybe one for you.
Post 26 Jul 2009, 04:44
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 26 Jul 2009, 07:14
I would like to make a program that animates plots in real-time. Each plot is generated not by calculating a color for each pixel but by a random walk-like process on the screen. Thus, it is almost necessary that the screen be cleared between plots. Each step in the walk requires 40-50 cycles to generate the next screen coordinate, and I would like to do 10^5 - 10^6 or so iterations. If I did the math right, this works out to a max of 46fps on a 2.3GHz cpu for a million iterations. I can't afford a performance hit for plotting each point, so I though writing directly to the screen buffer in memory would be a solution. I have seen something like this in the mandelbrot and juilia set programs involving [ddsd.lpSurface], but have not been able to extract the essential parts of these codes. Is [ddsd.lpSurface] not a pointer to the screen buffer? Any help would be appreciated. I am not too familiar with direct draw code.
Post 26 Jul 2009, 07:14
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 26 Jul 2009, 16:32
The DX surface is a buffer which gets transfered to screen.
If you are using WinXP or less you can make .com files
which can access video memory for VGA hardware.
That would be the fastest way to plot pixels.
Also i have made a simple OpenGL app which paints pixel.
The relevant code is commented like ;xxxxxxxxxxxxxxxx
If this turns out too slow for you i can help with the VGA coding.
You sure are lucky i have such a passion for graphics coding Very Happy


Description: OpenGL set pixel demo.
Download
Filename: pixel.zip
Filesize: 20.44 KB
Downloaded: 377 Time(s)


_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.


Last edited by bitshifter on 21 Sep 2009, 12:51; edited 1 time in total
Post 26 Jul 2009, 16:32
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 26 Jul 2009, 18:23
thanks. I'll write back as soon as I try it out
Post 26 Jul 2009, 18:23
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 27 Jul 2009, 04:33
Everything seems to be working up to the 1365th point. When glVertex2i is called for the 1365th time in render, something abnormal happens and all of the xmmx registers are cleared upon return. Are you able to reproduce this? Is there a limit to the number of points one can plot in one frame?
Post 27 Jul 2009, 04:33
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 31 Jul 2009, 20:26
I see no reason why you cant fill the entire resolution.
Post 31 Jul 2009, 20:26
View user's profile Send private message Reply with quote
Kuemmel



Joined: 30 Jan 2006
Posts: 200
Location: Stuttgart, Germany
Kuemmel 03 Aug 2009, 19:59
Hi tthsqe,

regarding your request about plotting something on the screen and waiting for key pressed, I stripped down my Mandelbrot bench (kind of fast rude strip down, some may be unusefull code, especially for threading left over).

You'll find it attached, it just displays now my palette data. So you should find the plot routine easily now. Everything should be there, like screen address, etc etc. Just read also up about DirectDraw, you need 'ddsd.lpSurface' for the address and also 'ddsd.lPitch'...to have the right offsets in case there.

You asked also about clearing the screen...so I don't do that in my code...but it would be just a memory fill to the screen or may be or for sure there might be some faster DirectDraw routine for that (sorry not a DirectDraw expert).


Description:
Download
Filename: KMB_plot.zip
Filesize: 5.17 KB
Downloaded: 261 Time(s)

Post 03 Aug 2009, 19:59
View user's profile Send private message Visit poster's website Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
windwakr 03 Aug 2009, 20:18
Kuemmel, have you tested that code? On my computer it went to fullscreen, drew the palette, and then COMPLETELY LOCKED UP MY SYSTEM. I had to hard boot my computer.
Post 03 Aug 2009, 20:18
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 03 Aug 2009, 21:03
IMO the easiest to use is SDL.
Post 03 Aug 2009, 21:03
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
windwakr 03 Aug 2009, 21:07
Someone should code up an example of SDL in assembly, I can't find anything about using it in assembly. It would require a lot of include converting...Ok, nvm...
Post 03 Aug 2009, 21:07
View user's profile Send private message Reply with quote
Kuemmel



Joined: 30 Jan 2006
Posts: 200
Location: Stuttgart, Germany
Kuemmel 03 Aug 2009, 21:46
windwakr wrote:
Kuemmel, have you tested that code? On my computer it went to fullscreen, drew the palette, and then COMPLETELY LOCKED UP MY SYSTEM. I had to hard boot my computer.

Hm, works well here on Vista 64 (but is 32bit code)...use ESC to exit after drawing...as I said, was quite a fast hack, might have some problems...the SDL stuff sounds quite nice...anybody setting it up for FASM !?
Post 03 Aug 2009, 21:46
View user's profile Send private message Visit poster's website Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
windwakr 03 Aug 2009, 21:54
I have 32 bit win xp sp3, It completely locks it up. ESC does nothing.

SDL in FASM would be quite an undertaking, but that would be awesome if someone managed it. Anyone here wanna do it? Too bad its not as simple as just importing the dll....
Post 03 Aug 2009, 21:54
View user's profile Send private message Reply with quote
c rex



Joined: 10 Sep 2009
Posts: 1
c rex 11 Sep 2009, 20:59
I used to code in visual basic, and someone showed me StretchDiBits which typically beats opengl and directx because they must convert video memory to normal ram, you do math, and memory is shot back to ram

Code:
Type RGBQUAD
 Blue  As Byte
 Green As Byte
 Red   As Byte
 Alpha As Byte
End Type

Type BITMAPINFOHEADER
    biSize          As Long 'vb 32 bits
    biWidth         As Long
    biHeight        As Long
    biPlanes        As Integer 'vb 16 bits
    biBitCount      As Integer
    biCompression   As Long
    biSizeImage     As Long
    biXPelsPerMeter As Long
    biYPelsPerMeter As Long
    biClrUsed       As Long
    biClrImportant  As Long
End Type

Type BITMAPINFO
    bmiHeader As BITMAPINFOHEADER
    bmiColors As RGBQUAD
End Type

Declare Function StretchDIBits Lib "gdi32" _
        (ByVal hDC As Long, _
         ByVal X As Long, _
         ByVal Y As Long, _
         ByVal dx As Long, _
         ByVal dy As Long, _
         ByVal SrcX As Long, _
         ByVal SrcY As Long, _
         ByVal wSrcWidth As Long, _
         ByVal wSrcHeight As Long, _
         lpBits As Any, _
         lpBitsInfo As BITMAPINFOHEADER, _
         ByVal wUsage As Long, _
         ByVal dwRop As Long) As Long

Public Const BI_RGB         As Long = 0
Public Const DIB_RGB_COLORS As Long = 0

'Function call

StretchDIBits DC, _
      X, Y, Wid, Hgt, _
      0, 0, BIH.biWidth, BIH.biHeight, _
      Array32bpp(0, 0), BIH, DIB_RGB_COLORS, vbSrcCopy
    

I think vbSrcCopy = 0
Post 11 Sep 2009, 20:59
View user's profile Send private message Reply with quote
pabloreda



Joined: 24 Jan 2007
Posts: 116
Location: Argentina
pabloreda 15 Oct 2009, 15:20
Hi, perhaps this help

I'm finish the core for compile and I use StretchDiBits, I don't finish the fullscreen mode.

this example fill the buffer and copy to video.


Description: core for :r4 language
Download
Filename: r4fasm.rar
Filesize: 3.73 KB
Downloaded: 235 Time(s)

Post 15 Oct 2009, 15:20
View user's profile Send private message Visit poster's website Reply with quote
Rahsennor



Joined: 07 Jul 2007
Posts: 61
Rahsennor 09 Nov 2009, 02:42
Google TinyPTC and its successor pixeltoaster. They use C, but they do exactly (and only) what you want and shouldn't take much to port to fasm.
Post 09 Nov 2009, 02:42
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.