C++ 在Opengl中绘制不显示C++;

C++ 在Opengl中绘制不显示C++;,c++,opengl,opengl-compat,C++,Opengl,Opengl Compat,我正试图画一条直线穿过我的窗户屏幕的颜色是工作的,但这条线似乎没有画出来。我相当肯定这是因为我可能设置了错误的位置,并且线被从窗口剪断,但我不确定如何修复这个问题 我的完整代码 #include <GL\glew.h> #include <GLFW/glfw3.h> #include <GL\glut.h> #include <glm.hpp> #include <GL\freeglut.h> #include <GL\GL.h&

我正试图画一条直线穿过我的窗户屏幕的颜色是工作的,但这条线似乎没有画出来。我相当肯定这是因为我可能设置了错误的位置,并且线被从窗口剪断,但我不确定如何修复这个问题

我的完整代码

#include <GL\glew.h>
#include <GLFW/glfw3.h>
#include <GL\glut.h>
#include <glm.hpp>
#include <GL\freeglut.h>
#include <GL\GL.h>
#include <IL/il.h>

using namespace std;

 int main() {
    int windowWidth = 1024, windowHeight = 1024;
    if (!glfwInit())
        return -1;


    GLFWwindow* window;
    window = glfwCreateWindow(windowWidth, windowHeight, "electroCraft", NULL, NULL);
    glfwMakeContextCurrent(window); // stes the specified window as active INACTIVE SCREEN IF WINDOW NOT CURRENT!!!!
    if (!window) {
        glfwTerminate();
        printf("Screen failed to start. ABORTING...\n");
        return -1;
    }
    glViewport(0, 0, windowWidth, windowHeight);
    glOrtho(0, windowWidth, 0, windowHeight, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glEnable(GL_DEPTH_TEST);
    while (!glfwWindowShouldClose(window)) {
        glClearColor(62.0f / 255.0f, 85.9f / 255.0f, 255.0 / 255.0, 0.0);
        glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

        //begin drawing
        glBegin(GL_LINE);
        glVertex2f(20, 100);
        glVertex2f(600, 100);
        glEnd();

        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    glfwTerminate();
    return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main(){
int windowWidth=1024,windowHeight=1024;
如果(!glfwInit())
返回-1;
GLFWwindow*窗口;
window=glfwCreateWindow(windowWidth,windowHeight,“electroCraft”,NULL,NULL);
glfwMakeContextCurrent(窗口);//如果窗口不是当前窗口,则将指定窗口存储为活动-非活动屏幕!!!!
如果(!窗口){
glfwTerminate();
printf(“屏幕启动失败。正在中止…\n”);
返回-1;
}
glViewport(0,0,windowWidth,windowHeight);
格洛托(0,窗宽,0,窗高,-1,1);
glMatrixMode(GLU模型视图);
glLoadIdentity();
glEnable(GLU深度试验);
而(!glfwWindowShouldClose(窗口)){
glClearColor(62.0f/255.0f、85.9f/255.0f、255.0/255.0、0.0);
glClear(GL_深度_缓冲_位| GL_颜色_缓冲_位);
//开始画画
glBegin(GLU线);
glVertex2f(20100);
glVertex2f(600100);
格伦德();
glfwSwapBuffers(窗口);
glfwPollEvents();
}
glfwTerminate();
返回0;
}

如注释中所述,您必须使用
GL\u行
而不是
GL\u行
,因为
GL\u行
不是有效类型


glBegin(GL_行);//请检查OpenGL错误(
glGetError
)。您应该在
glBegin(GL\u行)处获得一个
GL\u无效\u枚举
因为
GL\u LINE
不是有效模式。改用
GL\u行
。将GL\u行更改为GL\u行并不能解决此问题