Hi Guys:

My name is Michael. I am a computer science student at
Purdue University. Last semester I wrote, in C, an OpenGL
program that have two 3D balls in a room in motion.

I now want to do this with MASM32. My problem is how do I
create a sphere. I can not get gluSphere to work.

DrawGLScene proc
invoke glClear, GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
invoke glLoadIdentity ;reset modelview matrix
_glMatrixMode GL_PROJECTION
_glLoadIdentity
_glFrustum -100.0f, 100.0f, -100.0f, 100.0f, 0.0f, 320.0f
_glMatrixMode GL_MODELVIEW

invoke gluNewQuadric
mov quadricObj, eax

.if(eax == NULL)
invoke MessageBox, 0, quadricObj, addr szError, MB_OK
.else
invoke gluQuadricTexture, quadricObj, GL_TRUE
invoke gluQuadricDrawStyle, quadricObj, GLU_FILL
_glColor3f 1.0f, 0.5f, 0.0f
invoke gluSphere, quadricObj, 5, 5, 50, 50
.endif

mov eax, 1
ret
DrawGLScene endp

One strange problem: The OpenGL shows the gluSphere
with 4 parameters. But, the program, when assembled, complains
that there are too few parameters.
I played with the gluSphere paramters and the _glFrustum.

Question: When the gluNewQuadric create its pointer to the
quadricObj, is it in the eax register? How do I reference it?
I tried addr quadricObj, , addr .
Do I use an "assume", if yes, how?


Could someone help me here? I am using MASM32 with:

.586
.MODEL FLAT,STDCALL
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\mix.inc

include \masm32\include\opengl\gl.def
include \masm32\include\opengl\glu.def

include \masm32\include\opengl32.inc
include \masm32\include\glu32.inc
include \masm32\include\glaux.inc

include \masm32\include\opengl\kernel32.inc
include \masm32\include\opengl\user32.inc
include \masm32\include\opengl\gdi32.inc
include \masm32\include\WinExtra\winextra.def
; include \masm32\m32lib\imalloc.asm


includelib \masm32\lib\masm32.lib
includelib \masm32\lib\opengl32.lib
includelib \masm32\lib\glu32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\mix.lib

;------------------------------------------
thank you guys in advance.
Posted on 2001-08-13 14:18:23 by Michael
Afternoon, Michael.

I don't know much about using OpenGL, however I'll see if I can help.;)

First: 'gluNewQuadric' returns (in eax) a pointer to a 'GLUquadricObj'. Using 'mov quadricObj, eax ' is correct.
Question: Are you declaring 'quadricObj' as a PTR/DWORD?

Second: There seems to be a problem with the 'gluSphere' proc. It's declared in the 'glu32.inc ' file as taking five arguments, however in the Platform SDK it only takes four.

void gluSphere(

GLUquadricObj *qobj,
GLdouble radius,
GLint slices,
GLint stacks
);

This would mean that the declaration in the 'glu32.inc ' file should be:
gluSphere PROTO :DWORD,:QWORD,:DWORD,:DWORD

... and to use it ...
invoke gluSphere, quadricObj, 5, 50, 50


To repeat:
The older versions of OpenGL may have used five arguments for the 'gluSphere' proc (don't know - don't care), however the latest version only uses four. This would depend on the version of the 'glu32.lib ' file you're using. If you're using the latest 'glu32.lib ' file from M$, then the declaration in 'glu32.inc ' will have to be changed.

Hope some of this helps.

Cheers,
Scronty
Posted on 2001-08-13 17:23:35 by Scronty
Fodders method should work grand if you wish to use memory variables to pass values.

If however you wish to be ables to type numbers straight into your code as you can with the _glVertex MACROs you need to make one for gluSphere. Luckly for you I needed the same thing so I can give it to you:

_gluSphere MACRO a,b,c,d
push d
push c
gl_dpush b
push a
mov eax, eax
mov ecx, ecx
call gluSphere
ENDM

Example of use:
_gluSphere pQuad, 0.5f, 32, 32
Posted on 2001-08-13 18:43:01 by Eóin
Thank you Scronty:

I define the quadricObj as a dword. How do I define it as
a pointer?

Also, I took the glu32.lib from my viual c++ 6.0 lib. I then
used the l2inca command to get the glu32.inc.
Whe I check the glu32.inc it had 5 parameters, not 4 (by red book), for the gluSphere function. If I try to use four parameters but the program will not link. The assembler says there are too few parameters. I need to know why. Can you help?

Michael
Posted on 2001-08-14 11:08:56 by Michael
Zadkiel thank you so much for the macro.

Could you tell me more about fodder's method?

Also, why did you move a register to itsel? Are you zeroing
out the register? I have seen: xor eax, eax but not mov eax, eax

Michael
Posted on 2001-08-14 11:26:37 by Michael
Actually I ment to say scronty, I had been just reading a reply by fodder and so I type in the wrong name. Sorry.

Regarding the mov eax,eax I don't know why it has to be done acording to Serge Coban the author it has to done or the code won't work. Strange I know.
Posted on 2001-08-14 12:33:53 by Eóin
Correction: The glu32.inc is showing five parameters (DWORD)
not four. I used the l2inca from masm32 to build the
include file. But the Opengl's red book shows four parameters
not five. This is what I am trying to find out, why?

I am now downloading the glsetup 1.2.1 from www.opengl.org maybe the library file I borrowed from microsoft vc++ 6.0 was a old one.

I am also wondering is there something wrong with the
l2inca from masm32. I do not think so, because the program
will not link when I reduce the parameters from five to four
in the glu32.inc (made by l2inca).

Also, why do the l2inca only make parameters with DWORD?
Some of the parameters are real (GLfloat), do I change these
parameters in the include files, or do I make use of Scronty's method to make a macro.

Thank you all for helping me (and probably others).

Michael
Posted on 2001-08-14 13:22:51 by Michael
Afternoon, Michael.

It seems to me that the 'l2inca' utility checks the number of bytes associated with a given function, and then it generates parameters based on 'number-of-bytes / 4'.
i.e. (from Hutchs' utility 'L2extia':
externdef _imp__gluSphere@20:PTR pr5

gluSphere equ <_imp__gluSphere@20>

This is equivalent to:
gluSphere PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD

The second parameter should be a QWORD (i.e. 2 x DWORD).

The Macro that Zadkiel posted works because it's pushing a 'double' as the second parameter. This means that when using the '5 x DWORD' 'PROTO', the 'double' will be spread across the second and third DWORDs

There's nothing wrong with the '*.lib's you're using. The 'PROTO' just needs a bit of adjustment.

'invoke' has parameter-checking functionality, which means that it will check to see if you've supplied the same number of parameters as in the 'PROTO' declaration.

In any case, if you wish to use an 'invoke', the 'PROTO' for 'gluSphere' will have to be changed.

Hope this helps.

Cheers,
Scronty
Posted on 2001-08-14 17:33:21 by Scronty
Hi Guys, what's missing?



This is inside glu32.inc
-------------------------------------------
gluSphere PROTO :DWORD,:QWORD,:DWORD,:DWORD
-------------------------------------------
*

This is in .data
-----------------------------
quadricObj DWORD NULL
-----------------------------

*

this is where gluSphere is invoked
----------------------------------------------------------------
DrawGLScene proc
invoke glLoadIdentity
_glMatrixMode GL_PROJECTION
_glLoadIdentity
_glFrustum -100.0f, 100.0f, -100.0f, 100.0f, 320.0f, 640.0f
_glMatrixMode GL_MODELVIEW
_glClear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
_glColor3f 1.0f, 1.0f, 0.0f
invoke gluNewQuadric
mov quadricObj, eax
invoke gluSphere, quadricObj, 5, 50, 50
mov eax, 1
ret
DrawGLScene endp
--------------------------------------------------------------------
*

this is the error message
-------------------------------------------------------------------
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.

Assembling: c:\masm32\projects\ballroom\ballroom.asm
\masm32\include\glu32.inc(46) : error A2111: conflicting parameter definition
c:\masm32\projects\ballroom\ballroom.asm(485) : error A2137: too few arguments t
o INVOKE
_
Assembly Error
Press any key to continue . . .
--------------------------------------------------------------------
--------------------------------------------------------------------

This is the macro
--------------------------------------------------------------------
_gluSphere MACRO a,b,c,d
push d
push c
gl_dpush b
push a
mov eax, eax
mov ecx, ecx
call gluSphere
ENDM
----------------------------------------------------------------------

*

This is the macro version of gluSphere
----------------------------------------------------------------------
DrawGLScene proc
invoke glLoadIdentity
_glMatrixMode GL_PROJECTION
_glLoadIdentity
_glFrustum -100.0f, 100.0f, -100.0f, 100.0f, 320.0f, 640.0f
_glMatrixMode GL_MODELVIEW
_glClear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
_glColor3f 1.0f, 1.0f, 0.0f
invoke gluNewQuadric
mov quadricObj, eax
_gluSphere quadricObj, 5, 50, 50
mov eax, 1
ret
DrawGLScene endp
-----------------------------------------------------------------------

*

Here is the error message
--------------------------------------------------------------------
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.

Assembling: c:\masm32\projects\ballroom\ballroom.asm
\masm32\include\glu32.inc(46) : error A2111: conflicting parameter definition
_
Assembly Error
Press any key to continue . . .
-----------------------------------------------------------------------
Posted on 2001-08-14 18:40:25 by Michael
With the macro _gluSphere I can not even use a GLdouble
or GLfloat for the radius.

With the invoke version of gluSphere, I realized I should had
use variables. But, I still get the same error message even
with variables.

How do we make a sphere in assembler language utilizing
OpenGL?

Michael
Posted on 2001-08-14 22:15:49 by Michael
Michael,

If the function prototype for gluSphere is the following,



gluSphere PROTO :DWORD,:QWORD,:DWORD,:DWORD


then,

the calling syntax like

invoke gluSphere, quadricObj, 5, 50, 50

will not work.

Why?

INVOKE always does a comparision of its parameter type.
You are passing an immediate value of 5. INVOKE in no way knows what its size is. So you get all error message.

How to solve the problem?

Method 1:

Declare a variable in data section as DQ (8-byte) and use it.


.code
.386
.model flat, stdcall

gluSphere PROTO :DWORD,:QWORD,:DWORD,:DWORD

.data
d1 DQ 5.0

.code

start:

Invoke gluSphere, eax, d1, 50, 50

end start


Method 2:

If you don't want to use a variable then you can use stack directly as follows




Push 50 ; stacks
Push 50 ; slices
Push 5 ; radius in 4-byte integer
Fld DWORD PTR [esp] ; Load 4-byte value to FPU
; in FPU you have 10-byte value
; We want to store 8-bytes value to stack for glusphere.
; At this point we have to remove 5 puhsed in the previous
; one. So we have 4-bytes in stack. Add 4 more bytes in
; stack.
Sub esp, 4 ; 4 more bytes
Fstp QWORD PTR [esp] ; Store as 8-byte value
Push eax ; qObj
Call gluSphere ; OpenGL



Hope this helps.

NOTE:
Before using MASM's built-in macro, first please try to understand what it does, then use it.
Posted on 2001-08-15 17:51:39 by sjhenry
Captain, we have whales!

Thank you guys so much for helping me get off the ground.
I now know how to make a sphere in MASM using OpenGL.

I will continue to update you all on the progress.
I will write a small program to share with everyone else
that may need this information. Thank you so much!!!!!!!!!!!


Below is the fruit all of you help make.


inside glu.def
-------------------------------------------------------------
gluQuadricCallback PROTO :DWORD,:DWORD,:DWORD
gluQuadricDrawStyle PROTO :DWORD,:DWORD
gluQuadricNormals PROTO :DWORD,:DWORD
gluQuadricOrientation PROTO :DWORD,:DWORD
gluQuadricTexture PROTO :DWORD,:DWORD
gluSphere PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
-------------------------------------------------------------



------- marco that works ------------------------------------
_gluSphere MACRO a,b,c,d
push d
push c
push b
fld DWORD PTR
sub esp, 4
fstp QWORD PTR
push a
call gluSphere
ENDM
-------------------------------------------------------------



------------- data ---------------------------------------
quadricObj DWORD NULL
radius GLfloat 2.0f
slices DWORD 20
stacks DWORD 20
-----------------------------------------------------------


------------ code -------------------------------------------
invoke gluNewQuadric
mov quadricObj, eax
invoke gluQuadricDrawStyle, quadricObj, GLU_LINE
invoke gluQuadricNormals, quadricObj, GLU_SMOOTH
invoke gluQuadricOrientation, quadricObj, GLU_OUTSIDE
invoke gluQuadricOrientation, quadricObj, GL_TRUE
_glColor3f 1.0f, 1.0f, 0.0f
_gluSphere quadricObj, radius, slices, stacks
------------------------------------------------------------
Posted on 2001-08-17 02:19:30 by Michael
I took an existing opengl program, lesson05, and added
the sphere.

Michael
Posted on 2001-08-20 17:22:31 by Michael
wow this answered a lot of my questions.. thanks guys!
Posted on 2001-09-01 12:15:26 by closed_casket