The MASM Forum Archive 2004 to 2012

Project Support Forums => OpenGL Forum => Topic started by: Maeser on February 23, 2006, 06:47:42 AM

Title: OpenGL Examples will not render. Just show up as black screens.
Post by: Maeser on February 23, 2006, 06:47:42 AM
Hey guys.

I really hate to be this noobish. But I really want to get into the OpenGL Game, and I've been using MASM for a while now and I'd like to give it a shot. My problem is that when I run the program, I get a black screen. When I was programming in C++ this was due to glTranslatef not being able to go past 1.0f or -1.0f in the Z axis. But despite messing around with glTranslatef, I still get a black screen. Now I'm using Chrome, which handles all my includes and libraries for me, but I dont think it would affect the code. The drawing code I'm using is the Simple_Object.asm from the example archive.

Draw proc
invoke glClear, GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT
invoke glPushMatrix
invoke glTranslatef, CFLT(0.0), CFLT(0.0), CFLT(4.0)
invoke glRotatef, RotX, CFLT(0.0), CFLT(1.0), CFLT(0.0)
invoke glRotatef, RotY, CFLT(1.0), CFLT(0.0), CFLT(0.0)
invoke glRotatef, RotZ, CFLT(0.0), CFLT(0.0), CFLT(1.0)
invoke glBegin, GL_QUADS
invoke glColor3f, CFLT(0.0), CFLT(0.2), CFLT(0.3)
invoke glVertex3f, CFLT(1.0), CFLT(1.0), CFLT(-1.0)
invoke glVertex3f,CFLT(-1.0), CFLT(1.0), CFLT(-1.0)
invoke glVertex3f,CFLT(-1.0), CFLT(1.0), CFLT(1.0)
invoke glVertex3f, CFLT(1.0), CFLT(1.0), CFLT(1.0)

invoke glVertex3f, CFLT(1.0),CFLT(-1.0), CFLT(1.0)
invoke glVertex3f,CFLT(-1.0),CFLT(-1.0), CFLT(1.0)
invoke glVertex3f,CFLT(-1.0),CFLT(-1.0),CFLT(-1.0)
invoke glVertex3f, CFLT(1.0),CFLT(-1.0),CFLT(-1.0)

invoke glColor3f, CFLT(0.2), CFLT(0.4), CFLT(0.5)
invoke glVertex3f, CFLT(1.0), CFLT(1.0), CFLT(1.0)
invoke glVertex3f,CFLT(-1.0), CFLT(1.0), CFLT(1.0)
invoke glVertex3f,CFLT(-1.0),CFLT(-1.0), CFLT(1.0)
invoke glVertex3f, CFLT(1.0),CFLT(-1.0), CFLT(1.0)

invoke glVertex3f, CFLT(1.0),CFLT(-1.0),CFLT(-1.0)
invoke glVertex3f,CFLT(-1.0),CFLT(-1.0),CFLT(-1.0)
invoke glVertex3f,CFLT(-1.0), CFLT(1.0),CFLT(-1.0)
invoke glVertex3f, CFLT(1.0), CFLT(1.0),CFLT(-1.0)

invoke glColor3f, CFLT(0.4), CFLT(0.6), CFLT(0.7)
invoke glVertex3f, CFLT(-1.0), CFLT(1.0), CFLT(1.0)
invoke glVertex3f, CFLT(-1.0), CFLT(1.0),CFLT(-1.0)
invoke glVertex3f, CFLT(-1.0),CFLT(-1.0),CFLT(-1.0)
invoke glVertex3f, CFLT(-1.0),CFLT(-1.0), CFLT(1.0)

invoke glVertex3f, CFLT(1.0), CFLT(1.0),CFLT(-1.0)
invoke glVertex3f, CFLT(1.0),CFLT(1.0), CFLT(1.0)
invoke glVertex3f, CFLT(1.0),CFLT(-1.0), CFLT(1.0)
invoke glVertex3f, CFLT(1.0),CFLT(-1.0),CFLT(-1.0)
invoke glEnd
invoke glPopMatrix
ret
Draw endp


Any help you can provide would be greatly appreciated
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: zooba on February 23, 2006, 07:24:41 AM
If you can't translate beyond 1 unit, it's probably because you haven't called glDepthRange or gluLookAt or you've called glDepthRange or gluLookAt with bad numbers.

AFAICT, what you've got here is fine. :U
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: hitchhikr on February 23, 2006, 02:53:48 PM

invoke glTranslatef, CFLT(0.0), CFLT(0.0), CFLT(4.0)


Contrary to directx you have to use negative z values in ogl due to the way the matrices are built, use CFLT(-4.0) instead.
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: stachu on March 13, 2006, 10:20:52 PM
Hi!

I'm a noobish too and I've got the same problem. I think, everything is ok in my code, I can change the background color, but I can't draw anything on it. Is it necessary to use gluLookAt function? At this moment I only would like to draw some simple prymitives without any complicated effects and methods.

Thanks for any help and advices
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: hitchhikr on March 15, 2006, 12:33:04 PM
Show me your code.
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: stachu on March 15, 2006, 08:01:52 PM
...
...
...
k1 DWORD 1.0, 1.0, 1.0, 1.0
pkt1 DWORD 0.0,0.0,5.0
pkt2 DWORD 10.0,10.0,-10.0
pkt3 DWORD 10.0,0.0,-10.0

Value1Dbl      dq   1.0
Value3Dbl      dq   3.0
Value7Dbl      dq   7.0
Value70Dbl      dq   70.0

...
...
...

SetupRC proc

    invoke glClearColor, DWORD PTR BackColor, DWORD PTR BackColor+4, DWORD PTR BackColor+8, DWORD PTR BackColor+12
   
    invoke   glEnable,GL_DEPTH_TEST
    invoke   glEnable,GL_LIGHTING
    invoke   glEnable,GL_CULL_FACE      ; nie renderujemy powierzchni niewidocznych
    invoke   glShadeModel,GL_SMOOTH
    invoke   glEnable,GL_NORMALIZE
   
    ret
   
SetupRC endp


ChangeSize PROC w:DWORD, h:DWORD

    .if h==0
        mov h,1
    .endif
   
    invoke glViewport, 0, 0, w, h
    invoke glMatrixMode, GL_PROJECTION
    invoke glLoadIdentity
   
    invoke gluPerspective, DWORD PTR Value70Dbl, DWORD PTR Value70Dbl+4, DWORD PTR Value1Dbl, DWORD PTR Value1Dbl+4,
                    DWORD PTR Value3Dbl, DWORD PTR Value3Dbl+4, DWORD PTR Value7Dbl, DWORD PTR Value7Dbl+4
    invoke glMatrixMode,GL_MODELVIEW
    invoke glLoadIdentity
    ret
   
ChangeSize endp


RenderScene proc

    invoke glClear, GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT
    invoke glPushMatrix
    invoke glTranslatef, 0,0,-4

    invoke glBegin, GL_TRIANGLES

        invoke glColor3f, k1, k1+4, k1+8
        invoke glVertex3f, pkt1, pkt1+4, pkt1+8
        invoke glVertex3f, pkt2, pkt2+4, pkt2+8
        invoke glVertex3f, pkt3, pkt3+4, pkt3+8

    invoke glEnd

    invoke glPopMatrix
    invoke SwapBuffers,hDC

    ret
   
RenderScene endp



WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD

local wc:WNDCLASSEX                  ;na stosie tworzymy zmienne lokalne
local msg:MSG
local Wwd:DWORD
local Wht:DWORD
local Wtx:DWORD
local Wty:DWORD

...                               
...
...
...

    mov    hWnd, eax
    invoke ShowWindow, hWnd, CmdShow
    invoke UpdateWindow, hWnd

    call PetlaGlowna     
   
    ret

WinMain endp




PetlaGlowna proc
         LOCAL   msg:MSG
StartLoop:      
         invoke PeekMessage,ADDR msg,0,0,0,PM_NOREMOVE
         or eax,eax
         jz NoMsg
         invoke GetMessage,ADDR msg,NULL,0,0     
         or eax,eax
         jz ExitLoop
         invoke TranslateMessage,ADDR msg
         invoke DispatchMessage,ADDR msg
         jmp StartLoop
NoMsg:      
         invoke RenderScene       
         jmp StartLoop           
ExitLoop:      mov eax,msg.wParam     
         ret

PetlaGlowna endp




Sorry for any polish comments;) If you want more (or even all) code, just tell me.

Thanks
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: hitchhikr on March 15, 2006, 10:45:48 PM
Quote
invoke glTranslatef, 0,0,-4

Because masm doesn't convert arguments, -4 is an integer and glTranslatef awaits a floating point number, use:

Quote
ZPos real4 -4.0

invoke glTranslatef, 0,0,ZPos

You better dowload & use the stuff located here, it'll be much easier for you to use opengl with masm32:

http://www.masmforum.com/simple/index.php?topic=2522.0
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: stachu on March 24, 2006, 11:22:19 AM
Thanks for help, now everything is ok and works as it should  :U
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: modorang on April 03, 2006, 02:29:37 PM
study
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: Duracell on October 21, 2006, 12:10:04 PM
hi

I have got the same problem. I am noob and i can't draw. Please if you can, help me.
This is my macro:


fpc MACRO val:REQ
    LOCAL w,x,y,z,zz,ww

    ;; split type and value, defaulting to REAL4
    z INSTR 1,<&val>,<! >
    IF z EQ 0
        y TEXTEQU <REAL4>
        x TEXTEQU <&val>
    ELSE
        y TEXTEQU @SubStr(<&val>,1,z-1) ;; Type
        x TEXTEQU @SubStr(<&val>,z+1,)  ;; Value
    ENDIF

    ;; replace . with _
    z INSTR 1,x,<!.>
    IF z EQ 0
        w TEXTEQU x
        x CATSTR x,<.0> ;; prevent error message
    ELSE
        w CATSTR @SubStr(%x,1,z-1),<_>,@SubStr(%x,z+1,)
    ENDIF

    ;; replace - with _
    zz INSTR 1,w,<!->
    IF zz EQ 0
        ww TEXTEQU w
    ELSE
        ww CATSTR @SubStr(%w,1,zz-1),<_>,@SubStr(%w,zz+1,)
    ENDIF

    ;; figure out global name for constant
    z SIZESTR y ;; use last char for size distiction
    ww CATSTR <__>,ww,<r>,@SubStr(%y,z,1)

    IF (OPATTR(ww)) EQ 0 ;; not defined
        CONST SEGMENT
            ww y x
        CONST ENDS
    ENDIF
    EXITM ww
ENDM

...

Vertex3f MACRO xx,yy,zz
push fpc(zz)
push fpc(yy)
push fpc(xx)
call glVertex3f
ENDM



and this is drawing code:


Rysunek:
    invoke glClear,GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT
    invoke glDisable,GL_LIGHTING
    invoke glLoadIdentity

;pozx=x+8*sin(kat*pi180);

fld   kat
fmul  pi180
fsin
fmul  o
fadd  x
fstp  pozx

;pozz=z+8*cos(kat*pi180)

fld   kat
fmul  pi180
fcos
fmul  o
fadd  z
fstp  pozz

push dword ptr [oz+4]
push dword ptr [oz]
push dword ptr [oy+4]
push dword ptr [oy]
push dword ptr [ox+4]
push dword ptr [ox]
push dword ptr [pozz+4]
push dword ptr [pozz]
push dword ptr [pozy+4]
push dword ptr [pozy]
push dword ptr [pozx+4]
push dword ptr [pozx]
push dword ptr [z+4]
push dword ptr [z]
push dword ptr [y+4]
push dword ptr [y]
push dword ptr [x+4]
push dword ptr [x]

call gluLookAt

invoke glTranslatef,fpc(-1.5),fpc(0.0),fpc(-6.0)

invoke glBegin,GL_TRIANGLES

Vertex3f 0.0,1.0,0.0
Vertex3f -1.0,-1.0,0.0
Vertex3f 1.0,-1.0,0.0

invoke glEnd

ret


P.S. I have only fullscreen and i can change color.
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: hitchhikr on October 27, 2006, 09:22:59 PM
Paste the values of the variables you're passing to glulookat.
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: Duracell on October 28, 2006, 05:44:00 AM

o       QWORD   8

x QWORD 15.0
y QWORD 0.8
z QWORD 15.0
pozx QWORD 0.0
pozy QWORD 0.0
pozz QWORD 0.0
ox QWORD 0.0
oy QWORD 1.0
oz QWORD 0.0


When I give
;gluLookAt
That doesn't chang. I have screen only but don't see tringles
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: hitchhikr on October 28, 2006, 12:32:49 PM
As it seems several people have troubles to use glulookat i'll do an example about this one.
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: Duracell on October 28, 2006, 12:56:07 PM
are u thinking that gllulookat in my program is wrong?
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: hitchhikr on October 28, 2006, 01:47:59 PM
Yes.
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: Duracell on October 28, 2006, 02:29:37 PM
if i delete glulookat, all are ok?
Title: Re: OpenGL Examples will not render. Just show up as black screens.
Post by: hitchhikr on October 29, 2006, 03:47:35 PM
I added an example about gluLookAt in the archives (download both files).