此代码必须绘制两条正弦线。这里有两条常用线路通过着色器转换为正弦线。我有一个任务是旋转其中一个(例如,45度或90度),怎么做?
void CMyApplication::OnDraw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgramObjectARB(m_program);
glUniform1fARB(m_amplitudeUniformLocation, 0.3f);
glUniform1fARB(m_phaseUniformLocation, m_phase);
glUniform1fARB(m_frequencyUniformLocation, M_PI);
glUniform1fARB(m_colourUniformLocation, 0.0f);
//glUniform1fARB(m_rotateUniformLocation, true);
//glLoadIdentity();
//glRotatef(90.0f, 0.0f, 0.0f, 0.0f);
glBegin(GL_LINE_STRIP);
{
for (float x = -1; x <= 1.05; x += 0.01)
{
glVertex3f(x, 0, 0);
glColor3f(0, 0.5, -0.8);
}
}
glEnd();
//glLoadIdentity();
//glRotatef(-90.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glUniform1fARB(m_phaseUniformLocation, m_phase - 0.5);
glUniform1fARB(m_colourUniformLocation, 0.5f);
//glUniform1fARB(m_rotateUniformLocation, false);
glBegin(GL_LINE_STRIP);
{
for (float x = -1; x <= 1.05; x += 0.01)
{
glVertex3f(x, -0.5, 0);
glColor3f(0, -0.5, 0.8);
}
}
glEnd();
__glewMatrixRotatefEXT(GL_MODELVIEW, 45, 0, 0, 1); //THIS STRING HAS BEEN RESOLVED //MY PROBLEM
glUseProgramObjectARB(NULL);
glutSwapBuffers();
}
下面的着色器:
uniform float phase;
uniform float amplitude;
uniform float frequency;
void main()
{
vec4 v = gl_Vertex;
v.y += amplitude * sin(frequency * v.x + phase);
gl_Position = gl_ModelViewProjectionMatrix * v;
gl_FrontColor = gl_Color;
}
答案 0 :(得分:0)
因为您正在使用着色器,所以glRotatef将无法按预期运行。使用着色器启用可编程管道后,将关闭固定功能管道转换调用。所以从本质上讲,除非你已经在顶点着色器中使用了正确的矩阵,否则glRotatef在此处不执行任何操作。
要获得您想要的结果,您需要生成适当的旋转矩阵,将其传递到均匀变量中的顶点着色器,然后在应用WVP变换之前将其乘以创建的线。最终结果应该为您提供旋转线。