C++ 如何在使用Pi上的OpenGL ES绘制到屏幕之前旋转纹理

C++ 如何在使用Pi上的OpenGL ES绘制到屏幕之前旋转纹理,c++,c,opengl-es,raspberry-pi,C++,C,Opengl Es,Raspberry Pi,我最近才知道Raspberry Pi的GPU只支持OpenGL ES。 我有一个任务要完成,问题是,每当我搜索OpenGL ES时,我都会得到基于Android和IOS的结果 谢天谢地,我只有一个小问题。我偶然发现了simple2d库,它抽象了OpenGL ES与pi上的Video core IV GPU接口。 它是一个开源库,似乎不支持旋转纹理。这是我唯一想要的功能,以便清除所有障碍。这是对DrawTextures的调用。我将非常感谢在这个问题上帮助我的任何人 static void S2D_

我最近才知道Raspberry Pi的GPU只支持OpenGL ES。 我有一个任务要完成,问题是,每当我搜索OpenGL ES时,我都会得到基于Android和IOS的结果

谢天谢地,我只有一个小问题。我偶然发现了simple2d库,它抽象了OpenGL ES与pi上的Video core IV GPU接口。 它是一个开源库,似乎不支持旋转纹理。这是我唯一想要的功能,以便清除所有障碍。这是对DrawTextures的调用。我将非常感谢在这个问题上帮助我的任何人

static void S2D_GLES_DrawTexture(int x, int y, int w, int h,
                                 GLfloat r, GLfloat g, GLfloat b, GLfloat a,
                                 GLfloat tx1, GLfloat ty1, GLfloat tx2, GLfloat ty2,
                                 GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4,
                                 GLuint texture_id) {

  GLfloat vertices[] =
  //  x, y coords      | x, y texture coords
    { x,     y,     0.f, tx1, ty1,
      x + w, y,     0.f, tx2, ty2,
      x + w, y + h, 0.f, tx3, ty3,
      x,     y + h, 0.f, tx4, ty4 };

  GLfloat colors[] =
    { r, g, b, a,
      r, g, b, a,
      r, g, b, a,
      r, g, b, a };

  glUseProgram(texShaderProgram);

  // Load the vertex position
  glVertexAttribPointer(texPositionLocation, 3, GL_FLOAT, GL_FALSE,
                        5 * sizeof(GLfloat), vertices);
  glEnableVertexAttribArray(texPositionLocation);

  // Load the colors
  glVertexAttribPointer(texColorLocation, 4, GL_FLOAT, GL_FALSE, 0, colors);
  glEnableVertexAttribArray(texColorLocation);

  // Load the texture coordinate
  glVertexAttribPointer(texCoordLocation, 2, GL_FLOAT, GL_FALSE,
                        5 * sizeof(GLfloat), &vertices[3]);
  glEnableVertexAttribArray(texCoordLocation);

  // Bind the texture
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, texture_id);

  // Set the sampler texture unit to 0
  glUniform1i(samplerLocation, 0);

  glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
}
我的任务是修改上述函数,使其接受附加的旋转参数,以便在绘制纹理之前能够旋转它


我知道OpenGL,我很确定调用Rotatef不会有什么帮助。如果有人能告诉我如何在OpenGL ES for Pi中执行此操作,我将非常高兴。

您必须设置旋转矩阵。根据需要,在顶点着色器中通过旋转矩阵变换顶点坐标或纹理坐标

创建一个顶点着色器,如下所示:

attribute vec3 texPosition;
....

uniform mat4 u_rotateMat44;

void main()
{
    ....

    vec4 rotPos = u_rotateMat44 * vec4(texPosition, 1.0);
    gl_Position = rotPos;
}
#include <math.h> // sin, cos
或者这个:

attribute vec2 texCoord;
....

varying vec2 outTexCoord:

uniform mat4 u_rotateMat44;

void main()
{
    ....

    vec4 rotCoord = u_rotateMat44 * vec4(texCoord, 0.0, 1.0);
    outTexCoord   = rotCoord.st;

    ....
}
旋转矩阵可以如下设置:

attribute vec3 texPosition;
....

uniform mat4 u_rotateMat44;

void main()
{
    ....

    vec4 rotPos = u_rotateMat44 * vec4(texPosition, 1.0);
    gl_Position = rotPos;
}
#include <math.h> // sin, cos
通过以下方式设置制服:


这其实是我的错,我应该在这个问题上加上“c”的标签。我可以使用C++,但我想我们的团队希望避免…因为我们将把它用于luajit ffi。我将与我的团队澄清我们是否能够做到这一点。非常感谢你的回答。如果我没有得到不依赖C++标题的AOOTR,我会接受这个答案。托马斯好,但是这会如何影响我对你问题的回答?注意,带有GLM库的零件是可选的。你所需要的只是数组
float rotMat[16]
,顺便问一下,这个冒名顶替者是谁,要求编辑答案并代表我回答?虽然我们的名字是一样的,但在我们的个人资料图片中有差异,等等,“我是谁,我是谁”