Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 指定我自己的openGL坐标_Cocoa_Opengl - Fatal编程技术网

Cocoa 指定我自己的openGL坐标

Cocoa 指定我自己的openGL坐标,cocoa,opengl,Cocoa,Opengl,我有一个NSOpenGLView,其默认坐标设置为x方向从-1到+1的等距网格,y方向从-1到+1的等距网格。但是,我想将我的opengl视图设置为其坐标范围为x方向的-width/2到+width/2,而不是y方向的-height/2到+height/2。我尝试使用glOrtho(-w/2,w/2,-h/2,h/2,0,1)设置投影但我似乎没有成功,因为当我画三角形时,我的视图是空白的。有人能解释一下我的情况吗?我终于把它记下来了。以下是我的工作解决方案示例: - (void)drawRect

我有一个
NSOpenGLView
,其默认坐标设置为x方向从-1到+1的等距网格,y方向从-1到+1的等距网格。但是,我想将我的opengl视图设置为其坐标范围为x方向的
-width/2到+width/2
,而不是y方向的
-height/2到+height/2
。我尝试使用
glOrtho(-w/2,w/2,-h/2,h/2,0,1)设置投影但我似乎没有成功,因为当我画三角形时,我的视图是空白的。有人能解释一下我的情况吗?

我终于把它记下来了。以下是我的工作解决方案示例:

- (void)drawRect:(NSRect)bounds
{
    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-_w / 2., _w / 2., -_h / 2., _h / 2.,  0., 1.);
    glMatrixMode(GL_MODELVIEW);

    // Draw something:
    glBegin(GL_QUADS);
    glVertexd(-100., -100.);
    glVertexd(-100., 100.);
    glVertexd(100., 100.);
    glVertexd(100, -100.); 
    glEnd();
}

用户1240679获得了很多荣誉:

您不能更改OpenGL坐标系(NDC)。但您可以缩放和/或将自己的“世界”坐标转换为NDC。然后放置相机,以便可以看到变换后的坐标。和正交/透视投影。如果你不理解这些概念,那么你需要一个好的教程。