flat assembler
Message board for the users of flat assembler.

Index > Windows > Help me with OpenGL Textures...

Author
Thread Post new topic Reply to topic
Tyler Durden



Joined: 24 Feb 2004
Posts: 50
Tyler Durden 24 Feb 2004, 23:58
i ! Help me pelase ! This is my first opengl program (in fasm). But something is wrong ! Proc LoadImage returns "0". So texturemaping doesn't works Sad Also some problems with perspective (it doesn't works to Sad ) Please HELP !
Full source attached...

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

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_CLIPCH ILDREN,ebx,ebx,[screenWidth],[screenHeight],ebx,ebx,[hInstance],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+DM_DISPLAYF REQUENCY
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 Sad
;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_CREATEDIBSECTION
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_E XT,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=85
screenWidth dd 1024
screenHeight dd 768
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 ?
------------ --------------- --------------- -------------
the end.


Description:
Download
Filename: 3d.zip
Filesize: 37.05 KB
Downloaded: 501 Time(s)

Post 24 Feb 2004, 23:58
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.