我不完全理解在GPU上访问纹理数据的方式.如果可能的话 - 有人能解释一下吗?
当纹理单元的数量有限时,这是否会限制我可以使用生成的纹理数量glGenTextures()并使用上传到GPU glTexImage2D()?或者它只限制可以绑定的纹理单元的数量glBindTexture()?
我真正想做的是能够将我的所有纹理上传到GPU - 即使有超过可用纹理单元的数量.当需要纹理时,我只需使用它将其绑定到纹理单元glBindTexture().这可能吗?
我在OpenGL中遇到问题让我的对象(一个行星)相对于当前的相机旋转旋转.它似乎首先工作,但在旋转一点后,旋转不再正确/相对于相机.
我正在计算屏幕上mouseX和mouseY移动的增量(差异).旋转存储在称为"planetRotation"的Vector3D中.
这是我的代码来计算相对于planetRotation的旋转:
Vector3D rotateAmount;
rotateAmount.x = deltaY;
rotateAmount.y = deltaX;
rotateAmount.z = 0.0;
glPushMatrix();
glLoadIdentity();
glRotatef(-planetRotation.z, 0.0, 0.0, 1.0);
glRotatef(-planetRotation.y, 0.0, 1.0, 0.0);
glRotatef(-planetRotation.x, 1.0, 0.0, 0.0);
GLfloat rotMatrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, rotMatrix);
glPopMatrix();
Vector3D transformedRot = vectorMultiplyWithMatrix(rotateAmount, rotMatrix);
planetRotation = vectorAdd(planetRotation, transformedRot);
Run Code Online (Sandbox Code Playgroud)
理论上 - 它的作用是在'rotateAmount'变量中设置一个旋转.然后通过将此向量与逆模型变换矩阵(rotMatrix)相乘,将其转换为模型空间.
然后将该变换后的旋转添加到当前旋转.
要渲染这是正在设置的转换:
glPushMatrix();
glRotatef(planetRotation.x, 1.0, 0.0, 0.0);
glRotatef(planetRotation.y, 0.0, 1.0, 0.0);
glRotatef(planetRotation.z, 0.0, 0.0, 1.0);
//render stuff here
glPopMatrix();
Run Code Online (Sandbox Code Playgroud)
相机有点摆动,我试图执行的旋转,似乎与当前的变换无关.
我究竟做错了什么?
我正在尝试使用在OpenGL ES 2.0中工作的立方体贴图进行反射贴图.我不确定我是否正确计算反射方向以传递到片段着色器中的samplerCube.
首先,我有Projection,Model和View矩阵以及一个组合的ModelView矩阵.这是我在GLSL中的顶点着色器的代码:
attribute vec4 Position;
attribute vec3 Normal;
uniform mat4 Projection;
uniform mat4 ModelView;
uniform mat3 Model;
uniform mat4 ModelViewProjectionMatrix;
uniform vec3 EyePosition;
varying vec3 ReflectDir;
void main()
{
gl_Position = Projection * ModelView * Position;
mediump vec3 EyeDir = normalize(Position.xyz - EyePosition);
// Reflect eye direction by normal, and transform to world space
ReflectDir = Model * reflect(EyeDir, Normal);
}
Run Code Online (Sandbox Code Playgroud)
我的假设是EyeDirection必须在对象空间中.(正确?)如何在对象空间中获取EyePosition?我是否只是通过逆ModelView矩阵变换摄像机位置(即总是在OpenGL中的{0,0,0}?)?
我试过这个但是我的片段着色器将所有颜色都着色,好像ReflectDir不正确.
有没有人有一个在Xcode中工作的OpenGL ES 2.0反射映射(带有samplerCube)的工作示例?