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时遇到了麻烦。
第一部分很简单:
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);
我试过了:
GL.GLuint[] texture = {};
glGenTextures (1, texture);我得到了:
.vala:46.27-46.33: error: Argument 2: Cannot pass value to reference or output parameter我也试过了:
GL.GLuint[] texture = {};
glGenTextures (1, out texture);我得到了:
ERROR:valaccodearraymodule.c:1183:vala_ccode_array_module_real_get_array_length_cvalue: assertion failed: (_tmp48_)我试过了:
glGenTextures (1, &texture);我得到了:
.vala:46.27-46.34: error: Argument 2: Cannot pass value to reference or output parameter我试过很多其他类似的东西,有什么想法吗?
发布于 2012-09-18 07:37:21
听起来绑定是错误的。基于the glGenTextures man page,Vala绑定应该类似于:
public static void glGenTextures ([CCode (array_length_pos = 0.9)] GL.GLuint[] textures);正确的命名方式应该是这样:
GL.GLuint[] textures = new GL.GLuint[1];
glGenTextures (textures);
// your texture is textures[0]当然,对于你只想要一个纹理的用例来说,这并不是很好,但这并不是什么大问题。问题是你必须在堆上分配一个数组...我不怀疑这是一个性能敏感的代码领域,所以我可能不会费心,但你总是可以创建一个替代版本:
[CCode (cname = "glGenTextures")]
public static void glGenTexture (GL.GLsizei n, out GL.GLuint texture);然后,您可以使用
GL.GLuint texture;
glGenTexture (1, out texture);尽管您只能使用此版本生成单个纹理,但您仍然必须手动传递第一个参数。
https://stackoverflow.com/questions/12467843
复制相似问题