首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设置对象转换、属性?

如何设置对象转换、属性?
EN

Stack Overflow用户
提问于 2015-08-31 10:09:42
回答 1查看 70关注 0票数 1

我是OpenGL的新手,在网上做作业。我的第一个任务是用一个代码填充平底锅:旋转,缩放,平移,透视,左/右,上/下。我做到了,但遇到了下一个任务:设置转换。你能给我举个例子或一些链接吗?任何帮助都会感激的。

代码语言:javascript
复制
  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); 
    }

  }
代码语言:javascript
复制
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];
EN

回答 1

Stack Overflow用户

发布于 2015-08-31 11:18:15

现代OpenGL中的变换是通过在着色器中使用均匀矩阵来完成的。基本上,您必须查询转换变量(glGetUniformLocation)的统一位置,然后使用glUniformMatrix4fvobj->transform成员传递到这个位置。

对于具体的参数,工作流基本上是相同的,但是有一个不同的glUniform*调用,它适合这种类型。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32308833

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档