FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Extensions with Schooner's GL

 
Post new topic   Reply to topic     Forum Index -> Schooner
View previous topic :: View next topic  
Author Message
baxissimo



Joined: 23 Oct 2006
Posts: 241
Location: Tokyo, Japan

PostPosted: Mon Feb 05, 2007 3:15 am    Post subject: Extensions with Schooner's GL Reply with quote

How do I use an extension when using Schooner's GL?

In particular I'm trying to use glCompressedTexImage2DARB.

The gl.di file contains a function pointer typedef for it:
Code:

typedef void(* PFNGLCOMPRESSEDTEXIMAGE2DARBPROC)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, GLvoid* data);


But I'm not sure how I'm supposed to access it. Do I need to use wgl functions to load the function pointer or something? In Derelict I can use
Code:

ARBTextureCompression.load("GL_ARB_texture_compression");


Thanks for any info.
Back to top
View user's profile Send private message
Bradley Smith



Joined: 20 Jun 2006
Posts: 60

PostPosted: Mon Feb 05, 2007 10:47 am    Post subject: Reply with quote

Yes, you should be able to do something like the following, but I have not tested it.

Code:
PFNGLCOMPRESSEDTEXIMAGE2DARBPROC glCompressedTexImage2DARB = cast(PFNGLCOMPRESSEDTEXIMAGE2DARBPROC)
    wglGetProcAddress( toStringz("glCompressedTexImage2DARB") );

glCompressedTexImage2DARB(target, level, internalformat, width, height, border, imageSize, data);
Back to top
View user's profile Send private message
baxissimo



Joined: 23 Oct 2006
Posts: 241
Location: Tokyo, Japan

PostPosted: Mon Feb 05, 2007 3:33 pm    Post subject: Reply with quote

Bradley Smith wrote:
Yes, you should be able to do something like the following, but I have not tested it.

Code:
PFNGLCOMPRESSEDTEXIMAGE2DARBPROC glCompressedTexImage2DARB = cast(PFNGLCOMPRESSEDTEXIMAGE2DARBPROC)
    wglGetProcAddress( toStringz("glCompressedTexImage2DARB") );

glCompressedTexImage2DARB(target, level, internalformat, width, height, border, imageSize, data);


Ok. Thanks. I just didn't see any wgl functions in Schooner on first inspection, but maybe I wasn't looking in the right place.

I'll give it a try.
Back to top
View user's profile Send private message
baxissimo



Joined: 23 Oct 2006
Posts: 241
Location: Tokyo, Japan

PostPosted: Fri Feb 16, 2007 8:59 pm    Post subject: Got it working Reply with quote

Got it working with the following version/import mojo:

Code:

version (useDerelict) {
import derelict.opengl.extension.arb.texture_compression;
} else {
    private
    {
        PFNGLCOMPRESSEDTEXIMAGE3DARBPROC         glCompressedTexImage3DARB;
        PFNGLCOMPRESSEDTEXIMAGE2DARBPROC         glCompressedTexImage2DARB;
        PFNGLCOMPRESSEDTEXIMAGE1DARBPROC         glCompressedTexImage1DARB;
        PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC      glCompressedTexSubImage3DARB;
        PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC      glCompressedTexSubImage2DARB;
        PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC      glCompressedTexSubImage1DARB;
        PFNGLGETCOMPRESSEDTEXIMAGEARBPROC        glGetCompressedTexImageARB;

        version(Windows)
            import win32.wingdi; // for wgl funcs
        else version(linux)
            version = UsingGLX;
        version(UsingGLX)
            import x11.glx;
        import string=std.string;

        bool glBindExtFunc(void **ptr, char[] funcName)
        {
            version(Windows)
                *ptr = wglGetProcAddress(string.toStringz(funcName));
            else version(UsingGLX)
                *ptr = glXGetProcAddress(string.toStringz(funcName));
            return (*ptr !is null);
        }
    }
}

void initialize_compressed_texture_extension()
{
    version(useDerelict) {
        if (!ARBTextureCompression.load("GL_ARB_texture_compression"))
            throw new Exception("Unable to initialize texture compression extension");
    }
    else {
        if(!glBindExtFunc(cast(void**)&glCompressedTexImage3DARB, "glCompressedTexImage3DARB"))
            return false;
        if(!glBindExtFunc(cast(void**)&glCompressedTexImage2DARB, "glCompressedTexImage2DARB"))
            return false;
        if(!glBindExtFunc(cast(void**)&glCompressedTexImage1DARB, "glCompressedTexImage1DARB"))
            return false;
        if(!glBindExtFunc(cast(void**)&glCompressedTexSubImage3DARB, "glCompressedTexSubImage3DARB"))
            return false;
        if(!glBindExtFunc(cast(void**)&glCompressedTexSubImage2DARB, "glCompressedTexSubImage2DARB"))
            return false;
        if(!glBindExtFunc(cast(void**)&glCompressedTexSubImage1DARB, "glCompressedTexSubImage1DARB"))
            return false;
        if(!glBindExtFunc(cast(void**)&glGetCompressedTexImageARB, "glGetCompressedTexImageARB"))
            return false;
    }
}


All the extra code for the non-derelict case basically just does exactly what derelict's ARBTextureCompression.load function does, but modified to use schooner's imports.

--bb
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Schooner All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group