简体   繁体   English

OpenGL似乎正在使用(过于激进)视锥剔除,而我看不到如何修改

[英]OpenGL appears to be using (far too aggressive) frustum culling which I can't see how to modify

I'm trying to get an OpenGL application working in c++. 我正在尝试让OpenGL应用程序在c ++中工作。 OpenGL appears to be culling far & near objects. OpenGL似乎正在淘汰远近的物体。

在此处输入图片说明

The screenshot should be a load of square tiles but the squares that are a certain distance too close or too far from the camera are not rendered. 屏幕截图应该是正方形瓷砖的负载,但是不会渲染距离相机太近或太远的正方形。 This means that only a narrow strip of the squares is actually rendered (between what I believe to be the near & far plane). 这意味着实际上仅渲染了一个狭窄的正方形带(在我认为是近端和远端平面之间)。

I'm not using frustum culling, the only culling I have enabled is back face culling. 我没有使用视锥剔除,我启用的唯一剔除是背面剔除。 Does OpenGL have some sort of frustum culling on by default? 默认情况下,OpenGL是否进行了某种类型的视锥剔除? Is there something that I need to enable using glEnable to get all of my triangles to actually render? 是否需要启用glEnable才能使所有三角形真正渲染? Enabling GL_DEPTH_TEST stops absolutely everything from rendering no matter if I call glFrustum(...) afterwards. 无论之后是否调用glFrustum(...),启用GL_DEPTH_TEST都会完全阻止渲染。

Thanks. 谢谢。

Somewhere in your code you should intialize a projectionMatrix: 在代码中的某个位置,您应该初始化一个projectionMatrix:

auto projectionMatrix = glm::mat4 perspective(fovy, aspect, zNear, zFar);

or 要么

auto projectionMatrix = gluPerspective(fovy, aspect, near, far); 

something like the line above. 就像上面的线一样。 The zNear and zFar specify the lower and farest boundaries of your frustrum. zNear和zFar指定您的平截头体的下边界和最远边界。 Thoose values will map your fragment position to [-1, +1]. 选择值会将您的片段位置映射到[-1,+1]。

Every fragment with a z == near will be mapped to -1. z == near每个片段都将映射为-1。 Everything with a depth less than near will be discarded. 深度小于近于一切的一切都将被丢弃。

Try to find thoose near and far parameters and change their values to something that fit your scene. 尝试查找较远和较近的参数,并将其值更改为适合您的场景的参数。 Avoid 0 as a near value, you can also try to move your camera to see some changes happening. 避免将0设为接近值,您也可以尝试移动相机以查看发生的变化。

Fixed. 固定。 Not sure why but it was only rendering pieces of triangle that had their world coordinates (as opposed to coordinates relative to the camera) between 1 and -1. 不知道为什么,但仅渲染其世界坐标(相对于相对于摄影机的坐标)在1到-1之间的三角形。 Fixed by using gluPerspective() rather than glMatrixMode(GL_PROJECTION) followed by a glFrustum(...) call. 通过使用gluPerspective()而不是glMatrixMode(GL_PROJECTION)后跟glFrustum(...)调用进行修复。

Still none the wiser as to why it wasn't broken, but at least it's working now :) 关于它为什么没有损坏,仍然没有一个更明智的选择,但是至少它现在可以正常工作了:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM