2017-02-01 17 views
0

ウィンドウを作成して、それを目的の色にクリアすることができました。しかし、左下隅に四角形を描くことはできません。OpenGLとGLFW:ポリゴンを描画しない

#include <iostream> 

#define GLEW_STATIC 

#include <GL/glew.h> 
#include <GLFW/glfw3.h> 

const GLint WIDTH = 720; 
const GLint HEIGHT = 480; 

int main() 
{ 
    glfwInit(); 

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // Attempts to set to opengl 3.3 
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); 
    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); 

    GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "Learn OpenGL", nullptr, nullptr); 

    int screenWidth, screenHeight; 

    glfwGetFramebufferSize(window, &screenWidth, &screenHeight); 

    if (nullptr == window) 
    { 
     std::cout << "Failed to create GLFW window" << std::endl; 
     glfwTerminate(); 

     return EXIT_FAILURE; 
    } 

    glfwMakeContextCurrent(window); 

    glewExperimental = GL_TRUE; 

    if (GLEW_OK != glewInit()) 
    { 
     std::cout << "Failed to initialise GLEW" << std::endl; 

     return EXIT_FAILURE; 
    } 

    glViewport(0, 0, screenWidth, screenHeight); 

    while (!glfwWindowShouldClose(window)) 
    { 
     glClearColor(1.0f, 0.0f, 0.0f, 1.0f); 
     glClear(GL_COLOR_BUFFER_BIT); 

     glColor3f(0.0f, 0.0f, 1.0f); 
     glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); 

     glBegin(GL_POLYGON); 
      glVertex3f(0.0, 0.0, 0.0); 
      glVertex3f(0.5, 0.0, 0.0); 
      glVertex3f(0.5, 0.5, 0.0); 
      glVertex3f(0.0, 0.5, 0.0); 

     glEnd(); 
     glFlush(); 

     glfwSwapBuffers(window); 
     glfwPollEvents(); 
    } 

    glfwTerminate(); 

    return EXIT_SUCCESS; 
} 

答えて

1

廃止固定機能機能(glBegin()ら&マトリックススタック)コアコンテキスト(GLFW_OPENGL_CORE_PROFILE)で動作しません。互換性コンテキストへ

スイッチ:

#include <iostream> 

#include <GL/glew.h> 
#include <GLFW/glfw3.h> 

const GLint WIDTH = 720; 
const GLint HEIGHT = 480; 

int main() 
{ 
    glfwInit(); 

    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); 

    GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "Learn OpenGL", nullptr, nullptr); 

    int screenWidth, screenHeight; 

    glfwGetFramebufferSize(window, &screenWidth, &screenHeight); 

    if (nullptr == window) 
    { 
     std::cout << "Failed to create GLFW window" << std::endl; 
     glfwTerminate(); 

     return EXIT_FAILURE; 
    } 

    glfwMakeContextCurrent(window); 

    glewExperimental = GL_TRUE; 

    if (GLEW_OK != glewInit()) 
    { 
     std::cout << "Failed to initialise GLEW" << std::endl; 

     return EXIT_FAILURE; 
    } 

    glViewport(0, 0, screenWidth, screenHeight); 

    while (!glfwWindowShouldClose(window)) 
    { 
     glClearColor(1.0f, 0.0f, 0.0f, 1.0f); 
     glClear(GL_COLOR_BUFFER_BIT); 

     glMatrixMode(GL_PROJECTION); 
     glLoadIdentity(); 
     glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); 

     glMatrixMode(GL_MODELVIEW); 
     glLoadIdentity(); 

     glColor3f(0.0f, 0.0f, 1.0f); 
     glBegin(GL_POLYGON); 
      glVertex3f(0.0, 0.0, 0.0); 
      glVertex3f(0.5, 0.0, 0.0); 
      glVertex3f(0.5, 0.5, 0.0); 
      glVertex3f(0.0, 0.5, 0.0); 
     glEnd(); 

     glfwSwapBuffers(window); 

     glfwPollEvents(); 
    } 

    glfwTerminate(); 

    return EXIT_SUCCESS; 
} 

またはあなたのジオメトリをアップロードするVAO & VBOを使用&いくつかのシェーダを供給しています。

関連する問題