Question for VB OpenGL programmers regarding textures

Started by
10 comments, last by KyleEasterly 20 years, 6 months ago
I am in the process of (and so far not getting anywhere fast) switching the graphics engine for my 2D tile-based game from DirectDraw to OpenGL. The old graphics engine was ORE (Online RPG Engine... last release was about 2 years ago). I understood how the engine worked except for all the low-level DD stuff. I've been wanting to learn OpenGL and thought this would be a nice little project. Anyway, down to my real question/problem. So we have this file that has a list of all our graphics and their file numbers. Some graphics have many 'frames' per BMP file, but I'll get to that later. My main problem is that I seem to be unable to load more than 1 texture. I have the array (gaTextures() as long, like in example 9) for the textures and thats ok, but theres something up with initializing the texture I think. I enter a loop (for testing I'm only working with 15 ground tiles) that loads the textures, but when I start up the game, it only draws the texture that was loaded last. Also, it has a red tint to it (this has something to do with the RGB and BGR thing and me not switching it around, but I'm clueless as how to do that... lesson 9 used a black and white BMP so I can see why the code to switch was not even mentioned.) I tried having one function loop through the list and call a separate subscript to actually load the texture, but that didn't work... here's the code: Public Function LoadGLTextures() As Boolean Dim LoopA As Integer FrmLoading.Show FrmLoading.Caption = "Loading textures" NumGrhFiles = Val(GetVar(IniPath & "Grh.ini", "INIT", "NumGrhFiles")) NumGrhs = Val(GetVar(IniPath & "Grh.ini", "INIT", "NumGrhs")) ReDim gaTextures(NumGrhs) glGenTextures NumGrhs, gaTextures(0) For LoopA = 1 To NumGrhs DoEvents FrmLoading.LblInfo.Caption = "Loading texture " & LoopA & " of " & NumGrhs Call LoadGLTextures2(LoopA) Next FrmLoading.Hide LoadGLTextures = True End Function Sub LoadGLTextures2(Idx As Integer) Dim sFile As String Dim bmFile As BITMAPFILEHEADER Dim bmInfo As BITMAPINFOHEADER Dim bmRGB() As RGBQUAD Dim iFile As Integer Dim lImageSize As Long Dim iPixelSize As Integer Dim baImageData() As Byte sFile = App.Path & GrhPath & "Grh" & GrhData(Idx).FileNum & ".bmp" iFile = FreeFile If FileExist(sFile, vbNormal) = True Then Open sFile For Binary As iFile Get #iFile, , bmFile Get #iFile, , bmInfo If (bmInfo.biBitCount < 24) Then ReDim bmRGB(bmInfo.biClrUsed) Get #iFile, , bmRGB End If iPixelSize = bmInfo.biBitCount / 8 lImageSize = bmInfo.biWidth * bmInfo.biHeight * iPixelSize ReDim baImageData(lImageSize) Get #iFile, , baImageData Close #iFile glBindTexture glTexture2D, gaTextures(Idx) glTexParameteri glTexture2D, tpnTextureMagFilter, GL_LINEAR glTexParameteri glTexture2D, tpnTextureMinFilter, GL_LINEAR glTexImage2D glTexture2D, 0, 3, bmInfo.biWidth, bmInfo.biHeight, 0, tiBGRExt, GL_UNSIGNED_BYTE, baImageData(0) Erase baImageData End If End Sub That's all I've got for loading textures, except for the loading grh data subscript, but that works and has worked fine from day 1, I've verified that it is giving the correct file #'s during runtime. I'll post my tile-drawing code later when I get some things nailed down with it... Thanks, -Kyle Edit: Removed the bitmap declarations... [edited by - KyleEasterly on October 8, 2003 11:38:08 PM]
-Kyle Easterly
Advertisement
Quote: ''I''ll post my tile-drawing code later when I get some things nailed down with it...''

Kyle - Do you really think anyone is going to plow through hundreds of lines of your code? (Especially VB - I feel dirty just looking at it...)



You''d be better off spending a bit of time figuring out how to ask your question in a more concise manner. The less code the better.
Agreed, have you tried looking at some of NeHe''s VB Ported tutorials that use a Texture Arrays?
"I can only show you the door, your the one who has to walk through it." -Morpheus
Alright, I removed the declarations from the post (they were pretty long and aren''t really necessary.)

The code I''m using is straight from tutorial 9 ported to VB6. The way they do it is instead of using a loop, is running through the code twice.

I''m thinking theres something weird where I do this:
glGenTextures NumGrhs, gaTextures(0)
Because gaTextures() won''t work, needs the 0 index. However in the tutorial they did the same thing (except with 1 instead of 15 (value of numgrhs)

Ferdinand the Bull: I was going to post that after the problems have been worked out so anyone who wanted to see how to do a 2d tileengine in OpenGL could...
-Kyle Easterly
The red tint is probably RGB - BGR
Just
int temp;for( int i = 0; i < Size; ++i){    temp = textureArray;    textureArray = textureArray[i+2];<br>    textureArray[i+2] = temp;<br>}<br> </pre> <br>As for &#111;nly drawing &#111;ne texture, are you sure you''re keeping the texture ids in seperate variables?  </i>  
Ahhhhh

Why do people use that laungage
quote:Original post by skow
Ahhhhh

Why do people use that laungage



Because it''s handy for RAD, and relatively easy to understand for beginners.
Not a VB programmer but, you have to call BindTexture everytime you wish to use said texture, thats probably why you get the last texture loaded instead of the one you want.
Also, remember to do a glColor3f(1.0f,1.0f,1.0f) before rendering the textured polys.

Proud aedGUI developer.
Oh thank you Kwizatz, that fixed the red tint. Woohoo!!!

Also, about doing BindTexture, I do that. Here is my drawing the textured quad code:

glColor3f 1#, 1#, 1#
glBindTexture glTexture2D, gaTextures(2) ''(MapData(LoopX, LoopY).Graphic(1).GrhIndex)
glTexCoord2f 0#, 0#: glVertex3f -1#, 1#, 0#
glTexCoord2f 1#, 0#: glVertex3f 1#, 1#, 0#
glTexCoord2f 1#, 1#: glVertex3f 1#, -1#, 0#
glTexCoord2f 0#, 1#: glVertex3f -1#, -1#, 0#

I had it draw the second texture because I am only loading 15 textures, and we have 80 or so ground textures so this way I''d be able to see texture #2 whereever I am in the world. But the texture that is being drawn is number 15, not 2... I can change that number to anything and it will still come out as texture #15, so I''m thinking there has to be something wrong with the loading-the-texture code.
-Kyle Easterly
Still having issues here. Tried the method of texture-loading found in lesson 17 and the SAME EXACT THING HAPPENS.

I''m completely stumped by this.
-Kyle Easterly

This topic is closed to new replies.

Advertisement