Re: [Vala] Using OpenGL 3.0 from Vala



On Tue, 2010-02-23 at 16:26 -0800, Tristin Celestin wrote:
If you just need a couple functions, you can just declare
them as
"extern" in your vala files. otherwise it's better to write
a vapi.

Could I see an example of using extern this way?

[CCode (cname = "fputs", cheader_filename = "stdio.h")]
public extern int fputs (string str, GLib.FileStream fd);


...

I tried starting to write a .vapi that would cover glext.
I changed my mind about GL3 and instead decided to write to GL2, believing
there would be a better chance it'd be on the target machine.

After some time, I got somewhere in terms of covering what is in glext.h,
but then I had all these other questions...

1. I didn't know how to translate the preprocessing guards for particular
versions of the api, like #ifndef GL_VERSION_2_0.

Generally Vala bindings follow the policy of binding everything, and
people use the version given by the pkg-config file to figure out what
is supported in their build system.

You can bind something like "#define GL_VERSION 2" as a const int in
your vapi, which will give you access to it from code, but you can't use
it for conditional compilation.

It's worth noting that if you use something that is ifdef'd out in C
from Vala via a vapi, you should get an error while compiling. However,
you're using extern, vala will generate a prototype and you will not see
a compile-time error.


2. Because I couldn't do the former, I wasn't sure how I would be able to
do compile time checks to see if an extension was supported

For conditional compilation, you'll need to get the relevant information
to Vala's preprocesor (probably via some work with autotools). See
http://live.gnome.org/Vala/FAQ#Does_Vala_have_a_preprocessor.3F


3. Can I perform dlopen and dlsym from Vala? If not, how else would I
dynamically load libraries and check to see if a particular extension
exists during runtime

The posix vapi wraps dlopen and dlsym, so that is a possibility. It is
probably a better idea to use GModule, though. See

http://valadoc.org/gmodule-2.0/index.html
and
http://library.gnome.org/devel/glib/stable/glib-Dynamic-Loading-of-Modules.html


4. If I wanted to avoid figuring out how to do 2 or 3 myself, I could
always use GLew or GLee, except...I end up at my original problem of there not being bindings for what I 
want...


Attached is the glext.vapi file I started writing. I may not use Vala for my project afterall, but perhaps 
this will help someone else out.


--- On Mon, 2/22/10, Abderrahim Kitouni <a kitouni gmail com> wrote:

From: Abderrahim Kitouni <a kitouni gmail com>
Subject: Re: [Vala] Using OpenGL 3.0 from Vala
To: "Tristin Celestin" <tristin_celestin yahoo com>
Cc: Vala-list gnome org
Date: Monday, February 22, 2010, 9:00 AM
Hi,

2010/2/22 Tristin Celestin <tristin_celestin yahoo com>:
I am trying to use OpenGL 3.0 from Vala, but I notice
that only up to OpenGL 1.3 is defined in the .vapi
file. The methods relevant to me are defined in
GL/glext.h. How would I access the functions
declared there?

If you just need a couple functions, you can just declare
them as
"extern" in your vala files. otherwise it's better to write
a vapi.

Is it enough to just write a .vapi file for myself
referencing the necessary functions, or should I
modify gl.vapi? glext.h had a lot of methods, and I am
not going to be able to cover all of them
myself.

You don't need to bind all the methods, you can just bind
the methods
you need. I think it's fine to add to gl.vapi directly
(maybe in an
#if GL_3.0 or something), but GL bindings aren't included
with vala,
so it may be a good idea to contact the maintainer.

HTH,
Abderrahim



      
_______________________________________________ Vala-list mailing list Vala-list gnome org 
http://mail.gnome.org/mailman/listinfo/vala-list





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]