Skybox with seams

Hi Everyone!
I guess this topic is in every forum, but I can’t just find the answer! It doesn’t work, and I am about to give up . :frowning:

I already posted this post in the Begginers´s forum, but I noticed that a similar question was found on the advanced section, so I re-posted here. I hope it´s the correct place. :slight_smile:

I am using GL_CLAMP_TO_EDGE but seams still are visible.

I am using Visual Basic, and the reference file vbogl.tlb, does not include the GL_CLAMP_TO_EDGE constant; therefore, I defined:

Public Const GL_CLAMP_TO_EDGE = &H812F

This is my texture-loading routine:

code:

   

 (...)'Create the Mipmapped Texture 
glBindTexture glTexture2D,rsTexturesrsTextureSlot)

glTexParameteri glTexture2D, 
tpnTextureMagFilter, GL_LINEARglTexParameteri 

glTexture2D, tpnTextureMinFilter, 
GL_LINEAR_MIPMAP_NEARESTgluBuild2DMipmaps 

glTexture2D, 3, bmInfo.biWidth, bmInfo.biHeight, 
tiBGRExt, _ GL_UNSIGNED_BYTE, ByVal VarPtr
(baImageData(0))     
 
Call glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)  
  Call glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)   

Other tecnical notices:
I am using texture mapping from 0 to 1. I read in some forums that drawing a border and reducing the texture size solves the problem, but that since you are not using power of 2 textures, it greatly reduces performance. Is this true?

I am using a texture bitmap that is 1024x1024.
And a glperspective with a near =1 and a far=2000. I tried reducing the far but the problem still persists.

The symptom is that I see stripped lines of black in the borders.

Please someone help me get this to work!. Thank you so much all in advance!

Take a look at these links:

http://home.planet.nl/~monstrous/skybox.html
http://www.levp.de/3d/skybox.html
http://www.morrowland.com/apron/tutorials/gl/gl_skybox.zip

Also, look on search engines for hemispheric skybox tutorials.

Thanks for your answer! :slight_smile:

…However all the tutorials you linked I have already read… I think I have read all the existing tutorials about skyboxes!

Anyone know what could be happening?!

Maybe you accidently set the border nonzero in your glTextImage2D call?

Thanks for helping! :slight_smile:

No… I haven’t set up any border commands. Should I?!

I think I starting to realize why its not working.
I got VBOpenGL type Library v.1.2 that uses a ‘consolidation of Patrice Scribe’s ‘Microsoft OpenGL Type Library 1.1’’

That means that my library does not support OpenGL>1.1 commands, so that the CLAMP_TO_EDGE command is not recognized?! :confused:

Could this be it?!
However I defined the constant CLAMP_TO_EDGE… Shouldn’t work as it’s just a constant?! How can I include this command…?!

Please someone help me get pass this trough…

It’s just a token, it should work, unless there’s a wrapper under there filtering it (almost certainly not the case).

You should just be able to include glext.h and get the definitions too but what that looks like or whether anyone has created it for VB I have no idea. Is there a glext header with that distribution?

You must define GL_CLAMP_TO_EDGE to be the correct exact value, you do realize this don’t you?

This is what’s in glext.h:

#define GL_CLAMP_TO_EDGE 0x812F

So make sure 0x812F hex is what you define that token to be, in decimal that’s 33071 incase you need that.

Dorbie!!! THANK YOU SO MUCH!!! :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile:

I don’t know how to thank you! IT WORKED! :wink:
I put the decimal value instead of the hexadecimal and it works just fine!!!

One last question, should I texture the skybox with linear or midmapping?!

THANKS! :smiley:

GL_LINEAR should do it, but the question reveals something else you need to know.

There are two filters you set for each texture, the magnification filter (when a texture is magnified on the screen i.e. more pixels than texels) and the minification filter (when a texture is minified on screen i.e. more texels than pixels). Only the minification filter accepts MIPMAP filter tokens. Because you’re drawing a skybox it will almost certainly be drawn with the magnification filter (it would also be a waste of texture memory and performance to do anything else) so GL_LINEAR should be set on the mag filter. Even if it were minified GL_LINEAR minification produces acceptable results down to about 2:1 minification so again it is acceptable to use GL_LINEAR for this (might happen if someone draws your skybox in a really small window of VGA mode etc.).

You should really try to find that glext header file. All PCs are stuck with early OpenGL versions but programmers use wglGetProcAddress to access newer functions in the drivers and use the glext header for token definition and function type typedefs.

Thank you so much for your time! :slight_smile:
I didn’t know that…! :wink:
Cheers,
Rod

I have an updated version of the VB OpenGL type library available:

http://home.planet.nl/~buijs512/downloads/opengltlb.zip

Basicly it is a cleaned up version of Patrice Scribe’s type library. Supports OpenGL 1.2 (so including the GL_CLAMP_TO_EDGE definition), GLU, the latest/last version of GLUT and WGL (also has a GLEXT module with some extensions that didn’t have any new functions). Just like the original TLB it has some GDI stuff included to set up the framebuffer (pixelformat descriptor stuff).

You should be able to switch to this TLB on existing projects without issues.

It also has all functions documented, straight from the manual (see Object Explorer in VB), and fixes some enummerator typos.

Removed however are the VB enumerators, though this does make your code cleaner and easier to port to other languages.

Note that some tokens do not work when using the old TLB (Scribe’s), because VB doesn’t allow them to be passed (they are not in the VB enumerator list). For example passing GL_SEPARATE_SPECULAR_COLOR to glLightModel won’t work, as well as some texture format tokens on glTexImage2d.
This TLB fixes these issues.

If there is any interest I can release a complete package (with source) and all that.

  • I might want to add this:

There is absolutely NO way you can call extension functions directly from Visual Basic. VB does not support function pointers. The only way to do it is to create a C++ DLL wrapper, and call that from VB.

Hi remdul! Thanks for your post! :slight_smile:

Is your Tgl file supposed to replace Patrice Scribe’s type library, or should I use both?!
I am asking you this since the tgl file I have is 538kb while yours is 161kb. Is it complete?!

Sorry if I ask too basic questions, but I am kind of a newbie with OpenGl:
Whare do you mean by the VB enumerators?
And how are tgl files made?! Can I add more OpenGl functions to the tgl if I ever need them?

Concerning the function pointers you mentioned, I read that VB can fully handle pointers: using VarPtr, StrPtr, ObjPtr, GetAddressOf, etc. The following article explains how to pass pointers as parameters of functions, so that you can pass any variable you like.
http://www.thevbzone.com/secrets.htm
Do you think this can solve the problem for supporting extensions?
…And by the way… what are extensions functions used for? Sorry for my ignorance.

Yes I am very interested in a complete package with source! :slight_smile:

Thank you so much for everything.
Rodrix

Yes, it is supposed to replace it. Of cource you have to decide on yourself which is better, but I’ve been using this one for a year (mostly for quick tool development) and has proven to be very relyable.

The file is probably smaller because it strips things like the ‘VB enumerators’ (I called them like that to avoid confusion with OpenGL related enums). Thats the glBeginModeConstants stuff for example, where you pass bmTriangles, bmQuads instead of GL_TRIANGLES and GL_QUADS to glBegin(). Scribe added that for convenience, and is nice in combination with the VB IDE Intellisense/autocompletion typing stuff, but since I’ve ported some of my tools to C++ I found it easier to use the original GL tokens. Another issue with that is that if a constant is not listed in those enumerators, it may not be passed correctly, or ‘clamped’ to the nearest enum (value) that is listed.

My build of the TLB is probably smaller because it strips those enums, as well as some other things. However, if you used clean GL code in your projects you should be able to re-compile it without error after switching. I don’t think there will be conflicts when using both, but it is reccomended to remove the Vbopengl.tlb from the references, otherwise you won’t be sure which will be used (and the problem described above may or not persist).

Type Libraries can be created be listing function definitions, DLL entry points and constants in an ODL file, and compiling it with a MIDL compiler. There should be an MSDN doc that covers it.

There’s really no reason or need to add additional GL functions to the TLB (there are none besides the extensions). As mentioned, extensions require the use of function pointers which can’t be added to TLBs (they are passive and merely serve as interface to point to DLL entrypoints). You could however add extensions tokens to the TLB, for the few extensions that do not have any new entrypoints.

VarPtr, StrPtr etc. works only for variable pointers, not for function pointers. While you can retrieve the GL extension entrypoint addresses, VB doesn’t provide a mechanism to call them.
What you can do is create a C++ DLL, that wraps the extension calls, and add those entrypoints to the ODL, and compile that into a TLB. That keeps the interface in VB tidy, but of cource you need to ship the DLL along.

You might want to check out some extension wrapper libraries, I believe there are some that include DLLs, you’d be able to use that directly without creating one yourself.

Depending on your probject, you may want to use extensions like multitexturing, vertex buffer objects.

I can’t say when I’ll release the package (currently put up with some other things) but when I do so it will be posted up here. Until then, the TLB should be all you need.

-Remdul

Thank you so much for your answer again! :slight_smile:

I have tried your .tgl file, and I get some compilation errors. For example the following are described as undefined:

Sub ZeroMemory(pvDst As Any, cbCopy As Long)
Member of VBOpenGL.WinBase
Zeros memory to destination by reference

This sub is used in the Enable open gl routine found at Nehe’s:

  Sub EnableOpenGL(ghDC As Long)
Dim pfd As PIXELFORMATDESCRIPTOR, PixFormat As Long
    
    ZeroMemory pfd, Len(pfd)
    pfd.nSize = Len(pfd)
    pfd.nVersion = 1
    pfd.dwFlags = PFD_DRAW_TO_WINDOW Or PFD_SUPPORT_OPENGL Or PFD_DOUBLEBUFFER Or PFD_GENERIC_FORMAT
    pfd.iPixelType = PFD_TYPE_RGBA
    pfd.cColorBits = 24
    pfd.cDepthBits = 16
    pfd.cStencilBits = 1
    pfd.iLayerType = PFD_MAIN_PLANE
    
    PixFormat = ChoosePixelFormat(ghDC, pfd)
    If PixFormat = 0 Then GoTo ee
    SetPixelFormat ghDC, PixFormat, pfd
    hRC = wglCreateContext(ghDC)
    wglMakeCurrent ghDC, hRC
    
Exit Sub
ee: MsgBox "Can't create OpenGL context!", vbCritical, "Errror"
    End
End Sub

Is there a way I can replace this function with another?!
Thank you so much! :slight_smile:

ZeroMemory clears the pixelformat descriptor structure, however in VB this is not needed because all variables are initialized to zero by default.

You can simply omit that call.

Here’s my init code:

Private hglrc As Long

Private Sub Form_Load()
Dim pfd As PIXELFORMATDESCRIPTOR
Dim r As Long

    pfd.nSize = Len(pfd)
    pfd.nVersion = 1
    pfd.dwFlags = PFD_SUPPORT_OPENGL Or PFD_DRAW_TO_WINDOW Or PFD_DOUBLEBUFFER Or PFD_TYPE_RGBA
    pfd.iPixelType = PFD_TYPE_RGBA
    pfd.cColorBits = 24
    pfd.cDepthBits = 16
    pfd.iLayerType = PFD_MAIN_PLANE
    r = ChoosePixelFormat(Me.hDC, pfd)
    If r = 0 Then
        MsgBox "OpenGL initialization failed.", vbCritical
        Exit Sub
    End If
    r = SetPixelFormat(Me.hDC, r, pfd)
    hglrc = wglCreateContext(Me.hDC)
    wglMakeCurrent Me.hDC, hglrc
    
End Sub

Thanks for your reply! :slight_smile:

I have tried to test taking out ZeroMemory,
but after deleting your tlb library once, and downloading it again,I can’t seem a way to add it to the references.
When I go to references and click add, the tlb library does not add itself into the list.

What am I doing wrong?!
Thank you so much in advance :slight_smile:
Cheers,
Rodrix

It works fine for me in VB6.

Maybe after removing the “VBOpenGL” libraries first?

My version of the type library is listed as “OpenGL API 1.2”.

It worked!!! Thanks for everything!
For other VB users:
Download a TLG register utility, place it in windows/system32/ and register it!

It now works fine!

Thanks!

Actually there is no need to register anything, at least not with VB6. Maybe you need to have a Service Pack installed (SP6)?

To add the type library to your project, just click Project > References, click “Browse” and select the type library file, then hit “Open”. It now apears on the list (in this case it is “OpenGL API 1.2”), find it, mark it checked and click “OK”. The functions are now available.
To be sure, check for the “OpenGL” library in the “Object Browser”.