我是OpenGL的新手,在网上做作业。我的第一个任务是用一个代码填充平底锅:旋转,缩放,平移,透视,左/右,上/下。我做到了,但遇到了下一个任务:设置转换。你能给我举个例子或一些链接吗?任何帮助都会感激的。
for (int i = 0 ; i < numobjects ; i++) {
object* obj = &(objects[i]);
// Set up the object transformations
// And pass in the appropriate material properties
// Again glUniform() related functions will be useful
// Actually draw the object
// We provide the actual glut drawing functions for you.
// Remember that obj->type is notation for accessing struct fields
if (obj->type == cube) {
glutSolidCube(obj->size);
}
else if (obj->type == sphere) {
const int tessel = 20;
glutSolidSphere(obj->size, tessel, tessel);
}
else if (obj->type == teapot) {
glutSolidTeapot(obj->size);
}
}const int maxobjects = 10 ;
EXTERN int numobjects ;
EXTERN struct object {
shape type ;
GLfloat size ;
GLfloat ambient[4] ;
GLfloat diffuse[4] ;
GLfloat specular[4] ;
GLfloat emission[4] ;
GLfloat shininess ;
mat4 transform ;
} objects[maxobjects];发布于 2015-08-31 11:18:15
现代OpenGL中的变换是通过在着色器中使用均匀矩阵来完成的。基本上,您必须查询转换变量(glGetUniformLocation)的统一位置,然后使用glUniformMatrix4fv将obj->transform成员传递到这个位置。
对于具体的参数,工作流基本上是相同的,但是有一个不同的glUniform*调用,它适合这种类型。
https://stackoverflow.com/questions/32308833
复制相似问题