在64位Ubuntu 14.04 LTS上,我正在尝试编译一个使用过剩的简单OpenGL程序.我在main中执行任何代码行之前得到了一个Segmentation Fault(SIGSEV); 即使是在一个非常简单的测试计划上.什么可能导致这个?
我的命令行:
g ++ -Wall -g main.cpp -lglut -lGL -lGLU -o main
我的简单测试案例:
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <string>
#include <cstdio>
int main(int argc, char** argv){
printf("Started\n");
std::string dummy = "hello";
glutInit(&argc, argv);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我运行程序时,main开头的printf不会在segfault之前执行.在GDB下,我在segfault之后得到了这个回溯
#0 0x0000000000000000 in ?? ()
#1 0x00007ffff3488291 in init () at dlerror.c:177
#2 0x00007ffff34886d7 in _dlerror_run (operate=operate@entry=0x7ffff3488130 <dlsym_doit>, args=args@entry=0x7fffffffddf0) at dlerror.c:129
#3 0x00007ffff3488198 in __dlsym (handle=<optimized out>, name=<optimized out>) at dlsym.c:70
#4 0x00007ffff702628e in ?? () from …Run Code Online (Sandbox Code Playgroud) 我似乎无法在我的Android NDK项目中包含glu.h.
我正在尝试将现有的C++代码移植到NDK,它在一些地方使用glu(特别是gluErrorString).
OpenGLES没有胶水吗?
我有可以使用的端口吗?
如果不是,我可以删除对类似gluPerspective等事情的调用,但我该怎么办gluErrorString?
我尝试编译一些"hello world"过剩申请:
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
GLint Width = 512, Height = 512;
const int CubeSize = 200;
void Display(void)
{
int left, right, top, bottom;
left = (Width - CubeSize) / 2;
right = left + CubeSize;
bottom = (Height - CubeSize) / 2;
top = bottom + CubeSize;
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glColor3ub(255,0,0);
glBegin(GL_QUADS);
glVertex2f(left,bottom);
glVertex2f(left,top);
glVertex2f(right,top);
glVertex2f(right,bottom);
glEnd();
glFinish();
}
void Reshape(GLint w, GLint h)
{
Width = w;
Height = h; …Run Code Online (Sandbox Code Playgroud) 我们试图在无头的GNU/linux服务器上使用GLU的tesselation函数.我们想使用PyOpenGL,但问题是它在调用gluNewTess时出现崩溃(分段错误)
gdb backtrace说它在glGetError中,这让我觉得GLU tesselation需要GL上下文?或者它只是PyOpenGL中的一些复杂性?
我试图找到一些关于如何在无头(和虚拟化)机器上初始化GL上下文的信息,没有运气.有关这些主题的任何信息表示赞赏.
我想以下面的方式绘制一系列连接线(GL_LINE_STRIP).

我试过自己编码,但没有得到理想的结果,所以我来到这里,帮我找出错在哪里.这里我只给出我的draw()函数.
glBegin(GL_LINE_STRIP);
glVertex2f(-4.00, 0.00);
glVertex2f(-3.00, 2.00);
glVertex2f(-2.00, 0.00);
glVertex2f(-1.00, 2.00);
glVertex2f(0.0, 0.00);
glVertex2f(1.00, 2.00);
glVertex2f(2.00, 0.00);
glVertex2f(3.00, 2.00);
glVertex2f(4.00, 0.00);
glEnd();
Run Code Online (Sandbox Code Playgroud) 经过两个小时的谷歌搜索(这里,这里,这里,这里,这里,以及其他一些我不想找到的东西),我以为我终于学会了将3D坐标转换为2D坐标的理论.但它没有用.我们的想法是将船舶的3D坐标转换为屏幕上的2D坐标,以呈现控制该船舶的玩家的用户名.
但是,文本呈现在错误的位置:

文本是"Test || 2DXCoordinate || 2DZCoordinate".
这是我的getScreenCoords()- 将3D坐标转换为2D.
public static int[] getScreenCoords(double x, double y, double z) {
FloatBuffer screenCoords = BufferUtils.createFloatBuffer(4);
IntBuffer viewport = BufferUtils.createIntBuffer(16);
FloatBuffer modelView = BufferUtils.createFloatBuffer(16);
FloatBuffer projection = BufferUtils.createFloatBuffer(16);
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelView);
GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection);
GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
boolean result = GLU.gluProject((float) x, (float) y, (float) z, modelView, projection, viewport, screenCoords);
if (result) {
return new int[] { (int) screenCoords.get(0), (int) screenCoords.get(1) };
}
return …Run Code Online (Sandbox Code Playgroud) 编辑:这是一个库bug.我把它报告给HOpenGL邮件列表.
我使用9点矩形方法将圆/椭圆表示为NURBS.
要点是p1, p2, ..., p9,p9 = p1.它们如图所示:
y2 | p2 p3 p4
y1 | p1 p5
y0 | p8 p7 p6
-------------
| x0 x1 x2
x1 = (x0 + x2) / 2
y1 = (y0 + y2) / 2
Run Code Online (Sandbox Code Playgroud)
即p1 = (x0, y1), p2 = (x0, y2)等等.
重量是:
1中间点(p1,p3,p5,p7)sqrt(0.5)角点(p2,p4,p6,p8)我使用两种方法将权重应用为齐次坐标:
(x,y)重量w变成了Vertex4 (w*x) (w*y) 0 w我正在研究计算机图形学课程的交互式场景.我已经设置了一个生成彩色立方体的程序,让我用键盘旋转它们.然而,他们被我相机的近夹片平面切开了:

我试过使用gluPerspective,但OpenGL文档没有给出任何使用它的例子.我发现它在网上的示例程序中使用,并且半复制了它们的代码:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective( 65, 1, 0.01, 100 );
glMatrixMode(GL_MODELVIEW);
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
更新:正如下面的评论中所建议的,我尝试使用glFrustum代替,使用以下代码:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum( -0.5, 0.5, -0.5, 0.5, 0.1, 100 );
glMatrixMode(GL_MODELVIEW);
Run Code Online (Sandbox Code Playgroud)
再一次,没有区别.我没有正确地推动生成的矩阵或什么?
我知道有用于绘制矩形的内置函数(glRecti()例如),并且认为圆形也是一个非常基本的用法。
有没有这样的内置函数可以画圆?或者我应该总是自己实施?