flat assembler
Message board for the users of flat assembler.

Index > Windows > double precision function arguments

Author
Thread Post new topic Reply to topic
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 28 Aug 2008, 03:20
Hello, i am coding the last piece of my opengl demo template and need help with passing double precision values to some of the opengl functions.

Function prototype:
GLvoid gluPerspective(
GLdouble fovy,
GLdouble aspect,
GLdouble znear,
GLdouble zfar);

My variables:
g_fovy dq 45.0
g_aspect dq 1.3
g_znear dq 0.1
g_zfar dq 100.0

My first attempt:
invoke gluPerspective,[g_fovy],[g_aspect],[g_znear],[g_zfar]
Assembler complains, i go find invoke macro and see why.
Ahhh... invoke macro expects dword type arg.

My second attempt:
push dword [g_zfar+4]
push dword [g_zfar]
push dword [g_znear+4]
push dword [g_znear]
push dword [g_aspect+4]
push dword [g_aspect]
push dword [g_fovy+4]
push dword [g_fovy]
call gluPerspective

Now program crashes... 'cry'

My third attempt:
Read manual some more.
Search google for answers.
Six hours later...
No new idea's...

So now here i am, a total noob, with black rings under his eyes and cigarette stains on his fingers from staying up all night looking at screen.

Im sure its my own ignorance that is the problem, probably quite obvious to some asm guru such as yourself, so please post a solution...
Post 28 Aug 2008, 03:20
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 28 Aug 2008, 03:44
http://flatassembler.net/docs.php?article=win32

2.1 Procedure parameters wrote:
If the parameter is preceded by the word double, it is treated as 64-bit value and passed to the procedure as two 32-bit parameters. For example:

invoke glColor3d,double 1.0,double 0.1,double 0.1

will pass the three 64-bit parameters as six double words to procedure. If the parameter following double is the memory operand, it should not have size operator, the double already works as the size override.


But still, are you sure the crash is because of the gluPerspective call?
Post 28 Aug 2008, 03:44
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 28 Aug 2008, 04:27
Quote:
But still, are you sure the crash is because of the gluPerspective call?

If i comment out that function call she doesn't crash.

Also, i did find that part about preceding the var with double.
The manual is the first place i look before asking questions.
I had to include win32ax to make it visible to the assembler.
Is there any reason why my second attempt crashes?
Either way, im not seeing anything in the viewport.
My code is almost 400 lines so i would hate to post it, but if you would like me too i can.
Post 28 Aug 2008, 04:27
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 28 Aug 2008, 05:16
Post it as a zipped attachment, even the HTML code of this thread will be bigger than the ZIP.

Do you know what kind of exception are you getting? Perhaps your problem is that you don't have GLUT installed on your system (the library macro includes the import data only if some of the imported functions is used and import macro includes the used functions only).
Post 28 Aug 2008, 05:16
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 28 Aug 2008, 05:51
Ok, by including win32ax.inc and invoking the function like:
Code:
invoke  gluPerspective,double[g_fovy],double[g_aspect],double[g_znear],double[g_zfar]     

I got it working!

This is the code that was causing the crash, why? i do not know?
Code:
push dword [g_zfar+4]
push dword [g_zfar]
push dword [g_znear+4]
push dword [g_znear]
push dword [g_aspect+4]
push dword [g_aspect]
push dword [g_fovy+4]
push dword [g_fovy]
call gluPerspective
    


And im having problems with calculating the aspect ratio.
Code:
g_aspect dq ?
g_width dd 1024
g_height dd 768

; my attempt (g_aspect = g_width / g_height)
fild    [g_width]
fild    [g_height]
fdiv    st1,st0
fstp    [g_aspect]
    

Thanks for the help so far, you have been great!!!
Post 28 Aug 2008, 05:51
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 28 Aug 2008, 08:56
Ok, after some more reading the manual and some more tinkering i think i nailed it down!
Code:
g_width dd ?
g_height dd ?
g_aspect dq ?

.wmsize
   mov     eax,[lparam]
   mov     ebx,eax
   and     eax,0xFFFF
   shr     ebx,16
   mov     [g_width],eax
   mov     [g_height],ebx
   fld     [g_width]
   fld     [g_height]
   fdivp   st1,st0
   fstp    [g_aspect]
    

This seems to be working perfectly!
Now i can use the values to setup a perspective projection matrix.
Ahhh...How nice it is to get results.
Post 28 Aug 2008, 08:56
View user's profile Send private message Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 02 Sep 2008, 16:09
http://board.flatassembler.net/topic.php?t=8381
Some OGL code that may be useful.
Post 02 Sep 2008, 16:09
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 03 Sep 2008, 04:05
Yes, i had stumbled upon that article during my adventure's here.
Right now i am a little further along than that.
For practice i am porting much of my opengl code to fasm.
I strive to get my game engine up and running with it.
Post 03 Sep 2008, 04:05
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 23 Sep 2008, 02:32
Ok, i found why this crashes...
Code:
push dword [g_zfar+4]
push dword [g_zfar]
push dword [g_znear+4]
push dword [g_znear]
push dword [g_aspect+4]
push dword [g_aspect]
push dword [g_fovy+4]
push dword [g_fovy]
call gluPerspective
    

I was supposed to enclose the function in brackets like...
Code:
call [gluPerspective]
    

What confuses me is that imported function calls should be within brackets and .code section functions (using labels) should not be within brackets.
Post 23 Sep 2008, 02:32
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.