OpenGL在for循环中绘制正方形
我正在尝试画出图中的内容。所以我可以绘制随机彩色方块,但我很难让 for 循环在图案中绘制方块,如图所示。
代码:
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();
}
}
I am trying to draw what is in the picture. So I can draw the random colored square but I am having trouble getting the for loop to draw squares in the patter like the image.
Code:
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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您甚至没有在循环体中使用
i
和j
。尝试用它们替换 xpos 和 ypos(无论它们是什么)。You’re not even using
i
andj
in your loop body. Try substituting those forxpos
andypos
(whatever those are).