News:

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

I have only process

Started by Duracell, February 13, 2007, 07:01:50 PM

Previous topic - Next topic

Duracell

I'm trying, make a app.

I think, that everything is ok. But screen flashes and returns to Win. Process/Thread is working and use 90-99 % CPU.

what is wrong?

If u want a code, tell me which part i must send.

Duracell

Draakie

Please attach all of it - could be initialization / drawloop / anything really ...... ::)
Does this code make me look bloated ? (wink)

Duracell

#2

WinMain proc hInstance:DWORD, hPrevInst:DWORD, CmdLine:DWORD, CmdShow:DWORD
LOCAL msg:MSG
invoke CreateGLWindow, offset tytul,1024,768,32

mov done,FALSE
PetlaKomunikatow:
invoke PeekMessage,addr msg,0,0,0,PM_REMOVE
test eax,eax
jz ZadnychKomunikatow
invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
cmp done,TRUE
jne PetlaKomunikatow
jmp ZakonczProgram
ZadnychKomunikatow:
invoke DrawGLScene
invoke SwapBuffers,hDC
cmp done,TRUE
jnz PetlaKomunikatow
ZakonczProgram:
invoke KillGLWindow
invoke ExitProcess,0

 
    mov eax, MSG.wParam

xor eax,eax
ret

WinMain endp



ReSizeGLScene proc widthx:DWORD, heighty:DWORD
   
    invoke glViewport, 0, 0, widthx, heighty
    invoke glMatrixMode, GL_PROJECTION
    invoke glLoadIdentity 
       

CFTD 45.0
    CFTD 1.3333333333
    CFTD 0.1
    CFTD 100.0
    call gluPerspective
   
    invoke glMatrixMode, GL_MODELVIEW
    invoke glLoadIdentity
    ret

ReSizeGLScene endp

InitGL proc

invoke glShadeModel, GL_SMOOTH              ;enable smooth shading

CFTD 1.0
    call glClearDepth              ;depth buffer setup
   
    invoke glClearColor,CFLT(0.4),CFLT(0.2),CFLT(1.0),CFLT(0.0)
invoke glEnable,GL_DEPTH_TEST
invoke glDepthFunc,GL_LEQUAL

invoke glEnable, GL_NORMALIZE
invoke glEnable, GL_CULL_FACE

invoke glHint,GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST ;tu chyba jakosc srodka
    mov eax, 1
    ret

InitGL endp


WndProc proc hWind:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD

mov eax,uMsg
cmp eax,WM_KEYDOWN
jz Keydown
cmp eax,WM_KEYUP
jz Keyup
cmp eax,WM_DESTROY
jz Destroy
invoke DefWindowProc,hWnd,uMsg,wParam,lParam

ret

Destroy:
mov done,TRUE
ret

Keydown:
mov eax,wParam
mov byte ptr keys[eax],TRUE
ret

Keyup:
mov eax,wParam
mov byte ptr keys[eax],FALSE
xor eax,eax
ret

WndProc endp

DrawGLScene proc
  invoke glLoadIdentity
  invoke glClear,GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT


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

fld x
fadd odleglosc

fld kat
fmul pi180
fsin

fmul
fstp pozx


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

fld z
fadd odleglosc

fld kat
fmul pi180
fcos

fmul
fstp pozz


  CFTD oz
  CFTD oy
  CFTD ox

  CFTD pozz
  CFTD pozy
  CFTD pozx

  CFTD z
  CFTD y
  CFTD x

  call gluLookAt

;----------------------------------------------------------------------------------------------
RysujPlansze:
invoke glBegin,GL_TRIANGLES

Color3f 1.0,0.0,0.0
Vertex3f 1.0,3.0,0.0
Vertex3f 1.5,-5.0,0.0
Vertex3f 2.0,3.0,0.0

invoke glEnd

ret

DrawGLScene endp

CreateGLWindow proc WinTitle:DWORD, WinWidth:DWORD, WinHeight:DWORD, WinBits:UINT
    LOCAL dwExStyle:DWORD, dwStyle:DWORD, PixelFormat:UINT
    LOCAL rc:RECT, dmScreenSettings:DEVMODE, wc:WNDCLASSEX

mov wc.cbSize,sizeof WNDCLASSEX
mov wc.style,CS_HREDRAW or CS_VREDRAW or CS_OWNDC
    mov wc.lpfnWndProc, offset WndProc
    mov wc.cbClsExtra,0
    mov wc.cbWndExtra,0
    push hInst
    pop wc.hInstance
    mov wc.hbrBackground,0
    mov wc.lpszMenuName,0
    mov wc.lpszClassName,offset OpenGL_Class
    invoke LoadIcon,0,IDI_WINLOGO
    mov wc.hIcon,eax
    mov wc.hIconSm,0
    invoke LoadCursor,0,IDC_ARROW
    mov wc.hCursor,eax
       
    invoke RegisterClassEx,addr wc
   
    mov dmScreenSettings.dmSize,sizeof dmScreenSettings
    push WinWidth
    pop dmScreenSettings.dmPelsWidth
    push WinHeight
    pop dmScreenSettings.dmPelsHeight
    push WinBits
    pop dmScreenSettings.dmBitsPerPel
    mov dmScreenSettings.dmFields,DM_BITSPERPEL or DM_PELSWIDTH or DM_PELSHEIGHT

invoke ChangeDisplaySettings,addr dmScreenSettings,CDS_FULLSCREEN

invoke AdjustWindowRectEx,addr rc,WS_POPUP or WS_CLIPSIBLINGS or WS_CLIPCHILDREN,0,WS_EX_APPWINDOW ;kalkulacja okna wzgledem ekranu

invoke CreateWindowEx,WS_EX_APPWINDOW, offset OpenGL_Class,\
  offset tytul,\
  WS_POPUP or WS_CLIPSIBLINGS or WS_CLIPCHILDREN,\
  0,0,WinWidth,WinHeight,0,0,hInst,0

mov hWnd,eax
invoke GetDC,eax
mov ebx,eax
mov hDC,eax


invoke ChoosePixelFormat,eax,addr pfd
mov PixelFormat,eax

invoke SetPixelFormat,ebx,eax,addr pfd
invoke wglCreateContext,ebx
mov hRC,eax
invoke wglMakeCurrent,ebx,eax
invoke ShowWindow,hWnd,SW_SHOW
    invoke SetForegroundWindow,hWnd
    invoke SetFocus,hWnd

    invoke ReSizeGLScene,WinWidth,WinHeight
    invoke InitGL

ret

CreateGLWindow endp

Draakie

hmmm..... looks like the bug could be a mix-up of window handles passed between procedures,
but I ca'nt be sure seeing as I don't have u're full app with data definitions etc. ZIP and attach
to the post if you don't mind. Failing that - consider making u're opengl framework more generic
and rigid - use hitchiker's base example and modify it to u're needs.

[EDIT]
Kewlies - will have a look.
Does this code make me look bloated ? (wink)

Duracell

That is code. I try to make it baseed on small-engine.

[attachment deleted by admin]

Draakie

WndProc proc hWind:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD

   mov   eax,uMsg
   cmp   eax,WM_KEYDOWN
   jz   Keydown   
   cmp   eax,WM_KEYUP
   jz   Keyup
   cmp   eax,WM_DESTROY
   jz   Destroy
   invoke   DefWindowProc,hWnd,uMsg,wParam,lParam


the callback function wants :

invoke   DefWindowProc,hWind,uMsg,wParam,lParam

this allows the program to compile and run correctly.... although I'am not to sure
what's going on in u're drawloop - looks like it does'nt work correctly yet.

ps   : allways use FINIT before a co-processor instruction series
pps :  the program should run at 94-99% CPU usage - this is normal for opengl applications as per
you're message pump....

Good Luck
       
Does this code make me look bloated ? (wink)

Duracell

Working. Fnx. Now i can set up glulookat.

I thank you for assistance.