-
I'm rewriting my old project in LLGL, previously it was just OpenGL. I have a camera that I can zoom. I checked the projection, transform and view matrices's values in RenderDoc and they are completely the same in both projects. Here's the camera source code (the camera source code is identical in both projects): #include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include "math/rect.hpp"
#include "constants.hpp"
class Camera {
public:
Camera() {}
Camera(const glm::uvec2& viewport) {
m_viewport = viewport;
update_projection_area();
compute_projection_and_view_matrix();
}
void update() {
compute_projection_and_view_matrix();
compute_transform_matrix();
}
void set_zoom(float zoom) {
m_zoom = glm::clamp(zoom, constants::CAMERA_MAX_ZOOM, constants::CAMERA_MIN_ZOOM);
update_projection_area();
}
void set_viewport(const glm::uvec2& viewport) {
m_viewport = viewport;
update_projection_area();
}
void set_position(const glm::vec2& position) {
m_position = position;
}
private:
void compute_projection_and_view_matrix() {
const Rect projection_area = get_projection_area();
const glm::mat4 ortho = glm::ortho(
projection_area.min.x, projection_area.max.x,
projection_area.min.y, projection_area.max.y,
0.0f, 100.0f
);
const glm::mat4 projection_matrix = ortho;
const glm::mat4 view_matrix = glm::lookAt(
glm::vec3(m_position, -50.0),
glm::vec3(m_position, 0.0),
glm::vec3(0.0, -1.0, 0.0)
);
m_projection_matrix = projection_matrix;
m_view_matrix = view_matrix;
}
void compute_transform_matrix() {
m_transform_matrix = glm::translate(glm::mat4(1.0), glm::vec3(m_position, 0.));
}
void update_projection_area() {
m_area = Rect::from_corners(
-glm::vec2(m_viewport) / 2.0f * m_zoom,
glm::vec2(m_viewport) / 2.0f * m_zoom
);
}
private:
glm::mat4x4 m_projection_matrix;
glm::mat4x4 m_view_matrix;
glm::mat4x4 m_transform_matrix;
Rect m_area;
glm::uvec2 m_viewport;
glm::vec2 m_position;
float m_zoom = 1.0f;
}; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
With just the camera code, I can't tell how this projection matrix is applied and what "specific number" are we talking about? And how does this turn out to be culled? Do meshes immediately disappear? If your project comes from OpenGL, it's worth noting that OpenGL uses a different coordinate system than Direct3D. So you will have to generate different projection matrices depending on the rendering backend. LLGL tries to unify that as much as possible, but you have to at least account for OpenGL having a unit-cube for its NDC space, i.e. Z coordinates range from [-1, +1] after the vertices have been transformed with the projection matrix, while Direct3D uses a Z range [0, +1]. LLGL/ExampleBase accounts for that in its projection matrix functions: ExampleBase.cpp:957. Can you provide a bit more information about your scene setup and what the "culling" looks like since this seems to depend on your zoom values? FWIW: While LLGL doesn't enforce any specific coordinate system, the examples all use a left-handed coordinate system, while OpenGL has a right-handed coordinate system. Besides the Z-range, you can technically use either of them in GL but there are some other caveats with how image data is stored. |
Beta Was this translation helpful? Give feedback.
Oh nooo 🤦♂️.
I found the problem, I would never have figured it out if I hadn't checked the fragment stages...
The issue was with the samplers,
mipMapEnabled
was enabled so it tried to load another mip map, but I createad textures without mip maps.Anyways, thank you for your help!