flat assembler
Message board for the users of flat assembler.

Index > Windows > Troubles with openGL

Author
Thread Post new topic Reply to topic
Fred



Joined: 22 Oct 2010
Posts: 39
Fred 27 Feb 2011, 20:16
Been toying with openGL and trying to do 2D tile drawing and looked at this page for tips. According to this dood I can use gluOrtho2D (or glOrtho i guess) to set up a nice coordinate system thing on my window. But... well. It's not working. Setting glOrtho to anything but a square makes the screen go black and setting it to a square does nothing (screen coords remain as -1 to 1). I have no idea how to fix it. Neutral Can someone help me?

The reason i'm posting about openGL problems here is because I'm not sure if the error springs from my unawesome asm code or if my openGL knowledge is lacking... help is appreciated. Razz

Here's my current code: http://pastebin.com/g6H8nVnS (glOrtho is on line 123, and most of my other openGL code is around there too)
And if you want to run it: used includes and the image. Just put the folder in the fasm include folder and yeah.raw in the same folder as the code.

I have ninja'd code from various places (but mostly from here). And I'll say this now... I have never used openGL before. Razz
Post 27 Feb 2011, 20:16
View user's profile Send private message Reply with quote
SFeLi



Joined: 03 Nov 2004
Posts: 138
SFeLi 28 Feb 2011, 06:55
Both gluOrtho2D and glOrtho accept double arguments and you're passing floats. Include win32ax.inc instead of win32a.inc and prefix arguments with 'double' keyword.
Post 28 Feb 2011, 06:55
View user's profile Send private message Reply with quote
Xorpd!



Joined: 21 Dec 2006
Posts: 161
Xorpd! 28 Feb 2011, 07:17
You have to handle the WM_SIZE message and set your viewport there.
Post 28 Feb 2011, 07:17
View user's profile Send private message Visit poster's website Reply with quote
Fred



Joined: 22 Oct 2010
Posts: 39
Fred 28 Feb 2011, 13:26
Quote:
Both gluOrtho2D and glOrtho accept double arguments and you're passing floats. Include win32ax.inc instead of win32a.inc and prefix arguments with 'double' keyword.

Oh, didn't think of that! ...It works now! Thank you! I probably wouldn't have come up with that myself. Razz


Quote:
You have to handle the WM_SIZE message and set your viewport there.

Ok. Doesn't work... strange. It should work...
Anyway, resizing the window isn't important at the moment, but could come in handy later.


*general praise to awesome fasm board users*
Post 28 Feb 2011, 13:26
View user's profile Send private message Reply with quote
Xorpd!



Joined: 21 Dec 2006
Posts: 161
Xorpd! 28 Feb 2011, 20:22
Your reply has piqued my curiosity: did you finally come up with something that worked but yet did not handle the WM_SIZE message? Could you post your working example?
Post 28 Feb 2011, 20:22
View user's profile Send private message Visit poster's website Reply with quote
Fred



Joined: 22 Oct 2010
Posts: 39
Fred 28 Feb 2011, 21:34
Hmm, well, all I did was copying the openGL example:

Code:
        cmp     [wmsg],WM_CREATE
        je      .wmcreate
        cmp     [wmsg],WM_SIZE
        je      .wmsize    
[...]
  .wmcreate:
        invoke  GetDC,[hwnd]
        mov     [hdc],eax
        mov     edi,pfd
        mov     ecx,sizeof.PIXELFORMATDESCRIPTOR shr 2
        xor     eax,eax
        rep     stosd
        mov     [pfd.nSize],sizeof.PIXELFORMATDESCRIPTOR
        mov     [pfd.nVersion],1
        mov     [pfd.dwFlags],PFD_SUPPORT_OPENGL+PFD_DOUBLEBUFFER+PFD_DRAW_TO_WINDOW
        mov     [pfd.iLayerType],PFD_MAIN_PLANE
        mov     [pfd.iPixelType],PFD_TYPE_RGBA
        mov     [pfd.cColorBits],16
        mov     [pfd.cDepthBits],16
        mov     [pfd.cAccumBits],0
        mov     [pfd.cStencilBits],0
        invoke  ChoosePixelFormat,[hdc],pfd
        invoke  SetPixelFormat,[hdc],eax,pfd
        invoke  wglCreateContext,[hdc]
        mov     [hrc],eax
        invoke  wglMakeCurrent,[hdc],[hrc]
        invoke  GetClientRect,[hwnd],rc
        invoke  glViewport,0,0,[rc.right],[rc.bottom]
        invoke  GetTickCount
        mov     [clock],eax
        xor     eax,eax
        jmp     .finish
  .wmsize:
        invoke  GetClientRect,[hwnd],rc
        invoke  glViewport,0,0,[rc.right],[rc.bottom]
        xor     eax,eax
        jmp     .finish  
[...]
    


Since the viewport is set up in .wmcreate i went ahead and removed the .wmsize section. For some reason I can't resize the window, so .wmsize would do nothing anyway.
Post 28 Feb 2011, 21:34
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.