English 中文(简体)
为什么删除 glColor3f 的呼叫会影响整个生成?
原标题:Why does removing one call to glColor3f affect the entire rendering?
  • 时间:2012-05-25 05:02:46
  •  标签:
  • opengl
  • lwjgl

因此,我代码的一个子集(在翻转循环中)是:

    for(int x=0;x<data.length;x++) 
        for(int y=0;y<data[0].length;y++) {

            float r = colorData[x][y][0], g = colorData[x][y][1], b = colorData[x][y][2];
            glGetError();
            glColor3f(r,g,b);
            int xCoord = x*100;
            int yCoord = y*100;
            int height = (int) Math.round(data[y][x]*25);

            glBegin(GL_QUADS);


                //Top
                glVertex3f(xCoord,yCoord,height);
                glVertex3f(xCoord+100,yCoord,height);
                glVertex3f(xCoord+100,yCoord+100,height);
                glVertex3f(xCoord,yCoord+100,height);
                //*/

                //Sides
                glColor3f(r/2,g/2,b/2);          
                glVertex3f(xCoord,yCoord,height);
                glVertex3f(xCoord,yCoord,0);
                glVertex3f(xCoord+100,yCoord,0);
                glVertex3f(xCoord+100,yCoord,height);

                glVertex3f(xCoord,yCoord+100,height);
                glVertex3f(xCoord+100,yCoord+100,height);
                glVertex3f(xCoord+100,yCoord+100,0);
                glVertex3f(xCoord,yCoord+100,0);

                glVertex3f(xCoord,yCoord+100,height);
                glVertex3f(xCoord,yCoord+100,0);
                glVertex3f(xCoord,yCoord,0);
                glVertex3f(xCoord,yCoord,height);

                glVertex3f(xCoord+100,yCoord+100,height);
                glVertex3f(xCoord+100,yCoord,height);
                glVertex3f(xCoord+100,yCoord,0);
                glVertex3f(xCoord+100,yCoord+100,0);

                //Bottom
                glColor3f(r/4,g/4,b/4);
                glVertex3f(xCoord,yCoord,0);
                glVertex3f(xCoord,yCoord+100,0);
                glVertex3f(xCoord+100,yCoord+100,0);
                glVertex3f(xCoord+100,yCoord,0);



            glEnd();
            int err =  glGetError();
            if(err != GL_NO_ERROR)
                 System.out.println("An error has occured: #"+err);
            glColor3f(1,0,0);
            glBegin(GL_LINES);
                //Top
                glVertex3f(xCoord,yCoord,height);
                glVertex3f(xCoord+100,yCoord,height);
                glVertex3f(xCoord+100,yCoord+100,height);
                glVertex3f(xCoord,yCoord+100,height);
            glEnd();                
        }

代码工作正确, 绘制了两维方格的盒子, 盒子的侧面比顶部暗一点。 (穷人的灯光)

好奇的是,我接到了致glColor3f的第一通电话,希望盒子顶部成为无色的,而两侧保持原样;然而,整个盒子的网格都变白了。为什么会这样呢?这是这个代码中的东西吗?还是我变环中的其他部分导致了这个?

(如果有区别,我正在使用 OpenGL1.1 的 LWJGL s Java 执行)

最佳回答

OpenGL 即时模式像这样工作( 假码)

glColor3f(r,g,b){
state.color.{r,g,b} = r,g,b;
}

glNormal(x,y,z){
state.normal.{x,y,z} = x,y,z;
}

/* and so on */

glVertex3f(x,y,z){
    send_vertex_to_rasterizer(state.color, state.normal, ..., {x,y,z})
}

I. e. OpenGL 记得您所设置的最后一种颜色, 并且它会适用于所有跟随顶点的顶点, 直到您将它修改为另一个颜色, 然后应用它 。

问题回答

暂无回答




相关问题
OpenGL 3D Selection

I am trying to create a 3D robot that should perform certain actions when certain body parts are clicked. I have successfully (sort of) implemented picking in that if you click on any x-plane part, it ...

CVDisplayLink instead of NSTimer

I have started to implement cvDisplayLink to drive the render loop instead of nstimer, as detailed in this technical note https://developer.apple.com/library/archive/qa/qa1385/_index.html Is it ...

Can the iPhone simulator handle PVR textures?

I have a really weird problem with PVR textures on the iPhone simulator- the framerate falls through the floor on the iPhone simulator, but on the iPhone itself it works just fine. Has anyone had any ...

Calculate fps (frames per second) for iphone app

I am using an opengl es iphone application. What is the most accurate way to calculate the frames per second of my application for performance tuning?

Java - Zoom / 3D Data Visualization Libraries

What are the best libraries/frameworks for doing 3D and/or Zoom interfaces in Java? I d like to be able to do some prototyping of creating new types of interfaces for navigating within data and ...

FLTK in Cygwin using Eclipse (Linking errors)

I have this assignment due that requires the usage of FLTK. The code is given to us and it should compile straight off of the bat, but I am having linking errors and do not know which other libraries ...

热门标签