1
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
This is how it's done://-----------------------------------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------------------------------
int __cdecl ptc_torgb(unsigned char red, unsigned char green, unsigned char blue)
{
return 0xFFFFFFFFFF000000|(((red<<8)+green)<<8)+blue;
}
I was testing in the windows calculator converting various ARGB values into hex, and lots of F:s appeared in front of the colors.
// BGRA
return (blue<<24)|(green<<16)|(red<<8)|0xFF;
What's wrong here? I think there should be a torgb() function included in the lib.
I'm just trying out the library. Perhaps it will become a demo
int* buffer = malloc(RES_X*RES_Y);
memset(buffer, 0, RES_X*RES_Y);
ptc_update(buffer);
I'm slowly progressing with this thing now, and I found some v sync code by Rbraz:VSync: mov dx, 03DAh
in al,dx
test al,8
jz VSync
I have no idea why that works. What does "in" actually do?
However, I'm having a little problem with keyboard input. I found this code here on DBF:in al,60h ; keyboard check
dec al ; check for esc key
But I don't understand how that's supposed to check if escape is pushed. Is it possible to use this method for other keys as well?
Now, I just need to detect if the user is holding down a key.
But the paddle won't react when I push the up key, I must be doing something wrong.; ASM Pong
; By Phoenix September 22, 2007
org 100h ; COM
mov al, 13h ; Set up 13h resolution (320x200 256 colors)
int 10h ; Change to the resolution
Main: push ds ; Store the data segment's position on the stack, so we can get it back later
mov ax, 0a000h ; 0a000h = Video memory start
mov ds, ax ; Move ds to the 0a000h
mov cx, 65535 ; Start the counter at the end of the screen, so we can loop through all pixels
mov al, 0 ; Set the color to black
jmp ClearScreen ; Clear the screen
Render: mov cx, 30 ; Reset the height counter, making the paddle 30px high
jmp DrawPaddle ; Draw the first rectangle
Update: pop ds ; Return the old data segment to non-video memory
mov ah, 0 ; Prepare for key input, 0=read a key
int 16h ; Check for input, stores it in ah
cmp ah, 48h ; Was it the 'up' key?
je MoveUp ; If so, move!
cmp ah, 01 ; Was it escape?
jne Main ; If not, then just continue to playing
mov ax, 4c00h ; Prepare for exit
int 21h ; Exit
DrawPaddle: mov ax, 320 ; Start of with the screen width in the coordinate formula
mov bl, [y1] ; Set up the next parameter in the multiplication; y value
add bx, cx ; Add the current vertical position to the multiplication
mul bx ; Calculate!
add al, [x1] ; Add the x position to the final product
mov si, ax ; Set the drawing position, screen coordinates described as ScreenWidth*y+x
mov al, 255 ; Color 255 in the default palette (White)
mov [si], al ; Poke the pixel into memory
loop DrawPaddle ; Loop until cx (rectangle height counter) is 0
jmp Update ; Then go back to the main loop
MoveUp: inc byte [y1]
jmp Main ; Go back to the main loop
ClearScreen: mov si, cx ; Set the position to clear
mov [si], al ; Clear that pixel
loop ClearScreen ; Go to the next pixel
jmp Render ; Return to the main loop
; Variables
x1 db 10 ; Player 1's x
x2 db 160 ; Player 2's y
y1 db 100 ; Player 1's x
y2 db 100 ; Player 2's y
scoretext db " Score: $" ; The text that goes before the score, centered using spaces
score1 db "0$" ; Player 1's score
dash db "-$" ; Dash separating scores
score2 db "0$" ; Player 2's score
; ASM Pong
; By Phoenix September 22, 2007
org 100h ; COM
mov al, 13h ; Set up 13h resolution (320x200 256 colors)
int 10h ; Change to the resolution
mov ax, 0a000h ; 0a000h = Video memory start
mov ds, ax ; Move ds to the 0a000h
Main: mov cx, 65535 ; Start the counter at the end of the screen
mov al, 0 ; Set the color to black
jmp ClearScreen ; Clear the screen
Render: mov cx, 30 ; Reset the height counter
mov bx, 0
jmp DrawPaddle ; Draw the first rectangle
Update: mov bh, 0
mov ah, 00 ; Prepare for key input
int 16h ; Check for input, stores it in ah
cmp ah, 48h ; Was it the 'up' key?
je MoveUp ; If so, move!
cmp ah, 01 ; Was it escape?
jne Main ; If not, then just continue to playing
mov ax, 4c00h ; Prepare for exit
int 21h ; Exit
DrawPaddle: mov ax, 320 ; Start of with the screen width in the coordinate formula
mov bl, [y1] ; Set up the next parameter in the multiplication; y value
add bx, cx ; Add the current vertical position to the multiplication
mul bx ; Calculate!
add al, [x1] ; Add the x position to the final product
mov si, ax ; Set the drawing position, screen coordinates described as ScreenWidth*y+x
mov al, 255 ; Color 255 in the default palette (White)
mov [si], al ; Poke the pixel into memory
loop DrawPaddle ; Loop until cx (rectangle height counter) is 0
jmp Update ; Then go back to the main loop
MoveUp: inc byte [y1]
jmp Main ; Go back to the main loop
ClearScreen: mov si, cx ; Set the position to clear
mov [si], al ; Clear that pixel
loop ClearScreen ; Go to the next pixel
jmp Render ; Return to the main loop
; Variables
x1 db 10 ; Player 1's x
x2 db 160 ; Player 2's y
y1 db 100 ; Player 1's x
y2 db 100 ; Player 2's y
scoretext db " Score: $" ; The text that goes before the score, centered using spaces
score1 db "0$" ; Player 1's score
dash db "-$" ; Dash separating scores
score2 db "0$" ; Player 2's score


; ASM Pong
; By Phoenix September 22, 2007
org 100h ; COM
mov al, 13h ; Set up 13h resolution (320x200 256 colors)
int 10h ; Change to the resolution
mov ax, 0a000h ; 0a000h = Video memory start
mov ds, ax ; Move ds to the 0a000h
Render: mov cx, 30 ; Reset the height counter
mov bx, 0
jmp DrawPaddle ; Draw the first rectangle
Update: mov bh, 0
mov ah, 00 ; Prepare for key input
int 16h ; Check for input, stores it in ah
cmp ah, 48h ; Was it the 'up' key?
je MoveLeft ; If so, move!
cmp ah, 01 ; Was it escape?
jne Render ; If not, then just continue to playing
mov ax, 4c00h ; Prepare for exit
int 21h ; Exit
DrawPaddle: mov ax, 320 ; Start of with the screen width in the coordinate formula
mov bx, y1 ; Set up the next parameter in the multiplication; y value
add bx, cx ; Add the current vertical position to the multiplication
mul bx ; Calculate!
add ax, x1 ; Add the x position to the final product
mov si, ax ; Set the drawing position, screen coordinates described as ScreenWidth*y+x
mov al, 255 ; Color 255 in the default palette (White)
mov [si], al ; Poke the pixel into memory
loop DrawPaddle ; Loop until cx (rectangle height counter) is 0
jmp Update ; Then go back to the main loop
MoveLeft: inc [y1]
jmp Render ; Go back to the main loop
; Variables
x1 db 10 ; Player 1's x
x2 db 160 ; Player 2's y
y1 db 100 ; Player 1's x
y2 db 100 ; Player 2's y
rectLoop db 0
scoretext db " Score: $" ; The text that goes before the score, centered using spaces
score1 db "0$" ; Player 1's score
dash db "-$" ; Dash separating scores
score2 db "0$" ; Player 2's score
Gdi.PIXELFORMATDESCRIPTOR pfd = new Gdi.PIXELFORMATDESCRIPTOR();// The pixel format descriptor
pfd.nSize = (short) Marshal.SizeOf(pfd); // Size of the pixel format descriptor
pfd.nVersion = 1; // Version number (always 1)
pfd.dwFlags = Gdi.PFD_DRAW_TO_WINDOW | // Format must support windowed mode
Gdi.PFD_SUPPORT_OPENGL | // Format must support OpenGL
Gdi.PFD_DOUBLEBUFFER; // Must support double buffering
pfd.iPixelType = (byte) Gdi.PFD_TYPE_RGBA; // Request an RGBA format
pfd.cColorBits = (byte) colorBits; // Select our color depth
pfd.cRedBits = 0; // Individual color bits ignored
pfd.cRedShift = 0;
pfd.cGreenBits = 0;
pfd.cGreenShift = 0;
pfd.cBlueBits = 0;
pfd.cBlueShift = 0;
pfd.cAlphaBits = 0; // No alpha buffer
pfd.cAlphaShift = 0; // Alpha shift bit ignored
pfd.cAccumBits = accumBits; // Accumulation buffer
pfd.cAccumRedBits = 0; // Individual accumulation bits ignored
pfd.cAccumGreenBits = 0;
pfd.cAccumBlueBits = 0;
pfd.cAccumAlphaBits = 0;
pfd.cDepthBits = depthBits; // Z-buffer (depth buffer)
pfd.cStencilBits = stencilBits; // No stencil buffer
pfd.cAuxBuffers = 0; // No auxiliary buffer
pfd.iLayerType = (byte) Gdi.PFD_MAIN_PLANE; // Main drawing layer
pfd.bReserved = 0; // Reserved
pfd.dwLayerMask = 0; // Layer masks ignored
pfd.dwVisibleMask = 0;
pfd.dwDamageMask = 0;
windowForm = new Form();
windowForm.ClientSize = new Size( ScreenWidth, ScreenHeight );
windowWidth = windowForm.Width;
windowHeight = windowForm.Height;
windowForm.Icon = null;
windowForm.Text = windowTitle;
windowForm.FormClosing += new FormClosingEventHandler( windowForm_FormClosing );
windowForm.Resize += new EventHandler( windowForm_Resize );
// Window mode specific settings
// Changes borders/control boxes/etc
switch( mode )
{
case WindowMode.Windowed:
windowForm.FormBorderStyle = FormBorderStyle.FixedSingle;
windowForm.MaximizeBox = false;
windowForm.MinimizeBox = false;
break;
case WindowMode.Fullscreen:
Resolution.CResolution changeRes = new Resolution.CResolution( screenWidth, screenHeight );
windowForm.FormBorderStyle = FormBorderStyle.None;
windowForm.WindowState = FormWindowState.Maximized;
windowForm.TopMost = true;
break;
case WindowMode.WindowScalable:
windowForm.FormBorderStyle = FormBorderStyle.Sizable;
break;
case WindowMode.BorderlessWindow:
windowForm.FormBorderStyle = FormBorderStyle.None;
break;
}
// Initialize the OpenGL graphics device
glDevice = new SimpleOpenGlControl();
glDevice.Location = new Point( 0, 0 );
glDevice.Size = new Size( screenWidth, screenHeight );
glDevice.InitializeContexts();
windowForm.Controls.Add( glDevice );
// Set up OpenGL
Gl.glMatrixMode( Gl.GL_PROJECTION );
Gl.glOrtho( 0, screenWidth, screenHeight, 0, -1, 1 );
Gl.glMatrixMode( Gl.GL_MODELVIEW );
Gl.glClearColor( 1, 1, 1, 1 );
// Enable transparency
Gl.glBlendFunc( Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA );
Gl.glEnable( Gl.GL_BLEND );
// We're done setting up, so the program is running
running = true;
// Show the created window
windowForm.Show();
Gl.glBegin( Gl.GL_QUADS );
Gl.glVertex3f( X, Y, 0.0f );
Gl.glVertex3f( (Width + X), Y, 0.0f );
Gl.glVertex3f( (Width + X), (Height + Y), 0.0f );
Gl.glVertex3f( X, (Height + Y), 0.0f );
Gl.glEnd();Without any textures, colors or anything, and I get 15-20 fps. Is that normal? Should I stop using glBegin/glEnd?