OpenGL texture coordinates are mirrored when GLM_FORCE_LEFT_HANDED is defined
My engine uses a lefthanded coordinate system (y up z forward), so I am defining GLM_FORCE_LEFT_HANDED. However, I have found an issue that all textures are mirrored on the x axis. I tried fixing it by flipping the image on load, and while the image does render correctly after that, the uv coords become aligned to the bottom right instead of the bottom left.
GLM_FORCE_LEFT_HANDED on: Left handed coordinates show the image as flipped
GLM_FORCE_LEFT_HANDED off: Right handed show image correctly
1 answer

Alright I figured it out. It was actually my mesh that was the culprit. Not GLM_FORCE_LEFT_HANDED or OpenGL.
Each individual face was backward, with the 0,0 uv coordinate in the bottom right corner and 1,1 in the top left. After fixing the mesh the problem has gone away.
do you know?
how many words do you know
See also questions close to this topic

C++ increment with macro
I have the following code and I want to use increment with macro:
#include <iostream> #define ABS(x) ((x) < 0 ? (x) : (x)) int main(int argc, char** argv) { int x = 5; const int result = ABS(x++); std::cout << "R: " << result << std::endl; std::cout << "X: " << x << std::endl; return EXIT_SUCCESS; }
But output will be incorrect:
R: 6 X: 7
Is it possible to somehow use macros with an increment, or should this be abandoned altogether?

Can anyone pls tell me whats wrong with my code ? im stuck for the last 3 hours ,this question is bipartite graph in c++
idk why im getting error ,can someone help ? im trying to prove if a graph is bipartite or not in c++
bool isBipartite(vector<int> graph[],int V) { vector<int> vis(V,0); vector<int> color(V,1); color[0]=1; queue <int> q; q.push(0); while (!q.empty()) { int temp = q.front(); q.pop(); for (int i=0;i<V;i++) { if (!vis[i] && color[i] == 1) "if there is an edge, and colour is not assigned" { color[i] = 1  color[temp]; q.push(i); vis[i]=1; } else if (!vis[i] && color[i] == color[temp] "if there is an edge and both vertices have same colours" { vis[i]=1; return 0; // graph is not bipartite } } } return 1; }
it gives output "no" for whatever i enter

How to assign two or more values to a QMap Variable in Qt
I am getting confused of how to store the values assigned from 3 different functions and storing them in a single map variable
QMap<QString,QString> TrainMap = nullptr; if(......) ( TrainMap = PrevDayTrainMap(); TrainMap = NextDayTrainMap(); TrainMap = CurrentDayTrainMap(); }
The PrevDayTrainMap,NextDayTrainMap & CurrentDayTrainMap returns a set of values with Date and the TrainIdName.I need to store all the values from prevday,currentday and nextday in the TrainMap but it stores only the currentday values to the TrainMap as it is assigned at the last.I am not sure what to do so that it doesn't overwrite.If I should merge what is the way to do it?

School Project, set up OpenGL on VS 2019 Community
I am trying to set up OpenGL on my PC for a project. The project gave me sample code to run and a folder to add include directories and libs to my sample code solution in VS 2019 community. The directions were awful and wanted me to upload the include and lib directories to VC++. This did not work even remotely, none of the glfw or glew headers were recognized. I found other directions online to upload the include folders under C/C++>General>Additional Include Directories and the libs under Link>General>Additional Lib Directories. Then I added glfw3.lib;glu32.lib;glew32.lib;opengl32.lib to my Link>Input>Additional Dependencies. This allowed my program to compile. But now I get the following errors plus 90 more like it:
Warning LNK4098 defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library OpenGLSample C:\OpenGL_Projects\OpenGLSample\OpenGLSample\LINK 1 Error LNK2019 unresolved external symbol __imp__TranslateMessage@4 referenced in function __glfwPlatformInit OpenGLSample C:\OpenGL_Projects\OpenGLSample\OpenGLSample\glfw3.lib(win32_init.obj) 1```

Opengl GLFW3, Cant update vertices of two object at the same time
So i am trying to make a game where I want to update my player and enemy. enemy and player are squares. I have a square class with VAO, VBO, EBO and vertices where I load my square.
void Square::loadSquare() { unsigned int indices[] = { 0, 1, 3, // first triangle 1, 2, 3 // second triangle }; glGenVertexArrays(1, &VAO); glGenBuffers(1, &VBO); glGenBuffers(1, &EBO); // bind vertex array object glBindVertexArray(VAO); // bind vertex buffer object glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_DYNAMIC_DRAW); // bind element buffer objects // EBO is stored in the VAO glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); // registered VBO as the vertex attributes glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); glEnableVertexAttribArray(0); // unbind the VAO glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); }
and draw method:
void Square::drawSquare() { // Bind the VAO so OpenGL knows to use it glBindVertexArray(VAO); // Draw the triangle using the GL_TRIANGLES primitive glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); }
Player and Enemy classes are inherited from square class and they have their own update method where I call in my Carte classes update methode.
void Carte::update(){ drawMap(); enemy.update(GrapMap,0); player.update(GrapMap); }
In draw map I simply draw my enemy and player.
void Carte::drawMap(){ enemy.drawSquare(); player.drawSquare(); for(auto & wall : walls){ wall.drawSquare(); } }
Walls are squares too but in my case I draw therm where I want and I don't have a problem with them. at the end of every update of enemy and player after chancing vertices of them I call
glBindBuffer(GL_ARRAY_BUFFER, VAO); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_DYNAMIC_DRAW);
When it was only player that I was updating it was working flawlessly. But with enemy I cant see the player but I can see that its vertices are changing accordingly to the key input of the user. When I comment out player and try to update enemy only enemy is not updating but again I can see its vertices changing as it should.
Before creating my Carte object at the main I did this:
// Vertex Shader source code const char* vertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" "void main()\n" "{\n" " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" "}\0"; //Fragment Shader source code const char* fragmentShaderSource = "#version 330 core\n" "out vec4 FragColor;\n" "void main()\n" "{\n" " FragColor = vec4(0.8f, 0.3f, 0.02f, 1.0f);\n" "}\n\0"; int main() { // Initialize GLFW glfwInit(); // Tell GLFW what version of OpenGL we are using // In this case we are using OpenGL 3.3 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // Tell GLFW we are using the CORE profile // So that means we only have the modern functions glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Create a GLFWwindow object of 800 by 800 pixels, naming it "window" GLFWwindow* window = glfwCreateWindow(1000, 1000, "Window", NULL, NULL); // Error check if the window fails to create if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return 1; } // Introduce the window into the current context glfwMakeContextCurrent(window); //Load GLAD so it configures OpenGL gladLoadGL(); // Specify the viewport of OpenGL in the Window // In this case the viewport goes from x = 0, y = 0, to x = 800, y = 800 //glViewport(0, 0, 1400, 1400); // Create Vertex Shader Object and get its reference GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER); // Attach Vertex Shader source to the Vertex Shader Object glShaderSource(vertexShader, 1, &vertexShaderSource, NULL); // Compile the Vertex Shader into machine code glCompileShader(vertexShader); // Create Fragment Shader Object and get its reference GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); // Attach Fragment Shader source to the Fragment Shader Object glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL); // Compile the Vertex Shader into machine code glCompileShader(fragmentShader); // Create Shader Program Object and get its reference GLuint shaderProgram = glCreateProgram(); // Attach the Vertex and Fragment Shaders to the Shader Program glAttachShader(shaderProgram, vertexShader); glAttachShader(shaderProgram, fragmentShader); // Wrapup/Link all the shaders together into the Shader Program glLinkProgram(shaderProgram); // Delete the now useless Vertex and Fragment Shader objects glDeleteShader(vertexShader); glDeleteShader(fragmentShader);
In my while loop I am doing this:
// Specify the color of the background glClearColor(0.07f, 0.13f, 0.17f, 1.0f); // Clean the back buffer and assign the new color to it glClear(GL_COLOR_BUFFER_BIT); // Tell OpenGL which Shader Program we want to use glUseProgram(shaderProgram); int keyW = glfwGetKey(window, GLFW_KEY_W); int keyA = glfwGetKey(window, GLFW_KEY_A); int keyS = glfwGetKey(window, GLFW_KEY_S); int keyD = glfwGetKey(window, GLFW_KEY_D); carte.update(); if(keyW) deneme.setPlayerDirection(Directions::UP); else if(keyA) deneme.setPlayerDirection(Directions::LEFT); else if(keyS) deneme.setPlayerDirection(Directions::DOWN); else if(keyD) deneme.setPlayerDirection(Directions::RIGHT); // Swap the back buffer with the front buffer glfwSwapBuffers(window); // Take care of all GLFW events glfwPollEvents();
I don't understand why I can't update my two objects at the same time. Why I cant draw squares as the vertices changes when there is more then one objects vertices are changing.
edit to show how I change my vertices in Player:
if(getDirection() == Directions::UP){ trans = glm::translate(trans, glm::vec3(0.0f, 0.0002f, 0.0f)); setCenter(center.first,center.second + 0.0002f); } else if (getDirection() == Directions::LEFT){ trans = glm::translate(trans, glm::vec3(0.0002f, 0.0f, 0.0f)); setCenter(center.first0.0002f,center.second); } else if (getDirection() == Directions::DOWN){ trans = glm::translate(trans, glm::vec3(0.0f, 0.0002f, 0.0f)); setCenter(center.first,center.second0.0002f); } else if (getDirection() == Directions::RIGHT){ trans = glm::translate(trans, glm::vec3(0.0002f, 0.0f, 0.0f)); setCenter(center.first+0.0002f,center.second); } else if (getDirection() == Directions::STOP) trans = glm::translate(trans, glm::vec3(0.0f, 0.0f, 0.0f)); for(int i=0; i < 4; i ++){ glm::vec4 tmp = trans * glm::vec4(getVertices()[i],1); setVertices(i, tmp.x, tmp.y, tmp.z); } glBindBuffer(GL_ARRAY_BUFFER, VAO); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_DYNAMIC_DRAW);

Repeat a cubemap texture on a cube face with OpenGL
Is it possible to make a cube map texture (GL_TEXTURE_CUBE_MAP_POSITIVE_X...) repeat on a given face with OpenGL?
I have a simple unit cube with 24 vertexes centered around the origin (xyz between (0.5, 0.5, 0.5) and (0.5, 0.5, 0.5)). Among its attributes, initially I set the uvw coords to the xyz position in the fragment shader as was done in the cubemap learnopengl.com tutorial. I obviously tried also to have separate uvw coordinates set to values equal to the scale, but the texture wasnt't repeating on any cube face as can be seen from the one displayed below (I painted the uvw coordinates in the fragment shader) :
height (ycoord of top pixels) = 3.5 in the image above, so by setting v = 3.5 for the vertex at the top, I'd expect the gradient to repeat vertically (which is not the case).
If it's not possible, the only way left for me to fix it is to assign a 2D Texture with custom uv coordinates on each vertex, right?

Raytracing program fails to detect intersections in c++
I am working on a simple raytracer in c++. I am currently implementing an intersection function but have encountered some issues.
For some reason, the collision detection only works for a tiny rectangle in my image. In the image below you can see that it draws the room quite fine for a small part of the screen but fails to do so for the rest of the scene. Only a small section gets drawn correctly.
Why does my intersection detection not work? I have included the code for the intersection and draw function below.
LoadTestModel(m_Model); m_Light.position = glm::vec3(0.0f, 1.0f, 0.0); m_Light.color = glm::vec3(0.f, 0.f, 0.f); m_Light.ambient = glm::vec3(0.5f, 0.5f, 0.5f); m_Camera.position = glm::vec3(0.0, 0.0, 2.0); m_Camera.yaw = 0.0f; } void Lab2Scene::Draw(Window& window) { if (!m_RenderNext) return; m_RenderNext = false; for (uint32_t y = 0; y < window.GetHeight(); ++y) { for (uint32_t x = 0; x < window.GetWidth(); ++x) { Ray ray = {}; glm::vec3 d(x  (window.GetWidth() / 2), y  (window.GetHeight() / 2), (window.GetHeight() / 2)); d = glm::normalize(d); ray.direction = d * m_Camera.GetRotationY(); ray.start = m_Camera.position; // Find the closest intersection of the casted ray. Intersection nearest_intersection = {}; if (ClosestIntersection(ray, m_Model, nearest_intersection)) { //window.PutPixel(x, y, glm::vec3(1.f, 0.f, 0.f)); window.PutPixel(x, y, DirectLight(m_Light, nearest_intersection, m_Model) + m_Model[nearest_intersection.triangleIndex].color * m_Light.ambient); // DirectLight(m_Light, intersection, m_Model) } else { window.PutPixel(x, y, m_Light.color); } } } } bool Lab2Scene::ClosestIntersection(const Ray& ray, const std::vector<Triangle>& triangles, Intersection& intersection) { float m = std::numeric_limits<float>::max(); intersection.distance = m; bool inters = false; for (int i = 0; i < triangles.size(); ++i) { float dot = glm::dot(ray.direction, triangles[i].normal); if (dot != 0) { using glm::vec3; using glm::mat3; vec3 v0 = triangles[i].v0; vec3 v1 = triangles[i].v1; vec3 v2 = triangles[i].v2; vec3 e1 = v1  v0; vec3 e2 = v2  v0; vec3 b = ray.start  v0; mat3 A(ray.direction, e1, e2); vec3 x = glm::inverse(A) * b; if (x[1] >= 0 && x[2] >= 0 && x[1] + x[2] <= 1 && x[0] >= 0) { vec3 intersect = ray.start + (x[0] * ray.direction); if (glm::distance(ray.start, intersect) <= intersection.distance) { intersection.position = intersect; intersection.distance = glm::distance(ray.start, intersect); intersection.triangleIndex = i; inters = true; } } } } return inters; }

OpenGL Light can not fully cover model when model scaled
I have a obj which coordinates out of [1, 1], so I rescale it using ModelMatrix, it works.
But the light seems not working. the Light I set position is:
glm::vec3 lightPos = glm::vec3(4, 5, 6); glUniform3f(LightID, lightPos.x, lightPos.y, lightPos.z);
the model scaled down about 28 times.
It now looks like this:
Any help? How should I fix it?
I can not provide fully code!! Someone point me out that I might not rescale the normal. But I don't know how to rescale the normal.
Here was my matrix mainly used:
glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP; glm::mat4 ViewMatrix; glm::mat3 ModelView3x3Matrix = glm::mat3(ViewMatrix); // scale model matrix Model = glm::scale(Model, glm::vec3(1.0f / max_extent, 1.0f / max_extent, 1.0f / max_extent)); // Send our transformation to the currently bound shader, // in the "MVP" uniform glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]); glUniformMatrix4fv(ModelMatrixID, 1, GL_FALSE, &Model[0][0]); glUniformMatrix4fv(ViewMatrixID, 1, GL_FALSE, &ViewMatrix[0][0]); glUniformMatrix3fv(ModelView3x3MatrixID, 1, GL_FALSE, &ModelView3x3Matrix[0][0]); glm::vec3 lightPos = glm::vec3(4, 5, 6); glUniform3f(LightID, lightPos.x, lightPos.y, lightPos.z);
Please don't close my question so rude, otherwise I will curse all your family!!!