Jump to content
  • Advertisement
Sign in to follow this  
globalhost

OpenGL Use glfwWindowHint in GLFW

This topic is 903 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#include <iostream>
#include <string>
#include <vector>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
 
static void callbackError(int error, const char* description) { fputs(description, stderr); }
 
int main(void)
{
    GLFWwindow* m_window;
    glfwSetErrorCallback(callbackError);
    if (!glfwInit()) std::cout << "??????: glfwInit()" << std::endl;
    /*glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);*/
    m_window = glfwCreateWindow(640, 480, "Test", NULL, NULL);
    if (!m_window) { glfwTerminate(); std::cout << "??????: glfwCreateWindow()" << std::endl; }
    glfwMakeContextCurrent(m_window);
    glewExperimental = GL_TRUE;
    GLenum glewError = glewInit();
    if (glewError != GLEW_OK) { glfwTerminate(); exit(EXIT_FAILURE); }
    glViewport(0, 0, 640, 480);
    int oglMajor, oglMinor;
    glGetIntegerv(GL_MAJOR_VERSION, &oglMajor);
    glGetIntegerv(GL_MINOR_VERSION, &oglMinor);
    std::string ogl_vers = std::to_string(oglMajor) + "." + std::to_string(oglMinor);
    std::cout << std::endl << "  ?????? OpenGL: " << ogl_vers << std::endl;
    GLuint VBO;
    glGenBuffers(1, &VBO);
    std::vector<glm::vec3> m_bufferDataPoints;
    m_bufferDataPoints.push_back(glm::vec3(0.0, 0.0, 0.0));
    while (!glfwWindowShouldClose(m_window))
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glBindBuffer(GL_ARRAY_BUFFER, VBO);
        glBufferData(GL_ARRAY_BUFFER, m_bufferDataPoints.size() * sizeof(glm::vec3), &m_bufferDataPoints[0], GL_DYNAMIC_DRAW);
        glEnableVertexAttribArray(0);
        glBindBuffer(GL_ARRAY_BUFFER, VBO);
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*) 0);
        glDrawArrays(GL_POINTS, 0, m_bufferDataPoints.size());
        glDisableVertexAttribArray(0);
        glfwSwapBuffers(m_window);
        glfwPollEvents();
    }
    std::cout << std::endl << std::endl;
    m_bufferDataPoints.clear();
    glDeleteBuffers(1, &VBO);
    glfwDestroyWindow(m_window);
    glfwTerminate();
}

As a result, code execution is displayed point. Output in the console "OpenGL 3.0". When add

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

do not see anything (black screen). In the console "OpenGL 3.3". And there are no errors.

Share this post


Link to post
Share on other sites
Advertisement

You seem to be relying on fixed-function functionality (I don't see you setup any shaders), something you remove by selecting a 3.3 forward compatible core profile. To resolve this you could request a compatibility profile, but you really should add some shaders.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!