flat assembler
Message board for the users of flat assembler.

Index > Windows > LoadImage issue...

Author
Thread Post new topic Reply to topic
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 19 Jun 2007, 06:42
LoadImage keeps returning 0. That means it's not liking my resource id...

[code]invoke LoadImage, handle, IDB_CUBE, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION [/quote]

and my resource

[code]section '.rsrc' readable data resource

directory RT_BITMAP, bitmaps

resource bitmaps, IDB_CUBE, LANG_NEUTRAL, cube

bitmap cube, "cube.bmp" [/code]

And if you want the whole code (warning: messy as heck):

[code];NOTE: The code that is taking up all the processor's clock happens to be the layered attribute.

handle:
use32
format PE GUI 4.0

entry main

include '%fasminc%\win32ax.inc'
include '%fasminc%\opengl.inc'

;Usually it's not wise setting the screen size into a square. But for some reson, it worked this time.

sizex = 200
sizey = 200
speedx = 10
speedy = 10
IDB_CUBE = 7

section '.code' readable writeable executable

Class du "GENERIC", 0
wMain WNDCLASS 0, leproc, 0, 0, 0, 0, 0, 0, 0, Class
tMain du "Cube", 0
hMain dd 0
mMain MSG
hdcMain dd 0
hrcMain dd 0
pfdMain PIXELFORMATDESCRIPTOR
RMain RECT

aspect dq 0f

hBMP dd 0
iBMP dd 0

BMP BITMAP

xpos dd 0
ypos dd 0

quadrot GLfloat 0f
quadrotrate GLfloat 0.5f
;==========================================================================

main:

mov [wMain.hInstance], handle
invoke LoadIcon, 0, IDI_APPLICATION
mov [wMain.hIcon], eax
invoke LoadCursor, 0, IDC_ARROW
mov [wMain.hCursor], eax
invoke RegisterClass, wMain
invoke CreateWindowEx, WS_EX_LAYERED or WS_EX_TOPMOST, Class, tMain, WS_VISIBLE or WS_POPUP or WS_CLIPCHILDREN\
or WS_CLIPSIBLINGS, 0, 0, sizex, sizey, NULL, NULL, handle,\
NULL
mov [hMain], eax
mov [pfdMain.nSize], sizeof.PIXELFORMATDESCRIPTOR
mov [pfdMain.nVersion], 1
mov [pfdMain.dwFlags], PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER
mov [pfdMain.iPixelType], PFD_TYPE_RGBA
mov [pfdMain.cColorBits], BYTE 32
mov [pfdMain.cDepthBits], BYTE 32
mov [pfdMain.dwLayerMask], PFD_MAIN_PLANE
invoke SetLayeredWindowAttributes, [hMain], 0x00FFFFFF, 0, LWA_COLORKEY
invoke GetDC, [hMain]
mov [hdcMain], eax
invoke ChoosePixelFormat, eax, pfdMain
invoke SetPixelFormat, [hdcMain], eax, pfdMain
invoke wglCreateContext, [hdcMain]
mov [hrcMain], eax
invoke wglMakeCurrent, [hdcMain], [hrcMain]
invoke glEnable, GL_TEXTURE_2D
invoke glShadeModel, GL_SMOOTH
invoke glEnable, GL_DEPTH_TEST
invoke glHint, GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
invoke glEnable, GL_BLEND
invoke glGenTextures, 2, iBMP
invoke LoadImage, handle, IDB_CUBE, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION
or eax, eax
jz msgloopend
mov [hBMP], eax
invoke GetObject, eax, sizeof.BITMAP, BMP
invoke glBindTexture, GL_TEXTURE_2D, [iBMP]
invoke gluBuild2DMipmaps, GL_TEXTURE_2D, 3, [BMP.bmWidth], [BMP.bmHeight], GL_BGR_EXT, GL_UNSIGNED_BYTE, [BMP.bmBits]
invoke glTexParameteri, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
invoke glTexParameteri, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
;+----------+
;| MSG LOOP |
;+----------+

msgloop:
call DrawStuff
invoke Sleep, 20 ;To keep the layered thingy from eating up the processor
invoke PeekMessage, mMain, 0, 0, 0, PM_REMOVE
cmp [mMain.message], WM_QUIT
je msgloopend
invoke TranslateMessage, mMain
invoke DispatchMessage, mMain
jmp msgloop
msgloopend:

;+---------+
;| CLEANUP |
;+---------+

invoke glDeleteTextures, 6, iBMP
invoke wglMakeCurrent, 0, 0
invoke wglDeleteContext, [hrcMain]
invoke ReleaseDC, [hMain], [hdcMain]
invoke ExitProcess, 0

;==========================================================================

proc leproc, hwnd, msg, wparam, lparam
push ebx esi edi
cmp [msg], WM_DESTROY
je DESTROY
cmp [msg], WM_KEYDOWN
je KEYDOWN
jmp prepwindow
DESTROY:
invoke PostQuitMessage, 0
ret
KEYDOWN:
cmp [wparam], VK_UP
je UP
cmp [wparam], VK_DOWN
je DOWN
cmp [wparam], VK_LEFT
je LEFT
cmp [wparam], VK_RIGHT
je RIGHT
UP:
sub [ypos], speedy
jmp prepwindow
DOWN:
add [ypos], speedy
jmp prepwindow
LEFT:
sub [xpos], speedx
jmp prepwindow
RIGHT:
add [xpos], speedx
jmp prepwindow
prepwindow:
invoke GetSystemMetrics, SM_CXSCREEN
sub eax, sizex
cmp [xpos], 0
ja gox
add [xpos], speedx
gox:
cmp [xpos], eax
jb gox2
sub [xpos], speedx
gox2:
invoke GetSystemMetrics, SM_CYSCREEN
sub eax, sizey
cmp [ypos], 0
ja goy
add [ypos], speedy
goy:
cmp [ypos], eax
jb goy2
sub [ypos], speedy
goy2:
invoke GetClientRect, [hwnd], RMain
invoke glViewport, 0, 0, [RMain.right], [RMain.bottom]
invoke glMatrixMode, GL_PROJECTION
invoke glLoadIdentity
fild [RMain.right]
fild [RMain.bottom]
fdivp st1, st0
fstp QWORD [aspect]
glcall gluPerspective, 45f, aspect, 0.1f, 100f
invoke glMatrixMode, GL_MODELVIEW
invoke glLoadIdentity
invoke SetWindowPos, [hwnd], HWND_TOPMOST, [xpos], [ypos], 0, 0, SWP_NOSIZE
invoke DefWindowProc, [hwnd], [msg], [wparam], [lparam]
pop edi esi ebx
ret
endp

;==========================================================================

proc DrawStuff
invoke glClear, GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
invoke glLoadIdentity
invoke glDisable, GL_TEXTURE_2D ;So color works...
;Below is used so everything behind the cube is white instead of black, which will get filtered out
;making everything but the cube transparent.
invoke glBegin, GL_QUADS
invoke glColor3f, 1f, 1f, 1f
invoke glVertex3f, 100f, 100f, -10f
invoke glVertex3f, -100f, 100f, -10f
invoke glVertex3f, -100f, -100f, -10f
invoke glVertex3f, 100f, -100f, -10f
invoke glEnd
invoke glEnable, GL_TEXTURE_2D
invoke glTranslatef, 0f, 0f, -5f
invoke glRotatef, [quadrot], 5f, 5f, 5f
invoke glBegin, GL_QUADS
invoke glTexCoord2f, 0f, 0f
invoke glVertex3f, -1f, -1f, 1f
invoke glTexCoord2f, 1f, 0f
invoke glVertex3f, 1f, -1f, 1f
invoke glTexCoord2f, 1f, 1f
invoke glVertex3f, 1f, 1f, 1f
invoke glTexCoord2f, 0f, 1f
invoke glVertex3f, -1f, 1f, 1f
invoke glTexCoord2f, 0f, 0f
invoke glVertex3f, -1f, -1f, -1f
invoke glTexCoord2f, 1f, 0f
invoke glVertex3f, -1f, 1f, -1f
invoke glTexCoord2f, 1f, 1f
invoke glVertex3f, 1f, 1f, -1f
invoke glTexCoord2f, 0f, 1f
invoke glVertex3f, 1f, -1f, -1f
invoke glTexCoord2f, 0f, 0f
invoke glVertex3f, -1f, 1f, -1f
invoke glTexCoord2f, 1f, 0f
invoke glVertex3f, -1f, 1f, 1f
invoke glTexCoord2f, 1f, 1f
invoke glVertex3f, 1f, 1f, 1f
invoke glTexCoord2f, 0f, 1f
invoke glVertex3f, 1f, 1f, -1f
invoke glTexCoord2f, 0f, 0f
invoke glVertex3f, -1f, -1f, -1f
invoke glTexCoord2f, 1f, 0f
invoke glVertex3f, 1f, -1f, -1f
invoke glTexCoord2f, 1f, 1f
invoke glVertex3f, 1f, -1f, 1f
invoke glTexCoord2f, 0f, 1f
invoke glVertex3f, -1f, -1f, 1f
invoke glTexCoord2f, 0f, 0f
invoke glVertex3f, 1f, -1f, -1f
invoke glTexCoord2f, 1f, 0f
invoke glVertex3f, 1f, 1f, -1f
invoke glTexCoord2f, 1f, 1f
invoke glVertex3f, 1f, 1f, 1f
invoke glTexCoord2f, 0f, 1f
invoke glVertex3f, 1f, -1f, 1f
invoke glTexCoord2f, 0f, 0f
invoke glVertex3f, -1f, -1f, -1f
invoke glTexCoord2f, 1f, 0f
invoke glVertex3f, -1f, -1f, 1f
invoke glTexCoord2f, 1f, 1f
invoke glVertex3f, -1f, 1f, 1f
invoke glTexCoord2f, 0f, 1f
invoke glVertex3f, -1f, 1f, -1f
invoke glEnd

fld DWORD [quadrot]
fld DWORD [quadrotrate]
faddp
fstp DWORD [quadrot]
invoke SwapBuffers, [hdcMain]
ret
endp

;==========================================================================

section '.idata' readable writeable import

library kernel, 'kernel32.dll',\
gdi, 'gdi32.dll',\
glu, 'glu32.dll',\
opengl, 'opengl32.dll',\
user, 'user32.dll'

import kernel, ExitProcess, 'ExitProcess',\
Sleep, 'Sleep'

import gdi, ChoosePixelFormat, 'ChoosePixelFormat',\
GetObject, 'GetObjectW',\
SetPixelFormat, 'SetPixelFormat',\
SwapBuffers, 'SwapBuffers'

import glu, gluBuild2DMipmaps, 'gluBuild2DMipmaps',\
gluPerspective, 'gluPerspective'

import opengl, glBegin, 'glBegin',\
glBindTexture, 'glBindTexture',\
glClear, 'glClear',\
glColor3f, 'glColor3f',\
glDeleteTextures, 'glDeleteTextures',\
glDisable, 'glDisable',\
glEnable, 'glEnable',\
glEnd, 'glEnd',\
glGenTextures, 'glGenTextures',\
glHint, 'glHint',\
glLoadIdentity, 'glLoadIdentity',\
glMatrixMode, 'glMatrixMode',\
glRotatef, 'glRotatef',\
glShadeModel, 'glShadeModel',\
glTexCoord2f, 'glTexCoord2f',\
glTexParameteri, 'glTexParameteri',\
glTranslatef, 'glTranslatef',\
glVertex3f, 'glVertex3f',\
glViewport, 'glViewport',\
wglCreateContext, 'wglCreateContext',\
wglDeleteContext, 'wglDeleteContext',\
wglMakeCurrent, 'wglMakeCurrent'

import user, CreateWindowEx, 'CreateWindowExW',\
DefWindowProc, 'DefWindowProcW',\
DispatchMessage, 'DispatchMessageW',\
GetClientRect, 'GetClientRect',\
GetDC, 'GetDC',\
GetSystemMetrics, 'GetSystemMetrics',\
LoadCursor, 'LoadCursorW',\
LoadIcon, 'LoadIconW',\
LoadImage, 'LoadImageA',\
PeekMessage, 'PeekMessageW',\
PostQuitMessage, 'PostQuitMessage',\
RegisterClass, 'RegisterClassW',\
ReleaseDC, 'ReleaseDC',\
SetLayeredWindowAttributes, 'SetLayeredWindowAttributes',\
SetWindowPos, 'SetWindowPos',\
TranslateMessage, 'TranslateMessage'

section '.rsrc' readable data resource

directory RT_BITMAP, bitmaps

resource bitmaps, IDB_CUBE, LANG_NEUTRAL, cube

bitmap cube, "cube.bmp"[/code]

I've had troubles like this with wave files using playsound as well. I've been looking around in the search and apparently this issue has be resolved many times before, but apparently there's something different about my code... Don't know what it is, but it should be working. Thought i'd ask some one here to take a fresh look at the first two things i posted... See if i missed anything... Thanks in advance.
Post 19 Jun 2007, 06:42
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.