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```
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?
-
Can't clone from repository of Github in Visual Studio
Recently, my visual studio can't clone from repository of GitHub.
Once it is completed clone, the visual studio will report this error "One or more errors occurred":
I cannot find any error in the output windows in visual studio.
And then, the Git Changes is blank. I can't pull and push any.
Previously I considered maybe it is the problem of my Visual Studio or Operation System.
However, after I reinstalled my Visual Studio and even reinstalled my Operation System, the problem is still here.
Soon I found a topic may relate my problem:Git has stopped working after installing VS 2022
Whereas, I tried all the ways in it and it doesn't work any.
The version of my Visual Studio is 2022 17.1.6. What's wrong with it?
-
How can I add intel Fortran compiler after installed intel oneAPI and visual studio?
I installed visual studio 2022 Community. Also, I installed Intel® oneAPI Base Toolkit and Intel® oneAPI HPC Toolkit. However, I do not know how to configure fortran compiler into visual studio so I can make Fortran project. Can you please help me with this?
-
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); // Wrap-up/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.first-0.0002f,center.second); } else if (getDirection() == Directions::DOWN){ trans = glm::translate(trans, glm::vec3(0.0f, -0.0002f, 0.0f)); setCenter(center.first,center.second-0.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 (y-coord 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?
-
How to suppress compiler errors within vctmp.cshtml files in Visual Studio?
Whenever I open a temporary cshtml file or compare the difference between the files, the compiler shows a bunch of errors. It's unable to resolve razor syntax due to a lack of context:
My project does build despite these errors and I don't really care about errors in temporary files, but they are distracting and real errors get lost in the list. Is there any way to suppress or hide them specifically for the temp files?
-
Import deployed 2012 into VS 2017 while keeping target 2012
I have a SSIS project that is deployed on SQL 2012. Since 2012 is EOL, I need to convert to 2019. However, the previous owner used a 3rd party task that does not seem to work in the newer version of VS. When I try to import the project, it sets the default target to 2019. Even if I change that to 2012 and let it convert, it still has errors and restarts VS when I try to open this task (I have installed the task on my machine). And when I create a 2012 targeted project, it allows me to open the task.
The task does not even show in 2019.
I am trying to figure out if it is possible to start a new project. Convert it to target 2012, then then import the existing package.
Every attempt I have made causes it to fail.
I did install VS 2012 and that seemed to work, but then I got a message from our IT group that VS 2012 is to be uninstalled and the project did not seem to open in VS 2017 properly either.
If I do the conversion to 2012, it gives errors, will not allow me to open it, but it does show the task as visible, so I think it is the conversion that is the problem.
I do not even need this to work as is, just need it to know what they have done so it can be converted.
-
Why Won't my Texture Appear openGL Xcode 13 stb_image
I have made the program with no issues, but when I got to textures, nothing started appearing. Below is my code.
Texture.cpp:
Texture::Texture(const std::string& path) : m_RendererID(0), m_FilePath(path), m_LocalBuffer(NULL), m_Width(0), m_Height(0), m_BPP(0) { stbi_set_flip_vertically_on_load(1); m_LocalBuffer = stbi_load(path.c_str(), &m_Width, &m_Height, &m_BPP, 4); glGenTextures(1, &m_RendererID); glBindTexture(GL_TEXTURE_2D, m_RendererID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_LocalBuffer); glBindTexture(GL_TEXTURE_2D, 0); if (m_LocalBuffer) stbi_image_free(m_LocalBuffer); }
main.cpp:
Texture texture("textures/grass_side_carried.png"); texture.Bind(); shader.SetUniform1i("u_Tex0", 0); // Update the window while it is not closed while(!glfwWindowShouldClose(window)){ // Set the background color glClearColor(0.05f, 0.09f, 0.25f, 1.0f); // Clean the background buffer and assign a new color glClear(GL_COLOR_BUFFER_BIT); shader.Bind(); ibo.Bind(); // Draw the element as triagles (primitive type to render, amount of indicies to be rendered, what data is in indicies, offset of first index which is usually nullptr) glDrawElements(GL_TRIANGLES, indiciesSize, GL_UNSIGNED_INT, nullptr); // Swap the buffers so that the window is being updated glfwSwapBuffers(window); // Check any events that happened glfwPollEvents(); }
shader:
#shader vertex // Use the version 330 of glsl #version 330 core // Coords layout (location=0) in vec3 aPos; // Colors layout (location=1) in vec3 aColor; // Textures layout (location=2) in vec2 aTex; // Send out the color from the vertices out vec3 color; out vec2 texCoord; // Get a uniform (from the CPU) uniform float u_Scale; void main(){ // Set the position of the verticies to the positions passed in gl_Position = vec4(aPos*u_Scale, 1.0); // Set the passed in color to the color being sent out color = aColor; } #shader fragment #version 330 core // Give back a color out vec4 FragColor; // Take in the color from the vertex shader in vec3 color; in vec2 texCoord; uniform sampler2D u_Tex0; void main(){ // Assign the passed in color to the color being outputted FragColor = texture(u_Tex0, texCoord); }