flat assembler
Message board for the users of flat assembler.

Index > Windows > Where do I put my OpenGL drawing routine?

Author
Thread Post new topic Reply to topic
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
I'm new to OpenGL, so much confusion;

Do I draw in a separate thread? That seems to create problems with glBegin and glEnd.

Do I draw in my main window message pump? Then how do I make it redraw when it should? Does it redraw automatically? Do I need to send WM_PAINTs manually at intervals?

Where do I put the input routine? In the draw routine?

_________________
This is a block of text that can be added to posts you make.
Post 28 Apr 2011, 06:49
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
put them in the while getmessage loop.
or use setTimer and draw at each interval in either TimerProc or on WM_TIMER
Post 28 Apr 2011, 11:52
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17628
Location: In your JS exploiting you and your system
revolution
There is an OpenGL example already in the fasm download.
Post 28 Apr 2011, 11:55
View user's profile Send private message Visit poster's website Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
How and why do I put it in the getmessage loop? Do I make it a peekmessage loop? What advantage over putting it in the wndproc?

Can I put it in WM_TIMER instead?

The GL example I think abuses the message queue or something, it gobbles up an entire cpu core.
Post 28 Apr 2011, 21:26
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Enko



Joined: 03 Apr 2007
Posts: 678
Location: Mar del Plata
Enko
As I understand, you can use 3 options:

1)on WMPAINT in msg LOOP. (But it will be updated only when the windows needs to updated, somthing drawed over your windows)

2)Use a WM_TIMER: only draws when the WMTIMER event is activated.

3)Use peek Msg, this way, is the most used in games, becous as i get it, you dont wait a msg, you intercept it.
Post 28 Apr 2011, 21:58
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
you can just do this.

; This is also good as it gives you control as to when you want to draw

; meaning how many frames per second.


SetTimer,[hwnd],[timerId],[interVal],timerProc



proc timerProc hwnd, msg,id,elapsed

;TODO GL code here

ret
endp
Post 28 Apr 2011, 23:18
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
The problem is that when my glbegin..glEnd is in a different thread than the wndproc, responding to WM_SIZE and invoking glViewport fails when between glBegin and glEnd.
Post 29 Apr 2011, 05:17
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
mindcooler wrote:
The problem is that when my glbegin..glEnd is in a different thread than the wndproc, responding to WM_SIZE and invoking glViewport fails when between glBegin and glEnd.


use global variables or flags.. Wink
Code:
cmp [msg],WM_SIZE

mov [sized],1
....

proc timerProc

glBegin

cmp [sized],1
je    .notSized

.notSized:

;//TODO code goes here if window is not re-sized.
glEnd
    


Does that help ?
Post 29 Apr 2011, 05:36
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
Hmm, I guess. I'll try it out. Then I should be able to contain everything in it's own self-timed thread.
Post 29 Apr 2011, 16:03
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
My OpenGL demo for Win32
http://board.flatassembler.net/topic.php?t=9262
Have fun Smile
Post 30 Apr 2011, 02:42
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
Own self timed draw thread using global flags it seems. Sounds like the way to go. But I don't get the peekmessage loop.

2300 fps without the sleep. Razz Mouse input breaks with the sleep.
Post 30 Apr 2011, 16:17
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
Trying to get the aspect ratio correct, 4:3.

Any idea why nothing at all shows up on screen if the values of glOrtho differs even slightly from these values?

Code:
                invoke  glMatrixMode,GL_PROJECTION
                invoke  glLoadIdentity
                invoke  glOrtho,1.0,-1.0,1.0,-1.0,1.0
                invoke  glGetError
                invoke  glMatrixMode,GL_MODELVIEW
                invoke  glLoadIdentity    

_________________
This is a block of text that can be added to posts you make.
Post 01 May 2011, 01:23
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
My font demo is much simpler and uses ortho projection.
http://board.flatassembler.net/topic.php?t=9885
By convention, opengl sets ortho screen [0,0] at bottom left.
You can flip the values to make it top left instead.
Also note where double parameters are passed (not dwords but qwords)
Post 01 May 2011, 08:12
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
My example was missing an operand, but I still don't understand what's going on.

Code:
invoke  glOrtho,1.0,-1.0,1.0,-1.0,1.0,-1.0
    


Gives an error 501 and probably defaults to some standard view, showing my cube.

Code:
invoke  glOrtho,1.001,-1.001,1.0,-1.0,1.0,-1.0
    


gives no error, but present a black screen.

-----realization: glOrtho expects doubles------

I tried glFrustum too, with similiar results: (I can't use x headers)
Either it fails with error 501 and presents my cube orthogonally, or it accepts the operands and shows nothing.

Code:
                mov     esi,frustum
                push    dword [esi+40]
                push    dword [esi+44]

                push    dword [esi+32]
                push    dword [esi+36]

                push    dword [esi+24]
                push    dword [esi+28]

                push    dword [esi+16]
                push    dword [esi+20]

                push    dword [esi+08]
                push    dword [esi+12]

                push    dword [esi]
                push    dword [esi+04]
                invoke  glFrustum    



What operands should I use if I just want to show my sidelength 1 cube that sits in the origin?

Do I pass the parameters correctly?

_________________
This is a block of text that can be added to posts you make.
Post 01 May 2011, 21:32
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Take my wgl font demo (wglfont.asm) and plug this into it...
Code:
; TODO: Render 2D shit here...

        invoke  glPushMatrix
        invoke  glTranslatef,256.0,256.0,0.0     ;x = 256, y = 256 (pixels from bottom left)
        invoke  glColor3ub,255,255,255       ;white
        invoke  glBegin,GL_QUADS
        invoke  glVertex2i,-10,-10         ;10 pixels width,height (z = 0)
        invoke  glVertex2i,-10,10
        invoke  glVertex2i,10,10
        invoke  glVertex2i,10,-10
        invoke  glEnd
        invoke  glPopMatrix
    

Doing it in 3D with ortho is no different except 3D vertices with glVertex3*
Also translating to screenwidth/2, screenheight/2 puts it center of screen.
Make sure you know exactly what a function does before using it.
Hope this helps Smile

Ramble: I am thinking of OpenGL tutorial series for FASM.
If enough people show interest i may do it...

_________________
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.
Post 02 May 2011, 02:31
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
I have no trouble with the modelview matrices, only getting the perspective matrix going.

I pushed the doubles in the wrong order, with this I actually get something with some kind of perspective on screen:

Code:
                mov     esi,frustum
                push    dword [esi+44]
                push    dword [esi+40]

                push    dword [esi+36]
                push    dword [esi+32]

                push    dword [esi+28]
                push    dword [esi+24]

                push    dword [esi+20]
                push    dword [esi+16]

                push    dword [esi+12]
                push    dword [esi+08]

                push    dword [esi+04]
                push    dword [esi]
                invoke  glFrustum

                frustum         dq 5.0,-5.0,5.0,-5.0,0.1,5.0    

_________________
This is a block of text that can be added to posts you make.
Post 02 May 2011, 17:08
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.