OpenGL+GLUT没有填充最左边的多边形
OpenGL+GLUT Not filling Topmost-Leftmost Polygon?
我遇到了一个奇怪的OpenGL Bug。OpenGL对我来说很新,但我们被要求在我的人工智能课上使用它(因为老师是真正的图形学教授)。
无论哪种方式,都发生了:http://img818.imageshack.us/img818/422/reversiothello.png
它只发生在最上面,最左边的多边形。换句话说,它先找到左边最远的多边形,然后再找到上面最远的多边形,然后对它进行处理。(目前没有任何东西可以从板上擦除多边形)。
我的显示功能是:
void display_func(void)
{
glClearColor(0.0, 0.45, 0.0, 1.0); // Background Color (Forest Green :3)
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
draw_board();
glFlush();
glutSwapBuffers();
};
我的draw_board函数是:
void draw_board()
{
int size = 8;
int stepX = WINDOW_XS / size;
int stepY = WINDOW_YS / size;
glColor3f(0.0,0.0,0.0); // line color black
glBegin(GL_LINES);
// Draw Columns
for(int i = 0;i <= WINDOW_XS;i += stepX)
{
glVertex2i(i,0);
glVertex2i(i, WINDOW_YS);
}
// Draw Rows
for(int j = 0;j <= WINDOW_YS;j += stepY)
{
glVertex2i(0, j);
glVertex2i(WINDOW_XS, j);
}
// Draw Circles
for(int i = 0;i < 8;++i)
{
for(int j = 0;j < 8;++j)
{
if(engine->getOnBoard(i,j) == Reversi::PIECE_NONE) continue;
if(engine->getOnBoard(i,j) == Reversi::PIECE_WHITE)
glColor3f(1.0,1.0,1.0);
if(engine->getOnBoard(i,j) == Reversi::PIECE_BLACK)
glColor3f(0.0,0.0,0.0);
int drawX = ((i+1)*64)-32;
int drawY = 512-((j+1)*64)+32;
gl_drawCircle(drawX,drawY,30);
}
}
glEnd();
};
我的鼠标功能如下:
void mouse_func(int button, int state, int x, int y)
{
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN && x < WINDOW_XS)
{
// row and column index
x = (int)( x / (WINDOW_XS/8) );
y = (int)( y / (WINDOW_YS/8) );
std::cout << "Attempting to make a move at " << x << "," << y << std::endl;
if(engine->makeMove(x,y))
{
glutPostRedisplay();
}
}
};
我的gl_drawCircle函数是这样的
void gl_drawCircle(float x, float y, float r)
{
// http://stackoverflow.com/questions/5094992/c-drawing-a-2d-circle-in-opengl/5095188#5095188
glBegin( GL_POLYGON );
float t;
int n;
for(t = 0,n = 0; n <= 90; ++n, t = float(n)/90.f ) // increment by a fraction of the maximum
{
glVertex2f( x + sin( t * 2 * PI ) * r, y + cos( t * 2 * PI ) * r );
}
glEnd();
}
有谁能帮帮我吗? 我能找到的唯一值得给出答案的错误是您的draw_board
函数不能正确使用glBegin
和glEnd
语句。你必须在调用gl_drawCircle
之前使用glEnd
语句,否则你会得到一个讨厌的行为。
编辑:你的第一个圆圈是用线条绘制的,因为glBegin
被忽略了(因为你在glBegin
上下文中)。所有其他圈都完成得很好,因为在再次调用glBegin
之前执行了glEnd
。第一个绘制的圆是最左边,最上面的圆
在绘制行之后需要调用glEnd。当你不调用glEnd时,OpenGL忽略你的调用glBegin( GL_POLYGON );
,并假设你仍然想画线。
所以只是添加glEnd ();
画完行后应该解决它
相关文章:
- 如何创建一个QTableWidgetItem,用长文本右对齐,左边有省略号
- 计算缩放多边形的比例,得到给定的多边形面积
- 将QGraphicsItem的移动区域限制在多边形区域内
- 重新排列单线以形成闭合多边形?
- 提升几何体:C++并集多个多边形
- 在 QT C++中绘制/操作多边形
- Maya API C++:从多边形获取材质
- 添加带有提升的多边形::p奥利贡不编译?
- 使用 C++在 OpenGL 中对 3D 多边形进行纹理处理
- 使用 C++在 OpenGL 中移动自动旋转的 3D 多边形
- 如何使用增强::几何计算多边形的旋转固体体积?
- 从拉伸多边形构建多面体
- 使用提升几何缓冲区缩放多边形时的冗余折点
- cgal多边形网格中的tet网格密度分级
- 如何绘制具有随机顶点数量的多边形并旋转它们
- 多边形裁剪 - 一点点详细说明
- 使用裁剪器库在线和多边形之间相交
- 平移 CGAL 多边形,而无需循环穿过折点
- 无法正确改变窗口中多边形的形状
- OpenGL+GLUT没有填充最左边的多边形