glm-math

Do not understand captureViews in Diffuse-irradiance tutorial in learnopengl.com

扶醉桌前 提交于 2019-12-31 05:05:15
问题 I am learning IBL in https://learnopengl.com/PBR/IBL/Diffuse-irradiance. The tutorial convert a equirectangular to a cubemap by creating 6 views. And the views are the following code: glm::mat4 captureViews[] = { glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3( 1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)), glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)), glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3( 0.0f, 1.0f, 0.0f), glm::vec3

How does OpenGL fill buffers and read them back?

扶醉桌前 提交于 2019-12-25 07:39:35
问题 I was using an OpenGL buffer with a bunch of GLfloats as a vertex buffer and all was well. The format of the GLfloats being [x1, y1, z1, x2, y2, z2, ...] . But then, while following this tutorial, it tells me to use glm::vec3 instead: glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(GLfloat), &vertices[0], GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW); Now this code is valid, and I wonder how would OpenGL know how to

Opengl Billboard matrix

流过昼夜 提交于 2019-12-24 13:44:07
问题 I am writing a viewer for a proprietary mesh & animation format in OpenGL. During rendering a transformation matrix is created for each bone (node) and is applied to the vertices that bone is attached to. It is possible for a bone to be marked as "Billboarded" which as most everyone knows, means it should always face the camera. So the idea is to generate a matrix for that bone which when used to transform the vertices it's attached to, causes the vertices to be billboarded. On my test model

GLM matrix multiplication and OpenGL GLSL

南楼画角 提交于 2019-12-24 13:18:50
问题 I have similar code as in this question: some opengl and glm explanation I have a combined matrix that I pass as a single uniform //C++ mat4 combinedMatrix = projection * view * model; //GLSL doesn't work out_position = combinedMatrix * vec4(vertex, 1.0); It doesn't work. But if I do all the multiplication in the shader so I pass in each individual matrix and get //GLSL works out_position = projection * view * model * vec4(vertex, 1.0); It works. I can't see anything wrong with my matrices in

How to draw multiple objects in OpenGL using multiple VAO and VBO?

北战南征 提交于 2019-12-24 00:43:37
问题 I'm trying to render multiple objects in OpenGL using multiple VAO's and VBO's. To render multiple objects using the same vertices I've done it, but what I want to do is to use different vertices for each object, for example to draw a square and a circle. For a square I only need 6 vertices but for circle I need 360. I have error with reading or creating the shaders. Here is the Vertex Shader: #version 330 core layout (location = 0) in vec4 position; uniform mat4 model; uniform mat4 view;

glm returning nan on simple translate

时光怂恿深爱的人放手 提交于 2019-12-24 00:36:12
问题 I'm tinkering with OpenGL using glfw, glad, and glm. In one of the tutorials I'm using, they demonstrate some simple usage of glm as so: glm::vec4 vec(1.0f, 0.0f, 0.0f, 1.0f); glm::mat4 trans; trans = glm::translate(trans, glm::vec3(1.0f, 1.0f, 0.0f)); vec = trans * vec; std::cout << vec.x << vec.y << vec.z << std::endl; When I compile and run this code, I get trash values (usually NAN). The tutorial specifically noted that instantiating glm::mat4 trans; would by default create an identity

Multiplying a matrix and a vector in GLM (OpenGL)

青春壹個敷衍的年華 提交于 2019-12-18 18:47:32
问题 I have a transformation matrix, m , and a vector, v . I want to do a linear transformation on the vector using the matrix. I'd expect that I would be able to do something like this: glm::mat4 m(1.0); glm::vec4 v(1.0); glm::vec4 result = v * m; This doesn't seem to work, though. What is the correct way to do this kind of operation in GLM? Edit: Just a note to anyone who runs into a similar problem. GLM requires all operands to use the same type. Don't try multiplying a dvec4 with a mat4 and

glDrawElements crash (OpenGL 3.2 / Windows 7)

做~自己de王妃 提交于 2019-12-18 17:26:27
问题 I'm trying to draw a simple quad in OpenGL 3.2 however the application crashes with "Access violation reading location 0x00000000" when I call "glDrawElements". I assume the issue is that the Vertex Buffer data is wrong, but I am unsure how to fix the issue / debug it (an OpenGL trace would be fantastic but I do not know how to enable this either...) Initialization code: std::vector<CUShort> Indices; const CUShort IndicesArray[] = { 0, 1, 2, 2, 0, 3 }; for(size_t j = 0; j < 1; j++) { for(size

Ortho and Persp are reversing Z depth sign?

人走茶凉 提交于 2019-12-18 07:17:45
问题 NDC coordinates for OpenGL form a cube, who's -Z side presses against the screen while it's +Z side is farthest away. When I use... // ortho arguments are: left, right, bottom, top, near, far pos = pos * glm::ortho<float>(-1, 1, -1, 1, -1, 1); ...the z component of pos is reflected; -1 becomes 1, 10 becomes -10, etc. glm::persp does a similar thing and it's kind of a weird? If a position has a z equal to near , I would expect it to rest on the screen facing plane of the NDC cube, but instead

OpenGL transforming objects with multiple rotations of Different axis

放肆的年华 提交于 2019-12-18 07:07:14
问题 I am building a modeling program and I'd like to do transformations on objects in their own space and then assign that single object to a group to rotate around another axis which the group rotates around. However, I'd also like to be able to do transformations in the object's own space when it's combined. Manipulating the individual object, I pick the object's center. glm::mat4 transform; transform = glm::translate(transform, - obj.meshCenter); glm::mat4 transform1; transform1 = glm: