· Начало · Отвђтить · Статистика · Поиск · FAQ · Правила · Установки · Язык · Выход · WASM.RU · Noir.Ru ·

 WASM Phorum —› WASM.ASSEMBLER —› 3d почемуто не работает

Посл.отвђт Сообщенiе


Дата: Фев 25, 2004 01:48:40 · Поправил: Безпощадный даос

Прив всем ! Вот "наваял" тут свое first3d.exe :) А оно не пашет них... :(( что я только не делал :( Написано на Fasm'е. Я не знаю как в fasm'е линковать bitmap'ы (текстуры), но вроде сделал правильно (reshack их видит)... LoadImage же возвращает "0" :( Посмотрите плиз, а то не могу дальше продвинуться. Все подробности в исходниках: (аттач) Тут только основной файл:

----------- --------------- --------------- --------------

format PE GUI 4.0
entry start
include '%fasminc%\win32a.inc'
include 'opengl_const.inc'
include 'ext.inc'
start:
xor ebx,ebx
invoke GetModuleHandle,ebx
mov [hInstance],eax
invoke LoadIcon,eax,1
mov [wc.hIcon],eax
mov [wc.hCursor],eax
mov [wc.lpfnWndProc],WindowProc
mov eax,[hInstance]
mov [wc.hInstance],eax
mov [wc.lpszClassName],szClass
invoke RegisterClass,wc
invoke CreateWindowEx,ebx,szClass,szTitle,WS_VISIBLE+WS_POPUP+WS_CLIPSIBLINGS +WS_CLIPCHILDREN,ebx,ebx,[screenWidth],[screenHeight],ebx,ebx,[hInstan ce],ebx
mov [hInstance],eax
msg_loop:
invoke InvalidateRect,[hInstance],ebx,ebx
invoke TranslateMessage,msg
invoke DispatchMessage,msg
invoke GetMessage,msg,ebx,ebx,ebx
test eax,eax
jz end_loop
jmp msg_loop
end_loop:
invoke ExitProcess,[msg.wParam]
proc WindowProc,hwnd,wmsg,wparam,lparam
enter
push ebx esi edi
cmp [wmsg],WM_CREATE
jz .wmcreate
cmp [wmsg],WM_SIZE
jz .wmsize
cmp [wmsg],WM_PAINT
jz .wmpaint
cmp [wmsg],WM_KEYDOWN
jz .wmkeydown
cmp [wmsg],WM_DESTROY
jz .wmdestroy
.defwndproc:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp .finish
.wmcreate:
;fullscreen
mov [dmScreenSettings.dmSize],sizeof.DEVMODE
push [screenWidth]
pop [dmScreenSettings.dmPelsWidth]
push [screenHeight]
pop [dmScreenSettings.dmPelsHeight]
mov [dmScreenSettings.dmBitsPerPel],screenBPP
mov [dmScreenSettings.dmDisplayFrequency],screenFreq
mov [dmScreenSettings.dmFields],DM_BITSPERPEL+DM_PELSWIDTH+DM_PELSHEIGHT+D M_DISPLAYFREQUENCY
invoke ChangeDisplaySettings,dmScreenSettings,CDS_FULLSCREEN
;cursor hide
invoke ShowCursor,ebx
;init opengl
invoke GetDC,[hwnd]
mov [hdc],eax
mov [pfd.nSize],sizeof.PIXELFORMATDESCRIPTOR
mov [pfd.nVersion],1
mov [pfd.dwFlags],PFD_SUPPORT_OPENGL+PFD_DOUBLEBUFFER+PFD_DRAW_TO_WINDOW
mov [pfd.dwLayerMask],PFD_MAIN_PLANE
mov [pfd.iPixelType],PFD_TYPE_RGBA
mov [pfd.cColorBits],screenBPP
mov [pfd.cDepthBits],16
invoke ChoosePixelFormat,[hdc],pfd
invoke SetPixelFormat,[hdc],eax,pfd
invoke wglCreateContext,[hdc]
mov [hrc],eax
invoke wglMakeCurrent,[hdc],[hrc]
invoke GetClientRect,[hwnd],rc
invoke glViewport,ebx,ebx,[rc.right],[rc.bottom]
;z-buffer
invoke glClearDepth,ebx
invoke glDepthFunc,GL_GEQUAL
invoke glEnable,GL_DEPTH_TEST
;blending - works strange :(
;invoke glColor4f,1.0f,1.0f,1.0f,0.5f
;invoke glBlendFunc,GL_SRC_ALPHA,GL_ONE
;invoke glEnable,GL_BLEND
;perspective
invoke glHint,GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST
;lighting
invoke glShadeModel,GL_SMOOTH
invoke glLightfv,GL_LIGHT0,GL_AMBIENT,LightAmbient
invoke glLightfv,GL_LIGHT0,GL_POSITION,LightSourcePosition
invoke glEnable,GL_LIGHT0
invoke glEnable,GL_NORMALIZE
invoke glEnable,GL_LIGHTING
;fog
invoke glFogi,GL_FOG_MODE,GL_LINEAR
invoke glFogfv,GL_FOG_COLOR,fogColor
invoke glFogf,GL_FOG_DENSITY,0.1f
invoke glHint,GL_FOG_HINT,GL_DONT_CARE
invoke glFogf,GL_FOG_START,0.6f
invoke glFogf,GL_FOG_END,0.0f
invoke glEnable,GL_FOG
;texture - no works !
invoke glGenTextures,1,texture
invoke LoadImage,[hInstance],texture_back,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTIO N
test eax,eax
jnz .loadOK
invoke MessageBox,HWND_DESKTOP,er,er,MB_OK
.loadOK:
mov [hBack],eax
invoke GetObject,[hBack],sizeof.BITMAP,infoBack
invoke glBindTexture,GL_TEXTURE_2D,[texture]
invoke glTexImage2D,GL_TEXTURE_2D,0,3,[infoBack.bmWidth],[infoBack.bmHeight], 0,GL_BGR_EXT,GL_UNSIGNED_BYTE,infoBack.bmBits
invoke glTexParameteri,GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR
invoke glTexParameteri,GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR
invoke glEnable,GL_TEXTURE_2D
;lists
invoke glNewList,cube,GL_COMPILE
invoke glBegin,GL_QUADS
invoke glBindTexture,GL_TEXTURE_2D,[texture]
invoke glNormal3f,ebx,ebx,0.5f
invoke glTexCoord2f,0.0f,0.0f
invoke glVertex3f,-0.4f,-0.4f,-0.4f
invoke glTexCoord2f,0.0f,1.0f
invoke glVertex3f,-0.4f,0.4f,-0.4f
invoke glTexCoord2f,1.0f,1.0f
invoke glVertex3f,0.4f,0.4f,-0.4f
invoke glTexCoord2f,1.0f,0.0f
invoke glVertex3f,0.4f,-0.4f,-0.4f

invoke glNormal3f,ebx,ebx,-0.5f
invoke glVertex3f,-0.4f,-0.4f,0.4f
invoke glVertex3f,-0.4f,0.4f,0.4f
invoke glVertex3f,0.4f,0.4f,0.4f
invoke glVertex3f,0.4f,-0.4f,0.4f
invoke glNormal3f,0.5f,ebx,ebx
invoke glVertex3f,-0.4f,-0.4f,-0.4f
invoke glVertex3f,-0.4f,0.4f,-0.4f
invoke glVertex3f,-0.4f,0.4f,0.4f
invoke glVertex3f,-0.4f,-0.4f,0.4f
invoke glNormal3f,-0.5f,ebx,ebx
invoke glVertex3f,0.4f,0.4f,0.4f
invoke glVertex3f,0.4f,0.4f,-0.4f
invoke glVertex3f,0.4f,-0.4f,-0.4f
invoke glVertex3f,0.4f,-0.4f,0.4f
invoke glNormal3f,ebx,-0.5f,ebx
invoke glVertex3f,-0.4f,0.4f,0.4f
invoke glVertex3f,-0.4f,0.4f,-0.4f
invoke glVertex3f,0.4f,0.4f,-0.4f
invoke glVertex3f,0.4f,0.4f,0.4f
invoke glNormal3f,ebx,0.5f,ebx
invoke glVertex3f,-0.4f,-0.4f,0.4f
invoke glVertex3f,-0.4f,-0.4f,-0.4f
invoke glVertex3f,0.4f,-0.4f,-0.4f
invoke glVertex3f,0.4f,-0.4f,0.4f
invoke glEnd
invoke glEndList
xor eax,eax
jmp .finish
.wmsize:
mov eax,[lparam]
mov ebx,eax
and eax,0ffffh
shr ebx,16
mov [screenWidth],eax
mov [screenHeight],ebx
cmp [screenHeight],0
jnz .nz
inc [screenHeight]
.nz:
invoke glViewport,0,0,[screenWidth],[screenHeight]
invoke glMatrixMode,GL_PROJECTION
invoke glLoadIdentity
fild [screenWidth]
fild [screenHeight]
fdivp st1,st0
fstp [ratio]
;DOESN'T WORKS !!! ;invoke gluPerspective,const_45d1,const_45d0,dword [ratio],dword [ratio+4],const_01d1,const_01d0,const_100d1,const_100d0
invoke glMatrixMode,GL_MODELVIEW
invoke glLoadIdentity
jmp .finish
.wmpaint:
;clear
invoke glClear,GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT
invoke glClearColor,0.5f,0.5f,0.5f,1.0f
;rotate
invoke glRotatef,[theta],0.2f,0.3f,0.1f
;cube
invoke glCallList,cube
;draw buffer
invoke SwapBuffers,[hdc]
xor eax,eax
jmp .finish
.wmkeydown:
cmp [wparam],VK_ESCAPE
jnz .defwndproc
.wmdestroy:
;exit
invoke wglMakeCurrent,ebx,ebx
invoke wglDeleteContext,[hrc]
invoke ReleaseDC,[hwnd],[hdc]
invoke PostQuitMessage,ebx
xor eax,eax
.finish:
pop edi esi ebx
return
data import
include 'imports.inc'
end data
data resource
include 'resources.inc'
end data
const_100d0 equ 1079574528
const_100d1 equ ebx
const_01d0 equ 1069128089
const_01d1 equ -1717986918
const_45d0 equ 40468000h
const_45d1 equ ebx
screenBPP=32
screenFreq=60
screenWidth dd 800
screenHeight dd 600
theta GLfloat 0.5f
fogColor GLfloat 0.5f,0.5f,0.5f,1.0f
LightAmbient GLfloat 0.5f,0.5f,0.5f,0.1f
LightSourcePosition GLfloat 0.0f,0.0f,-2.0f,1.0f
szTitle db 'Tyler Durden 3D',0
szClass db 't3d',0
er db 'Error loading texture',0
cube GLuint 1.0f,1.0f,0.0f
dmScreenSettings DEVMODE
pfd PIXELFORMATDESCRIPTOR
msg MSG
wc WNDCLASS
rc RECT
infoBack BITMAP
hInstance dd ?
hBack dd ?
ratio dq ?
texture GLuint ?
hdc dd ?
hrc dd ?

------------ --------------- --------------- -------------
Типа, заранее благодарю ;)

_1014052460__3d.zip


Дата: Фев 25, 2004 09:40:11

tylerdurden
Зачем такой большой листинг, сам пишешь что проблема с ресурсами..

Вся прелесть FASMа в том, что ему линкер в общем-то и не нужен.
А следовательно и LoadImage & Co :

The "file" is a special directive and its syntax is different. This
directive includes a chain of bytes from file and it should be followed by the
quoted file name, then optionally numerical expression specifying offset in
file preceded by the colon, then - also optionally - comma and numerical
expression specifying count of bytes to include (if no count is specified, all
data up to the end of file is included).


Powered by miniBB 1.6 © 2001-2002
Время загрузки страницы (сек.): 0.043