flat assembler
Message board for the users of flat assembler.
Index
> Windows > *SOLVED* OpenGL Textures - Porting problem. |
Author |
|
calpol2004 16 Jan 2008, 17:06
EDIT: SOLVED PROBLEM, SEE END REPLY, EXECUTABLE UPDATED TOO .
recently i decided to start learning how to use opengl. Since i have a module on it it next semester i thought i may as well check it out. It's either that or make a flash game in a newbie WYSIWYG editor *gah*. Well, i've been using NeHe tutorials and i'm currently up to http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06. At the moment i have a simple 3D map (4 walls and a floor) which you can walk around using the arrows keys. But im stuck getting my texture loader to work. The examples from the website are written in all sorts of languages (at least 20...) and one of them is MASM. Which lucky for me is kind of similar to FASM, but alas im still having problems. What makes things really annoying is that the assembled MASM executable can't be read in a debugger so i can't see exactly whats going on (contains too much embedded data, probably a compressed program). There is one key difference between mine and the MASM code, and that is that i want to load the image from a file as opposed to from a resource within the program. My LoadImage() returns successful so im assuming this is not the problem. ORIGINAL MASM CODE: Code: invoke glGenTextures, 1, ADDR texture invoke LoadImage, hInstance, IDD_BITMAP, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION cmp eax, 0 je end_load mov hBMP, eax invoke GetObject, hBMP, sizeof BITMAP, ADDR ImgInfo invoke glBindTexture, GL_TEXTURE_2D, texture invoke glTexImage2D, GL_TEXTURE_2D, 0, 3, ImgInfo.bmWidth, ImgInfo.bmHeight,\ 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, ImgInfo.bmBits invoke glTexParameteri, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR invoke glTexParameteri, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR mov eax, 1 end_load: ret My Code: Code: invoke glGenTextures,1,texture invoke LoadImage,NULL,filename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE+LR_CREATEDIBSECTION mov [hBMP],eax invoke GetObject,eax,sizeof.BITMAP,[ImgInfo] invoke glBindTexture, GL_TEXTURE_2D,[texture] invoke glTexImage2D, GL_TEXTURE_2D,0,3,[ImgInfo.bmWidth],[ImgInfo.bmHeight],0,GL_BGR_EXT,GL_UNSIGNED_BYTE,[ImgInfo.bmBits] invoke glTexParameteri,GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR invoke glTexParameteri, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR my data declared like so: Code: filename db 'walltexture.bmp',0 hBMP dd NULL ImgInfo BITMAP ? texture GLuint NULL ;im pretty sure this is just a dd too... I've checked all the windows functions and they're returning successfully. I can't check the opengl functions since none of the sites explaining functionality seems to tell me anything about them :/. Can anyone see any faults in my program? If you can't, have you any opengl examples which load textures? I've included my source with executable, if you want to take a look.
Last edited by calpol2004 on 17 Jan 2008, 18:41; edited 2 times in total |
|||||||||||
16 Jan 2008, 17:06 |
|
r22 16 Jan 2008, 21:08
Easy fix for you (there may be more errors but this one popped out at me).
Remove the square brackets [] on ImgInfo in your GetObject call. |
|||
16 Jan 2008, 21:08 |
|
Madis731 17 Jan 2008, 07:59
Isn't this bad programming?
Code: invoke glTexCoord3f,0.0,0.0,0.0 invoke glVertex3f,0.0,0.0,0.0 invoke glTexCoord3f,1.0,0.0,0.0 I haven't done much 3D-programming but I remember D3D had a Vertex buffer ^o) and you just give it a pointer. Looks like here you make a call for every vertex :S. |
|||
17 Jan 2008, 07:59 |
|
calpol2004 17 Jan 2008, 09:14
Madis731 wrote: Isn't this bad programming? Yea, i think they're called display lists. You can store a routine and call it with one line. I haven't learned how to use those yet though. |
|||
17 Jan 2008, 09:14 |
|
calpol2004 17 Jan 2008, 18:45
Turns out that [hBMP] wasn't a valid handle. i was tweaking with VirtualAlloc() and LocalAlloc until instead of displaying the current colour it displayed black. This led me to believe that [hBMP] was now valid but was empty.
So i spent 3 or 4 hours trying to get ReadFile to work, until i decided to use fread() instead. I then swapped VirtualAlloc for malloc() and CreateFile for fopen(). Now fread() actually read the file and the image displayed. Heres the code: Code: cinvoke malloc,256*256*3 mov [hBmp],eax cinvoke fopen,filename,access mov [hFile],eax cinvoke fread,[hBmp],256*256*3,1,[hFile] cinvoke fclose,[hFile] invoke glGenTextures,1,GLTexture invoke glBindTexture,GL_TEXTURE_2D,GLTexture invoke glTexEnvf,GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE invoke glTexParameterf,GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST invoke glTexParameterf,GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR invoke glTexParameterf,GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT invoke glTexParameterf,GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT invoke gluBuild2DMipmaps,GL_TEXTURE_2D,3,256,256,GL_RGB,GL_UNSIGNED_BYTE,[hBmp] Last edited by calpol2004 on 18 Jan 2008, 14:55; edited 2 times in total |
|||
17 Jan 2008, 18:45 |
|
Madis731 18 Jan 2008, 07:24
Nice - I thought its 2D at first and was a bit disappointed. Then I read the source and saw the keys (L, R, U, D,...) and started using them NICE!
Btw, did you notice how strangely the floor acts when you rotate around. Maybe its my drivers or my videocard if you don't notice it, but I think its about how OGL transfers the colours in a two-colour "environment" (read: on a quad consisting of two tri-vertex planes). |
|||
18 Jan 2008, 07:24 |
|
asmfan 18 Jan 2008, 09:34
malloc, fopen, fread, fclose, free - C calling convention. Use cinvoke rather than invoke.
|
|||
18 Jan 2008, 09:34 |
|
calpol2004 18 Jan 2008, 14:38
Madis731 wrote: Nice - I thought its 2D at first and was a bit disappointed. Then I read the source and saw the keys (L, R, U, D,...) and started using them NICE! Yea i did, it does look a lot better with a texture as the floor (still needs work though). Come to think of it, take a look for yourself (attached). Now i've got textures down, it's collision detection, looking with mouse (not looking forward to the maths...), Simple timing so it runs at the same speed on all pc's and loading the world from a file. . I'm hoping to have a VERY simple 3D engine ready for when the module starts . asmfan wrote: malloc, fopen, fread, fclose, free - C calling convention. Use cinvoke rather than invoke. Thanks :p, i usually forget things like that .
|
|||||||||||
18 Jan 2008, 14:38 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.