News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

on Strange Prototypes...

Started by savage, May 28, 2006, 11:56:06 PM

Previous topic - Next topic

savage

Um ok so I couldn't get the function "gluPerspective" to work (from glu32.lib) because according to what I can see from opengl tutorials, it should take FOUR double variables, in other words:

  gluPerspective PROTO :REAL8, :REAL8, :REAL8, :REAL8


And I'm getting this error:
Quote
: error A2114: INVOKE argument type mismatch : argument : 4
: error A2114: INVOKE argument type mismatch : argument : 3
: error A2114: INVOKE argument type mismatch : argument : 2
: error A2114: INVOKE argument type mismatch : argument : 1

So I looked into the file, glu32.inc, and here is what I see:

gluPerspective PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD


Instead of taking 4 owords, it's taking 8 dwords!  :dazzled:  In the end, it's the same stack offset, but still, why is it defined like this?


!! Also, strangely, this tutorial (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=01) actually sends GLfloat instead of GLdouble:

gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);



Tedd

A REAL8 takes up the same space as two DWORDs, the prototype just defines the function's arguments in terms of size required, it doesn't matter what they actually are (I think they're listed with all dwords because they were auto-generated from the .lib files).

This still works for checking that you've given the function the correct number of arguments, but you have to push two DWORDs for each REAL8 - in other words, you have to push the 2 DWORDs that make each REAL8 for each one you want to push.

These two are equivalent:
C: gluPerspective(45,1,1,25000)
MASM: invoke gluPerspective, 0,40468000, 0,3FF00000, 0,3FF00000 0,40D86A00


The problem is getting the upper and lower parts of a real8 ::) (or getting masm to do it for you :wink)
No snowflake in an avalanche feels responsible.

MichaelW

It looks to me like the prototype is wrong.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc

    _gluPerspective PROTO :REAL8,:REAL8,:REAL8,:REAL8
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      r8 REAL8 0.0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke _gluPerspective,r8,r8,r8,r8

    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
_gluPerspective proc fovy:REAL8,aspect:REAL8,zNear:REAL8,zFar:REAL8
    fld fovy
    fld aspect
    fld zNear
    fld zFar
    finit
    ret
_gluPerspective endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

void gluPerspective(
  GLdouble fovy,
  GLdouble aspect,
  GLdouble zNear,
  GLdouble zFar
);


00401000                    start:
00401000 FF3504304000           push    dword ptr [403004h]
00401006 FF3500304000           push    dword ptr [403000h]
0040100C FF3504304000           push    dword ptr [403004h]
00401012 FF3500304000           push    dword ptr [403000h]
00401018 FF3504304000           push    dword ptr [403004h]
0040101E FF3500304000           push    dword ptr [403000h]
00401024 FF3504304000           push    dword ptr [403004h]
0040102A FF3500304000           push    dword ptr [403000h]
00401030 E820000000             call    fn_00401055
00401035 6808304000             push    403008h
0040103A E82D000000             call    fn_0040106C
0040103F E86C000000             call    fn_004010B0
00401044 6821304000             push    403021h
00401049 E81E000000             call    fn_0040106C
0040104E 6A00                   push    0
00401050 E8C1000000             call    fn_00401116
00401055                    fn_00401055:
00401055 55                     push    ebp
00401056 8BEC                   mov     ebp,esp
00401058 DD4508                 fld     qword ptr [ebp+8]
0040105B DD4510                 fld     qword ptr [ebp+10h]
0040105E DD4518                 fld     qword ptr [ebp+18h]
00401061 DD4520                 fld     qword ptr [ebp+20h]
00401064 9B                     wait
00401065 DBE3                   finit
00401067 C9                     leave
00401068 C22000                 ret     20h
0040106B CC                     int     3

eschew obfuscation