OpenGL圆绘制得到一个椭圆
OpenGL circle drawing getting an ellipse
我试图在opengl中画一个圆,但我似乎无法得到正确的坐标,所以无论我使用什么方法,我总是得到一个省略号。当前代码如下:
void Ball::Render() {
float center_position_x = _body->GetWorldCenter().x;
float center_position_y = _body->GetWorldCenter().y;
float radius = static_cast<b2CircleShape*>(_body->GetFixtureList()->GetShape())->m_radius;
glBegin(GL_LINE_STRIP);
for(float angle = 0; angle <= 360; ++angle) {
float angleInRadians = glm::radians(angle);
float x = glm::cos(angleInRadians);
float y = glm::sin(angleInRadians);
glVertex3f(x,y,0);
}
glEnd();
}
(我知道代码应该在原点画圆,但即使这样它也不是一个完美的圆,如果我理解正确的话,应该在原点画一个半径=1的圆)
我使用的其他方法有:http://slabode.exofire.net/circle_draw.shtmlhttp://www.opengl.org/discussion_boards/showthread.php/167955-drawing-a-smooth-circle
这是我的OpenGL窗口设置代码(这是一个存根程序,所以我从硬编码值开始):gluOrtho2D(-10, 15, -10, 15);
使用gluOrtho2D(-WIDOWS_WIDTH, WIDOWS_WIDTH, -WINDOWS_HEIGHT, WINDOWS_HEIGHT);
顺便说一下,你们在2013年使用的是固定管道。有了顶点着色器,这就容易理解了。
由gluOrtho2d定义的2D投影矩阵的长宽比必须与你正在渲染的视口/窗口相同,否则你会注意到你正在渲染的数字失真。你可以使用上面的gluOrtho2d语句或者用其他方式写-
float = (float)WindowWidth/windowwheight;
gluOrtho2D(-1*ar, ar, -1, 1)
相关文章:
- 如何在 Gnuplot 中分别绘制 2 个文件数据?我有一个文件"sin.txt",另一个文件"cos.txt",我想将它们分别绘制在一个图表上
- 绘制一个对象,比较模具缓冲区的两个不同值
- 使用 glDrawElements 绘制一个 std::vector
- 我正在尝试创建一个 C++ 贪吃蛇游戏,但我似乎无法绘制第二个高度边框,我该如何解决这个问题?
- 如何在openGL C++中绘制一个空心圆
- 尝试绘制存储在数组中的矩形,但只出现一个矩形?
- Opencv,在图像中的对象周围绘制一个框
- OpenGL 2D游戏只绘制第二个精灵纹理而不是第一个
- 图层不会绘制另一个图层
- 绘制椭圆延迟并绘制另一个椭圆延迟
- OPENCV C .在for循环中在不同的图像像素上绘制一个圆圈(应在每个循环运行时将图像打开)
- 直接X 11:在屏幕上绘制一个简单的彩色矩形
- 使用 C++ 库 GLEW 在 openGl 中绘制一个红色三角形
- 在另一个线程中绘制 OpenGL
- 如何在 MFC 中围绕当前光标的位置绘制一个矩形
- SFML在另一个对象上方绘制对象
- 创建一个包含要绘制的项的类(seg-fault)
- 为什么我的 OpenGL 对象相对于最后一个绘制的对象绘制
- 如何保持一个绘制矩形在相同的地方,因为相机周围移动
- 是否有可能保存当前的视口,然后在OpenGL和c++中在下一个绘制周期中重新绘制保存的视口?