Show Posts

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.


Messages - Phoenix

Pages: [1] 2 3 4
1
Coding tutorials / Re: OpenGL framebuffer library
« on: October 15, 2007 »
You're right :) It can be shortened to:
Code: [Select]
return 0xFF+(((red<<8)+green)<<8)+blue;

2
Coding tutorials / Re: OpenGL framebuffer library
« on: October 15, 2007 »
I solved it :) This is how it's done:
Code: [Select]
//-----------------------------------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------------------------------
int __cdecl ptc_torgb(unsigned char red, unsigned char green, unsigned char blue)
{
return 0xFFFFFFFFFF000000|(((red<<8)+green)<<8)+blue;
}

However, I have no idea how it works :P I was testing in the windows calculator converting various ARGB values into hex, and lots of F:s appeared in front of the colors.

3
Coding tutorials / Re: OpenGL framebuffer library
« on: October 15, 2007 »
I tried to write a function that converts RGB to a single value, but with no luck:
Code: [Select]
// 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.

4
Coding tutorials / Re: OpenGL framebuffer library
« on: October 15, 2007 »
I don't know what I'm making actually :P I'm just trying out the library. Perhaps it will become a demo :)

5
Coding tutorials / Re: OpenGL framebuffer library
« on: October 15, 2007 »
Thanks Jim, that works great :)

6
Coding tutorials / Re: OpenGL framebuffer library
« on: October 14, 2007 »
Code: [Select]
int* buffer = malloc(RES_X*RES_Y);
memset(buffer, 0, RES_X*RES_Y);

ptc_update(buffer);

Isn't that how it's supposed to be done? I get an unhandled exception when I try to run it.

7
ASM / Re: Pong in Assembly
« on: September 25, 2007 »
Oddly enough, everything is rendered just fine with one exception. Everything that's drawn at the top ~30 pixels is invisible or flashing heavily. Does anyone know what the problem might be? Should I post the source?

8
ASM / Re: Pong in Assembly
« on: September 23, 2007 »
I decided to use the "in al, 60h" method; it works, and that's good enough for me ;) I'm slowly progressing with this thing now, and I found some v sync code by Rbraz:
Code: [Select]
VSync: mov dx, 03DAh
       in al,dx
       test al,8
       jz VSync
I have no idea why that works. What does "in" actually do?

9
ASM / Re: Pong in Assembly
« on: September 23, 2007 »
That works, and my code looks a little better now :) However, I'm having a little problem with keyboard input. I found this code here on DBF:
Code: [Select]
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?

10
ASM / Re: Pong in Assembly
« on: September 23, 2007 »
FASM doesn't like that, and says that jsr is an illegal instruction. Also, jsr doesn't exist in the FASM manual. Are you using another assembler?

11
ASM / Re: Pong in Assembly
« on: September 23, 2007 »
I can't find any information on how to use subroutines, how do they work?

12
ASM / Re: Pong in Assembly
« on: September 22, 2007 »
Yes! That's it! Thanks a lot Stonemonkey :) Now, I just need to detect if the user is holding down a key.

13
ASM / Re: Pong in Assembly
« on: September 22, 2007 »
The dot isn't showing up now :) But the paddle won't react when I push the up key, I must be doing something wrong.
Code: [Select]
; 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

14
ASM / Re: Pong in Assembly
« on: September 22, 2007 »
The dot still flashes that way :-\

Edit: Updated code, with screen clearing:
Code: [Select]
; 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

15
ASM / Re: Pong in Assembly
« on: September 22, 2007 »
Aha, that's the problem. I'll change the code and see if I can get it working. Thanks :)

Edit: But how am I supposed to increase y1 if I can't type inc [y1]?

16
ASM / Pong in Assembly
« on: September 22, 2007 »
I'm attempting to create pong, in FASM. Maybe it seems quite pointless, but I want to brush my assembly skills. So far, I have been progressing quite well, until I wanted to add movement. When the I press the up key, y1 is increased, but the paddle doesn't move. Instead, a colored dot appears at the top of the screen. This dot also comes if I change y1 to, well any variable I have defined. My guess is that I'm accessing the video memory at some place where I shouldn't be doing it, but I'm unsure where. Good news though, is that nowadays I comment my code ;)
Code: [Select]
; 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

Why am I experiencing this weird behavior? How do I fix it?

Many many thanks in advance,
Martin :)

17
General coding questions / Re: OpenGL texturing
« on: September 04, 2007 »
No luck, I changed them but the FPS still sits at 15-20.

18
General coding questions / Re: OpenGL texturing
« on: September 04, 2007 »
I'm using a SimpleOpenGLControl (found in the Tao framework), with C#, and it's attached to  a Windows Form. Pixel format seems to be normal:
Code: [Select]
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;

Complete window code, if needed.
Code: [Select]
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();

19
General coding questions / Re: OpenGL texturing
« on: September 04, 2007 »
1.5 GHz Intel processor, 64mb graphics card. Runs at more than 1000 fps with 2.54 GHz Intel/256mb video memory.

20
General coding questions / Re: OpenGL texturing
« on: September 04, 2007 »
After stripping the code down a lot, there aren't many lines left. This is called 500 times:
Code: [Select]
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?

Pages: [1] 2 3 4