Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: The first example I see in a book

  1. #11
    Junior Member Newbie
    Join Date
    Sep 2017
    Posts
    29
    Thank you.
    I'm at the Compilation stage. I opened the GLFW.sln file by VS 2017 but no glfw3.lib file was created!
    What could the problem be please?

  2. #12
    Junior Member Newbie
    Join Date
    Sep 2017
    Posts
    29
    I did these:

    1- Added glfw3.lib to this address:
    C:\Users\Abbasi\Documents\OpenGL_Projects\Libs

    and glad.h and other header files of the include folder to:
    C:\Users\Abbasi\Documents\OpenGL_Projects\Includes

    2- Then, created a project on VS 2017:
    File > New Project > Win32 console application (name testgl1) > Next > Empty project finished.
    In the solution explorer: Add New Item > C++ source file (name testgl1) > Add


    3- Went to testgl1's properties:
    VC++ Directories: Include directories => added: "C:\Users\Abbasi\Documents\OpenGL_Projects\Include s" > OK
    Linker > Input > Additional Dependencies => added: "C:\Users\Abbasi\Documents\OpenGL_Projects\Lib s" > OK


    4- Now in the project when I write: #include <glad/glad.h>, it doesn't recognized it!
    And also when I type this code:

    Code :
    #include <iostream>
    using namespace std;
    #include "vgl.h"
    #include "LoadShaders.h"
     
    enum VAO_IDs { Triangles, NumVAOs };
    enum Buffer_IDs { ArrayBuffer, NumBuffers };
    enum Attrib_IDs { vPosition = 0 };
    GLuint VAOs[NumVAOs];
    GLuint Buffers[NumBuffers];
    const GLuint NumVertices = 6;
    //--------------------------------------------------------------------
    //
    // init
    //
    void
    init(void)
    {
    	static const GLfloat vertices[NumVertices][2] =
    	{
    		{ -0.90, -0.90 }, // Triangle 1
    		{ 0.85, -0.90 },
    		{ -0.90, 0.85 },
    		{ 0.90, -0.85 }, // Triangle 2
    		{ 0.90, 0.90 },
    		{ -0.85, 0.90 }
    	};
    	glCreateBuffers(NumBuffers, Buffers);
    	glNamedBufferStorage(Buffers[ArrayBuffer], sizeof(vertices),
    		vertices, 0);
    	ShaderInfo shaders[] = {
    		{ GL_VERTEX_SHADER, "triangles.vert" },
    		{ GL_FRAGMENT_SHADER, "triangles.frag" },
    		{ GL_NONE, NULL }
    	};
    	GLuint program = LoadShaders(shaders);
    	glUseProgram(program);
    	glGenVertexArrays(NumVAOs, VAOs);
    	glBindVertexArray(VAOs[Triangles]);
    	glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
    	glVertexAttribPointer(vPosition, 2, GL_FLOAT,
    		GL_FALSE, 0, BUFFER_OFFSET(0));
    	glEnableVertexAttribArray(vPosition);
    }
    //--------------------------------------------------------------------
    //
    // display
    //
    void
    display(void)
    {
    	static const float black[] = { 0.0f, 0.0f, 0.0f, 0.0f };
    	glClearBufferfv(GL_COLOR, 0, black);
    	glBindVertexArray(VAOs[Triangles]);
    	glDrawArrays(GL_TRIANGLES, 0, NumVertices);
    }
    //--------------------------------------------------------------------
    //
    // main
    //
    int
    main(int argc, char** argv)
    {
    	glfwInit();
    	GLFWwindow* window = glfwCreateWindow(640, 480, "Triangles", NULL,
    		NULL);
    	glfwMakeContextCurrent(window);
    	gl3wInit();
    	init();
     
    	while (!glfwWindowShouldClose(window))
    	{
    		display();
    		glfwSwapBuffers(window);
    		glfwPollEvents();
    	}
     
    	glfwDestroyWindow(window);
    	glfwTerminate();
    }

    I get this result pointing to many unknown functions!

    What is/are the problem(s) please?
    How did you run your OpenGL project using Cmake and Visual Studio for the first time?

  3. #13
    Junior Member Newbie
    Join Date
    Sep 2017
    Posts
    29
    It seemed that .h and .lib files hadn't been put in the right folder. So I put the contents of both Include and Lib folders of:
    C:\Users\Abbasi\Documents\OpenGL_Projects to the include and lib folders of this path:
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.10.25017

    Then in a Win32 Console Application on Visual Studio 2017 I typed:
    <glad/glad.h>

    Still not identified by the Visual Studio!!

  4. #14
    Junior Member Newbie
    Join Date
    Oct 2017
    Location
    holographica
    Posts
    10

    Simple Strategy I follow

    I follow following strategy might help you.

    1. Where ever you .sln soultion file is in same directory create folders with name "include" and "lib".
    2. All the .h file needed by your project put them in this include folder.
    3. All the .lib files needed by your project put them in .lib folder
    4. Open you solution file
    5. Go to projects -> settings -> c/c++ -> additional header
    In this set following path
    "$(SolutionDir)\include

    6. Click on apply
    7. In same Project->settings ->Linker -> General -> Additional Library Directories
    Put here "$(SolutionDir)\lib"
    8.Click apply
    9. Now go to Projects -> Settings->Linker -> input
    Here in right hand side first row you will see all .lib file names.
    Add all libs needed by your project here.
    example glut.lib;glew.lib

    Note : Please be careful while adding libs here. If you are in debuging mode please add debug versions of .libs.
    Also if you are developing applications on x64 i.e 64 bit platform please add 64 bit versions of libs.
    10.Again click apply -> then click OK

    11. After this your project should find includes and libs and it will compile and link and create exe in debug folder if you are in debug mode.
    12. Please before running make sure all dll files of the libs that you are using are present in this debug folder or folder where your final exe is generated.


    Note : Please remember If what ever settings I have given above are done by you while you were working in debug mode and later on you change to release mode you have to do this setting again but only one time. Similar for changing platform from win32 to x64. Setting across this modes are not persistent.

    Hope this will help.

    Regards
    PixelClear

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •