I'm new to computer graphics. I played around with OpenGL and now am trying out Vulkan.
Basically what I want to do, in 2D is have an 800x800 window, and I want that to represent 800 meters by 800 meters. Then I want a circle with a radius of 1 meter.
I am going off of the Vulkan tutorial.
My data structure is this:
struct Vertex {
glm::vec2 pos;
};
I create my circle:
const int NUM_POINTS = 20;
uint32_t angle = 360/NUM_POINTS;
Vertex vertex;
std::vector<Vertex> vertices;
for(uint32_t i=0; i <= 360; i+=angle){
vertex.pos.x = cos(glm::radians(float(i)));
vertex.pos.y = sin(glm::radians(float(i)));
vertices.push_back(vertex);
}
Something to do with the viewport:
VkViewport viewport = {};
viewport.x = 0.0f;
viewport.y = 0.0f;
viewport.width = (float) swapChainExtent.width;
viewport.height = (float) swapChainExtent.height;
viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f;
viewport.width and viewport.height both equal 800.0f.
Projection matrices:
struct UniformBufferObject{
glm::mat4 model;
glm::mat4 view;
glm::mat4 proj;
};
projections:
ubo.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
ubo.proj = glm::perspective(glm::radians(45.0f), swapChainExtent.width / (float) swapChainExtent.height, 0.1f, 10.0f);
ubo.proj[1][1] *= -1;
This shows the circle, but it's almost as big as the window and it's tilted 45° away from me.
First of all, I don't understand why, if I make the first argument to glm::lookAt be glm::vec3(0.0f, 0.0f, 2.0f), I see nothing. I mean the circle is in the x-y plane. If I move in the z-direction, shouldn't I see it?
Then I tried glu::ortho
ubo.proj = glm::ortho(0.0f, 800.0f, 800.0f, 0.0f);
But I still see nothing.