【问题标题】:Loop to save vertices in openGL [closed]循环以在openGL中保存顶点[关闭]
【发布时间】:2015-11-20 14:52:39
【问题描述】:

我有一个带有四边形的网格,我想将所有顶点保存在一个数组中。我写了这段代码:

int counter=0;
int i = 0;
for(i=0; i<=600; i+=40){
    verticePosition[counter] = i;
    verticePosition[counter+1] = i;
    verticePosition[counter+2] = i+40;
    verticePosition[counter+3] = i;
    verticePosition[counter+4] = i;
    verticePosition[counter+5] = i+40;
    verticePosition[counter+6] = i+40;
    verticePosition[counter+7] = i+40;
    counter += 8;
}

我想在表格中保存四到四个顶点,然后我调用一个函数来用不同的颜色填充每个四边形,但我在这个 for 循环中遇到错误:

prog.c:13:1: error: expected identifier or ‘(’ before ‘for’
 for(xpos=0; xpox<=600; xpos+=40){
 ^

还有另一个错误:

prog.c:13:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<=’ token
 for(xpos=0; xpox<=600; xpos+=40){
             ^

我找不到我的循环有什么问题。

【问题讨论】:

  • 您应该围绕失败的代码提供更多代码,因为问题可能来自前面的代码行。顺便说一句,在第二个 for 中,xpox 应该是 xpos?
  • 我用 i 更改了所有的 xpos,但我得到了同样的错误
  • dimitris,请向我们展示更多关于 prog.c 的代码,以便我们为您提供帮助。
  • 给定代码中的变量与错误中的变量不匹配。发布导致错误的实际代码。
  • @dimitrisdimas1313 你是否有机会在函数之外拥有所有这些代码?

标签: c++ c opengl glut


【解决方案1】:

变量xpos被使用但未声明,必须声明并初始化:

for (int xpos = 0; xpos <= 600;  xpos += 40) {

或者在循环之前声明:

int xpos;
for (xpos = 0; xpos <= 600;  xpos += 40) {

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-15
    • 1970-01-01
    • 2017-06-11
    • 1970-01-01
    • 1970-01-01
    • 2014-06-01
    • 2021-10-15
    • 2021-09-16
    相关资源
    最近更新 更多