Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenGL中的显示窗口和线段_C++_Opengl_Glut - Fatal编程技术网

C++ OpenGL中的显示窗口和线段

C++ OpenGL中的显示窗口和线段,c++,opengl,glut,C++,Opengl,Glut,电话线没有显示出来。代码有什么问题 #include<windows.h> //#ifdef __APPLE__ //#include <GLUT/glut.h> //#else #include <GL/glut.h> //#endif //#include <stdlib.h> void init(void){ glClearColor(1.0, 1.0,1.0,0.0); glMatrixMode(GL_PROJECTION)

电话线没有显示出来。代码有什么问题

#include<windows.h>
 //#ifdef __APPLE__
 //#include <GLUT/glut.h>
 //#else
#include <GL/glut.h>
//#endif
//#include <stdlib.h>

void init(void){
  glClearColor(1.0, 1.0,1.0,0.0);
  glMatrixMode(GL_PROJECTION);
  gluOrtho2D(0.0, 200.0, 0.0,150.0);
 }

 void lineSegment(void){
   glClear(GL_COLOR_BUFFER_BIT);
   glColor3f(1.0f, 0.0f, 0.0f);     // Red

  //glColor3f(0.2, 0.4, 0.2);
  glBegin(GL_LINE);
  glVertex2i(180,15);
  glVertex2i(10,145);
  glEnd();
  glFlush();
}


int main(int argc, char* argv[]){
   glutInit(&argc,argv);
   glutInitDisplayMode(GLUT_DOUBLE); // Enable double buffered mode
   //glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
   glutInitWindowPosition(50,100);
   glutInitWindowSize(400,300);
   glutCreateWindow("An example OpenGL Program");
   init();
    glutDisplayFunc(lineSegment);
   glutMainLoop();
 return 0;
}
#包括
//#苹果__
//#包括
//#否则
#包括
//#恩迪夫
//#包括
void init(void){
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_投影);
gluOrtho2D(0.0,200.0,0.0150.0);
}
空心线段(空心){
glClear(GLU颜色缓冲位);
glColor3f(1.0f,0.0f,0.0f);//红色
//GL3F(0.2,0.4,0.2);
glBegin(GLU线);
glVertex2i(180,15);
glVertex2i(10145);
格伦德();
glFlush();
}
int main(int argc,char*argv[]){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE);//启用双缓冲模式
//glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
位置(50100);
glutInitWindowSize(400300);
glutCreateWindow(“一个示例OpenGL程序”);
init();
glutDisplayFunc(线段);
glutMainLoop();
返回0;
}
  • 您正在请求一个
    GLUT\u DOUBLE
    缓冲窗口,但在
    glutDisplayFunc()
    回调结束时调用
    glutSwapBuffers()
    失败<代码>glFlush()不够
  • GL\u LINE
    不是
    glBegin()
    的有效参数。您想到的是
    GL\u行
总而言之:

#include <GL/glut.h>

void init()
{
    glClearColor( 1.0, 1.0, 1.0, 0.0 );
    glMatrixMode( GL_PROJECTION );
    gluOrtho2D( 0.0, 200.0, 0.0, 150.0 );
}

void lineSegment()
{
    glClear( GL_COLOR_BUFFER_BIT );
    glColor3f( 1.0f, 0.0f, 0.0f );     // Red
    glBegin( GL_LINES );
    glVertex2i( 180, 15 );
    glVertex2i( 10, 145 );
    glEnd();
    glutSwapBuffers();
}

int main( int argc, char* argv[] )
{
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_DOUBLE ); // Enable double buffered mode
    glutInitWindowSize( 400, 300 );
    glutCreateWindow( "An example OpenGL Program" );
    init();
    glutDisplayFunc( lineSegment );
    glutMainLoop();
    return 0;
}
#包括
void init()
{
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_投影);
gluOrtho2D(0.0,200.0,0.0,150.0);
}
无效线段()
{
glClear(GLU颜色缓冲位);
glColor3f(1.0f,0.0f,0.0f);//红色
glBegin(GL_行);
glVertex2i(180,15);
glVertex2i(10145);
格伦德();
glutSwapBuffers();
}
int main(int argc,char*argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE);//启用双缓冲模式
glutInitWindowSize(400300);
glutCreateWindow(“一个示例OpenGL程序”);
init();
glutDisplayFunc(线段);
glutMainLoop();
返回0;
}