flat assembler
Message board for the users of flat assembler.
Index
> Windows > Proc problems (Now OpenGL discussion) |
Author |
|
windwakr 23 Jan 2010, 00:31
Ok, nevermind....I just have to add 'double' before the float in the glClearDepth invoke....
But why don't I need it in "invoke glClearColor,0.0,0.0,0.0,0.5"? EDIT: I see why I don't need it there, glClearColor only uses single-precision floats. OK Then, I guess I don't need your help for now. Although, if you see something bad or wrong in my code you can point it out to me. OpenGL is confusing.... --------------------------------------------------------------------- OLDEDIT: It seems the functions in the procs eat the return address........ Please ignore the bad code formatting, too many anonymous labels, bad variable naming, lack of comments, etc. The problem is in the proc CreateGLWindow at the very end, where it call the procs ResizeGLScene and InitGL. Those two procs crash upon executing their ret instruction. Anyone have any ideas? You won't be able to assemble this, missing includes. Plus the code is incomplete. Code: ;NEHE Tutorial #1 port to FASM by windwakr ;Some bits of code borrowed from bitshifter....hope you don't mind.... format PE GUI 4.0 entry start include 'win32ax.inc' include 'opengl32.inc' include 'gdistuff.inc' section '.code' code readable executable start: invoke MessageBox,NULL,fsmsg,fstitle,MB_YESNO or MB_ICONQUESTION cmp eax,IDNO jne @f mov [fullscreen],0 @@: stdcall CreateGLWindow,windowtitle,640,480,16,[fullscreen] cmp eax,1 jne @f invoke ExitProcess,0 @@: msg_loop: invoke GetMessage,msg,NULL,0,0 or eax,eax jz end_loop invoke TranslateMessage,msg invoke DispatchMessage,msg jmp msg_loop end_loop: invoke ExitProcess,[msg.wParam] proc WindowProc uses ebx esi edi, hwnd, wmsg, wparam, lparam cmp [wmsg],WM_DESTROY je .wmdestroy .defwndproc: invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam] jmp .finish .wmdestroy: invoke PostQuitMessage,0 xor eax,eax .finish: ret endp proc CreateGLWindow stdcall windowtitle, width, height, bits, fullscreen locals windowfail db 'Window creation error.',0 regfail db 'Failed to register the window class.',0 modeunsuptitle db 'Mode unsupported.',0 modeunsupport db 'The requested fullscreen mode is not supported by',13,10,'your video card. Use windowed mode instead?',0 closing db 'Program will now clode.',0 endl mov [WindowRect.left],0 mov eax,[width] mov [WindowRect.right],eax mov [WindowRect.top],0 mov eax,[height] mov [WindowRect.bottom],eax invoke GetModuleHandle,0 mov [wc.hInstance],eax invoke LoadIcon,0,IDI_APPLICATION mov [wc.hIcon],eax invoke LoadCursor,NULL,IDC_ARROW mov [wc.hCursor],eax invoke RegisterClass,wc test eax,eax jnz @f invoke MessageBox,NULL,addr regfail,error,MB_OK or MB_ICONEXCLAMATION mov eax,1 ret @@: cmp [fullscreen],1 jne .2 mov edi,dmScreenSettings mov ecx,sizeof.DEVMODE shr 2 xor eax,eax rep stosd mov [dmScreenSettings.dmSize],sizeof.DEVMODE mov eax,[width] mov [dmScreenSettings.dmPelsWidth],eax mov eax,[height] mov [dmScreenSettings.dmPelsHeight],eax mov eax,[bits] mov [dmScreenSettings.dmBitsPerPel],eax mov [dmScreenSettings.dmFields],DM_BITSPERPEL or DM_PELSWIDTH or DM_PELSHEIGHT invoke ChangeDisplaySettings,dmScreenSettings,CDS_FULLSCREEN cmp eax,DISP_CHANGE_SUCCESSFUL je .2 invoke MessageBox,NULL,addr modeunsupport,addr modeunsuptitle,MB_YESNO or MB_ICONEXCLAMATION cmp eax,IDYES je @f invoke MessageBox,NULL,addr closing,error,MB_OK or MB_ICONSTOP mov eax,1 ret @@: mov [fullscreen],0 .2: cmp [fullscreen],1 jne @f mov [dwExStyle],WS_EX_APPWINDOW mov [dwStyle],WS_POPUP invoke ShowCursor,FALSE jmp .1 @@: mov [dwExStyle],WS_EX_APPWINDOW or WS_EX_WINDOWEDGE mov [dwStyle],WS_OVERLAPPEDWINDOW .1: invoke AdjustWindowRectEx,WindowRect,dwStyle,FALSE,dwExStyle mov eax,[dwStyle] or eax,WS_CLIPSIBLINGS or eax,WS_CLIPCHILDREN mov ebx,[WindowRect.right] sub ebx,[WindowRect.left] mov ecx,[WindowRect.bottom] sub ecx,[WindowRect.top] invoke CreateWindowEx,[dwExStyle],_class,[windowtitle],eax,0,0,ebx,ecx,NULL,NULL,[wc.hInstance],NULL test eax,eax jnz @f stdcall KillGLWindow invoke MessageBox,NULL,addr windowfail,error,MB_OK or MB_ICONEXCLAMATION mov eax,1 ret @@: mov [hwnd],eax mov eax,[bits] mov [pfd.cColorBits],al invoke GetDC,[hwnd] mov [hdc],eax invoke ChoosePixelFormat,[hdc],pfd invoke SetPixelFormat,[hdc],eax,pfd invoke wglCreateContext,[hdc] mov [hrc],eax invoke wglMakeCurrent,[hdc],[hrc] invoke ShowWindow,[hwnd],SW_SHOW invoke SetForegroundWindow,[hwnd] invoke SetFocus,[hwnd] stdcall ResizeGLScene,[width],[height] stdcall InitGL mov eax,0 ret endp proc KillGLWindow stdcall ret endp proc ResizeGLScene stdcall width,height cmp [height],0 jnz @f mov [height],1 @@: invoke glViewport,0,0,[width],[height] invoke glMatrixMode,GL_PROJECTION invoke glLoadIdentity fild [width] fst [orthographic_right] fild [height] fst [orthographic_bottom] fdivp fstp [perspective_aspect] invoke gluPerspective,double 45.0,double [perspective_aspect],double 0.1,double 100.0 invoke glMatrixMode,GL_MODELVIEW invoke glLoadIdentity ret endp proc InitGL stdcall invoke glShadeModel,GL_SMOOTH invoke glClearColor,0.0,0.0,0.0,0.5 invoke glClearDepth,double 1.0 invoke glEnable,GL_DEPTH_TEST invoke glDepthFunc,GL_LEQUAL invoke glHint,GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST ret endp proc DrawGLScene stdcall invoke glClear,GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT invoke glLoadIdentity ret endp section '.data' data readable writeable _class db 'OGLTEST',0 _error db 'Startup failed.',0 error db 'ERROR',0 fsmsg db 'Would you like to run in fullscreen mode?',0 fstitle db 'Start fullscreen?',0 windowtitle: db 'OpenGL Test',0 hdc dd 0 hrc dd 0 hwnd dd 0 orthographic_right dd 0 orthographic_bottom dd 0 perspective_aspect dd 0 WindowRect RECT dwExStyle dd 0 dwStyle dd 0 wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,NULL,NULL,_class pfd PIXELFORMATDESCRIPTOR sizeof.PIXELFORMATDESCRIPTOR,1,\ PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER,PFD_TYPE_RGBA,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,\ PFD_MAIN_PLANE,0,0,0,0 rc RECT msg MSG dmScreenSettings DEVMODE fullscreen dd 1 active dd 1 keys rb 256 section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL',\ gdi32,'GDI32.DLL',\ opengl32,'OPENGL32.DLL',\ glu32,'GLU32.DLL' include 'api\kernel32.inc' include 'api\user32.inc' include 'api\gdi32.inc' include 'api\opengl32.inc' include 'api\glu32.inc' Last edited by windwakr on 25 Jan 2010, 20:11; edited 1 time in total |
|||
23 Jan 2010, 00:31 |
|
windwakr 23 Jan 2010, 02:04
Ok, I'm done with this for the night. I have just two problems right now.
1. When I press F1, the window just closes. It doesn't switch between fullscreen/windowed like it should. 2. I can't move, resize, minimize the window, only close it with escape. I've attached it and the necessary includes in case anyone wants to take a look through it.
|
|||||||||||
23 Jan 2010, 02:04 |
|
baldr 23 Jan 2010, 03:45
windwakr,
1. CreateGLWindow appears to return 0 if everything went OK, yet you jump to end_loop after call to switch to fullscreen returns 0. 2. WM_SYSCOMMAND notification is important for default window behavior. Pass to DefWindowProc all unprocessed notifications. |
|||
23 Jan 2010, 03:45 |
|
windwakr 23 Jan 2010, 03:50
Wow, thanks for the help guys. I wouldn't have found those mistakes by myself.
It's working fine now. I'm surprised you guys were even able to find your way through my code, it's such a mess. EDIT: Lol....ugh. I guess it isn't working as fine as I thought it was. After making those fixes it appears to work, but when I go ahead and try to change it to follow the second NEHE tutorial, nothing appears. I change the 'DrawGLScene' code to this: Code: proc DrawGLScene stdcall invoke glClear,GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT invoke glLoadIdentity invoke glTranslatef,-1.5,0.0,-6.0 invoke glBegin,GL_TRIANGLES invoke glColor3f,1.0,1.0,1.0 invoke glVertex3f,0.0,1.0,0.0 invoke glVertex3f,-1.0,-1.0,0.0 invoke glVertex3f,1.0,-1.0,0.0 invoke glEnd invoke glTranslatef,3.0,0.0,0.0 invoke glBegin,GL_QUADS invoke glColor3f,1.0,1.0,1.0 invoke glVertex3f,-1.0,1.0,0.0 invoke glVertex3f,1.0,1.0,0.0 invoke glVertex3f,1.0,-1.0,0.0 invoke glVertex3f,-1.0,-1.0,0.0 invoke glEnd ret endp And it should show a triangle and square....but it doesn't.... EDIT: The glClear is getting executed fine, so I don't know what's going on....probably something to do with ResizeGLScene screwing up some important setting.... EDIT2: Yep, it's the Aspect Ratio. When I put in 1.3333 it appears fine. So the calculation of it is messed up. EDIT3: LOL, just had to change 'perspective_aspect' from dd to dq....... Now that this boring set-up stuff if finally out of the way, I can get on to the fun part. EDIT4: Ahhhh, texture loading....gonna have to come up with some other way of loading than what the tutorials use, as GLAUX isn't really an option here. EDIT5: Found another bug. I was passing the location and not the contents of the variables for the styles in 'AdjustWindowRectEx' causing the client size to be off by a few pixels... |
|||
23 Jan 2010, 03:50 |
|
bitshifter 23 Jan 2010, 10:22
Thats why i made this OpenGL demo...
http://board.flatassembler.net/topic.php?t=9262 So people would not have to screw around making framework! |
|||
23 Jan 2010, 10:22 |
|
Madis731 23 Jan 2010, 23:43
@bitshifter: Only the people that have looked inside the attachments have realized what it is. Maybe "opengl first person camera" should be renamed to something appropriate, like the [CONTRIBUTION] flag I found one day
I plan to use it in the future... |
|||
23 Jan 2010, 23:43 |
|
LocoDelAssembly 23 Jan 2010, 23:58
bitshifter, I've added your example to Windows FAQ. Please check if I'm describing it correctly.
|
|||
23 Jan 2010, 23:58 |
|
windwakr 25 Jan 2010, 00:34
EDIT: Lol, I got it....apparently BMPs use BGR instead of RGB.....
Ok, I managed to butcher most of bitshifter's texture loading into my program, with modifications to load 24-bit BMPs, but there is an odd problem. The colors are all wrong. I don't understand why. I've tried changing the offset for the start where I load the pixel data in the BMP from, but they're still messed up. Here's my files: http://filesmelt.com/dl/nehe6_badloading.zip The BMP has blue words, but loads as orange... Pretty much everything you would need to look at is in the LoadGLTexture procedure. bitshifter wrote: Thats why i made this OpenGL demo... But it's more of a learning experience doing it my way. |
|||
25 Jan 2010, 00:34 |
|
bitshifter 25 Jan 2010, 08:50
The problem is that i use RGB RAW image with 12
byte header and your loading a BGR 24bpp bitmap... You can use LoadImage for 24bpp bitmap very easily... http://nehe.gamedev.net/counter.asp?file=files/misc/nehe_glaux_replacement.zip EDIT: I fix it for u Code: invoke glTexImage2D,GL_TEXTURE_2D,0,3,[width],[height],0,GL_BGR,GL_UNSIGNED_BYTE,esi Have fun! |
|||
25 Jan 2010, 08:50 |
|
windwakr 25 Jan 2010, 17:16
bitshifter wrote: The problem is that i use RGB RAW image with 12 Hmmm, That LoadImage shortens my texture loading code by a lot. It's probably much slower than what I was doing, but it makes my code look a lot neater: Code: proc LoadGLTexture stdcall texture,texid locals hbmp dd 0 bmp BITMAP endl invoke glGenTextures,1,[texid] invoke LoadImage,NULL,[texture],IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION or LR_LOADFROMFILE test eax,eax jz .done mov [hbmp],eax invoke GetObject,eax,sizeof.BITMAP,addr bmp invoke glBindTexture,GL_TEXTURE_2D,[texid] invoke glTexParameteri,GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR invoke glTexParameteri,GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR invoke glTexImage2D,GL_TEXTURE_2D,0,3,[bmp.bmWidth],[bmp.bmHeight],0,GL_BGR,GL_UNSIGNED_BYTE,[bmp.bmBits] invoke DeleteObject,[hbmp] .done: ret endp Quote:
Yeah, that's the first thing I tried when I found out BMPs were stored as BGR. |
|||
25 Jan 2010, 17:16 |
|
bitshifter 25 Jan 2010, 17:28
Once you begin to use 8/24/32 bpp images, you
will understand why i choose custom image format. Sure a Targa (TGA) can do it, but they are bloated. And to use BMP i would need 24 bpp image and 8 bpp mask. Then have to make alpha mask at runtime, very slowly. Sure, having to convert images is time consuming but worth it. I make image in Photoshop, then export as linear RAW no header. Then use my fps2raw converter program to insert 12 byte header. Photoshop can open image as RAW with 12 byte header as specified. Just though i might explain why i made this decision... Have fun |
|||
25 Jan 2010, 17:28 |
|
bitshifter 25 Jan 2010, 19:29
Awww man...
I just found a bug in my code (and yours) glBindTexture takes texture ID value (not pointer) Funny that it worked though So to fix this... Code: invoke glBindTexture,GL_TEXTURE_2D,[id] Also loading code need to be corrected... Code: invoke glGenTextures,1,[texid] mov eax,[texid] ; Get value that pointer points to! invoke glBindTexture,GL_TEXTURE_2D,dword[eax] Sorry about this... I will correct my sources and re-upload them... Of course with some new changes as well... |
|||
25 Jan 2010, 19:29 |
|
windwakr 25 Jan 2010, 19:51
Nice find.
Fixed up my sources: http://filesmelt.com/dl/nehe6.zip EDIT: Ok, 1 more fix for mine....I need to add this: Code: invoke glPixelStorei,GL_UNPACK_ALIGNMENT,4 In the loader too. Something about BMPs padding on new lines. Last edited by windwakr on 25 Jan 2010, 20:25; edited 1 time in total |
|||
25 Jan 2010, 19:51 |
|
Borsuc 25 Jan 2010, 20:24
bitshifter wrote: Once you begin to use 8/24/32 bpp images, you _________________ Previously known as The_Grey_Beast |
|||
25 Jan 2010, 20:24 |
|
windwakr 29 Jan 2010, 04:00
I'm trying to switch to the normal horizontal FOVs that are used, and away from the stupid vertical ones that OpenGL functions define, but did I get this right?
Based off this: http://glprogramming.com/dgs.php?dg=1 Code: proc PerspectiveGL stdcall fovx:QWORD,aspect:QWORD,znear:QWORD,zfar:QWORD locals pi dq 3.141592653589793238 top dq 0 bottom dq 0 left dq 0 right dq 0 endl finit fld [fovx] ;fovx fmul qword[pi] ;fovx*pi push dword 360 fidiv dword[esp] ;fovx*pi/360 add esp,4 fptan ;1 tan(fovx*pi/360) fstp st0 ;tan(fovx*pi/360) fmul qword[znear] ;tan(fovx*pi/360)*znear fst [right] fchs ;-tan(fovx*pi/360)*znear fst [left] fld [aspect] ;aspect -tan(fovx*pi/360)*znear fdivp ;(-tan(fovx*pi/360)*znear)/aspect fstp [bottom] fld [right] ;right fdiv [aspect] ;right/aspect fstp [top] invoke glFrustum,double[left],double[right],double[bottom],double[top],double[znear],double[zfar] ret endp And how would I go about converting a vertical FOV to a horizontal one? I mean, what would be the equivalent fovx to a fovy? I've read that you just multiply fovy by the aspect ratio, but doesn't quite look right, too small......maybe it's a problem with my maths up there? EDIT: Ok, apparently fovx = 2 * actan (aspect * tan (fovy / 2)); Don't understand it, but it seems to work right. Only reason I even need to convert it is because I still want my output to be 1:1 with the NeHe tutorials. But Hmmmm, when I make the window really small, the picture is different. Maybe my function up there isn't working right. |
|||
29 Jan 2010, 04:00 |
|
Alphonso 13 Feb 2010, 06:46
Hi Guys,
just thought I'd mention the NeHe fasm ported lessons 1-18 by keYMax at http://vertexland.narod.ru/data/opengl_fasm.htm |
|||
13 Feb 2010, 06:46 |
|
baldr 13 Feb 2010, 08:26
Alphonso,
F331 th3 p0w3r 0f c0mmunity! |
|||
13 Feb 2010, 08:26 |
|
bitshifter 21 Feb 2010, 07:22
Here is standard way of making projection matrix (fovy)
Code: void InitProjectionMatrix(float fovy, int width, int height, float znear, float zfar) { float aspect = (float)width / (float)height; float fovy2r = fovy * MATH_PI_DIV_360; float cotan = cosf(fovy2r) / sinf(fovy2r); g_projMatrix[0] = cotan / aspect; g_projMatrix[1] = 0.0F; g_projMatrix[2] = 0.0F; g_projMatrix[3] = 0.0F; g_projMatrix[4] = 0.0F; g_projMatrix[5] = cotan; g_projMatrix[6] = 0.0F; g_projMatrix[7] = 0.0F; g_projMatrix[8] = 0.0F; g_projMatrix[9] = 0.0F; g_projMatrix[10] = (zfar + znear) / (znear - zfar); g_projMatrix[11] = -1.0F; g_projMatrix[12] = 0.0F; g_projMatrix[13] = 0.0F; g_projMatrix[14] = (znear * zfar * 2.0F) / (znear - zfar); g_projMatrix[15] = 0.0F; } Have fun _________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
21 Feb 2010, 07:22 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.