首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Vala OpenGL glGenTexture

Vala OpenGL glGenTexture
EN

Stack Overflow用户
提问于 2012-09-18 06:16:11
回答 1查看 597关注 0票数 0
代码语言:javascript
复制
colors = surface->format->BytesPerPixel;
if (colors == 4) {   // alpha
    if (surface->format->Rmask == 0x000000ff)
        texture_format = GL_RGBA;
    else
        texture_format = GL_BGRA;
} else {             // no alpha
    if (surface->format->Rmask == 0x000000ff)
        format = GL_RGB;
    else
        format = GL_BGR;
}

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture); 
glTexImage2D(GL_TEXTURE_2D, 0, colors, surface->w, surface->h, 0,
                    texture_format, GL_UNSIGNED_BYTE, surface->pixels);

我正在尝试将我在Stack Overflow上找到的代码转换为Vala。然而,我在使用glGenTextures时遇到了麻烦。

第一部分很简单:

代码语言:javascript
复制
    int texture_format;
    uchar colors = screen.format.BytesPerPixel;
    if (colors == 4) {
        if (screen.format.Rmask == 0x000000ff) {
            texture_format = GL_RGBA;
        } else {
            texture_format = GL_BGRA;
        }
    } else {
        if (screen.format.Rmask == 0x000000ff) {
            texture_format = GL_RGB;
        } else {
            texture_format = GL_BGR;
        }
    }

这部分,虽然,我不知道如何转换: glGenTextures(1,&texture);

我试过了:

代码语言:javascript
复制
    GL.GLuint[] texture = {};
    glGenTextures (1, texture);

我得到了:

代码语言:javascript
复制
.vala:46.27-46.33: error: Argument 2: Cannot pass value to reference or output parameter

我也试过了:

代码语言:javascript
复制
GL.GLuint[] texture = {};
glGenTextures (1, out texture);

我得到了:

代码语言:javascript
复制
ERROR:valaccodearraymodule.c:1183:vala_ccode_array_module_real_get_array_length_cvalue: assertion failed: (_tmp48_)

我试过了:

代码语言:javascript
复制
glGenTextures (1, &texture);

我得到了:

代码语言:javascript
复制
.vala:46.27-46.34: error: Argument 2: Cannot pass value to reference or output parameter

我试过很多其他类似的东西,有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-18 07:37:21

听起来绑定是错误的。基于the glGenTextures man page,Vala绑定应该类似于:

代码语言:javascript
复制
public static void glGenTextures ([CCode (array_length_pos = 0.9)] GL.GLuint[] textures);

正确的命名方式应该是这样:

代码语言:javascript
复制
GL.GLuint[] textures = new GL.GLuint[1];
glGenTextures (textures);
// your texture is textures[0]

当然,对于你只想要一个纹理的用例来说,这并不是很好,但这并不是什么大问题。问题是你必须在堆上分配一个数组...我不怀疑这是一个性能敏感的代码领域,所以我可能不会费心,但你总是可以创建一个替代版本:

代码语言:javascript
复制
[CCode (cname = "glGenTextures")]
public static void glGenTexture (GL.GLsizei n, out GL.GLuint texture);

然后,您可以使用

代码语言:javascript
复制
GL.GLuint texture;
glGenTexture (1, out texture);

尽管您只能使用此版本生成单个纹理,但您仍然必须手动传递第一个参数。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12467843

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档