OpenGL绘图在for循环中呈正方形

时间:2011-10-25 00:18:10

标签: opengl colors

我正在尝试绘制图片中的内容。所以我可以绘制随机彩色方块,但是我无法让for循环在图像中绘制方块。 enter image description here

代码:

for (int i =0; i < image.width; i = i+5) {
    for (int j = 0; j < image.height; j = j+5) {

        //will this for loop give me what's in the image?
        //want to incorporate the code below in here. Modifications?
        glPushMatrix();
        glTranslatef(i, j, 0);
        glColor3ub( rand()%255, rand()%255, rand()%255 );
        glBegin(GL_QUADS);
        glVertex2i(0,0);
        glVertex2i(1,0);
        glVertex2i(1,1);
        glVertex2i(0,1);
        glEnd();
        glPopMatrix();
    }
}

1 个答案:

答案 0 :(得分:3)

您甚至没有在循环体中使用ij。尝试用xposypos替换那些(无论那些是什么)。