Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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-GLFW窗口不';无法在Debian上打开_C_Opengl_Debian - Fatal编程技术网

C-GLFW窗口不';无法在Debian上打开

C-GLFW窗口不';无法在Debian上打开,c,opengl,debian,C,Opengl,Debian,我试图在Debian上开始使用GLFW,我尝试编译并运行一个示例程序,但它拒绝运行。在几个printf语句的帮助下,我发现当程序试图打开GLFW窗口时失败,然后退出——但我不知道为什么。任何帮助都将是惊人的 #include <stdlib.h> // For malloc() etc. #include <stdio.h> // For printf(), fopen() etc. #include <math.h> // For s

我试图在Debian上开始使用GLFW,我尝试编译并运行一个示例程序,但它拒绝运行。在几个printf语句的帮助下,我发现当程序试图打开GLFW窗口时失败,然后退出——但我不知道为什么。任何帮助都将是惊人的

#include <stdlib.h>    // For malloc() etc.
#include <stdio.h>     // For printf(), fopen() etc.
#include <math.h>      // For sin(), cos() etc.
#include <GL/glfw.h>   // For GLFW, OpenGL and GLU


//----------------------------------------------------------------------
// Draw() - Main OpenGL drawing function that is called each frame
//----------------------------------------------------------------------

void Draw( void )
{
    int    width, height;  // Window dimensions
    double t;              // Time (in seconds)
    int    k;              // Loop counter

    // Get current time
    t = glfwGetTime();

    // Get window size
    glfwGetWindowSize( &width, &height );

    // Make sure that height is non-zero to avoid division by zero
    height = height < 1 ? 1 : height;

    // Set viewport
    glViewport( 0, 0, width, height );

    // Clear color and depht buffers
    glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    // Set up projection matrix
    glMatrixMode( GL_PROJECTION );    // Select projection matrix
    glLoadIdentity();                 // Start with an identity matrix
    gluPerspective(                   // Set perspective view
        65.0,                         // Field of view = 65 degrees
        (double)width/(double)height, // Window aspect (assumes square pixels)
        1.0,                          // Near Z clipping plane
        100.0                         // Far Z clippling plane
    );

    // Set up modelview matrix
    glMatrixMode( GL_MODELVIEW );     // Select modelview matrix
    glLoadIdentity();                 // Start with an identity matrix
    gluLookAt(                        // Set camera position and orientation
        0.0, 0.0, 10.0,               // Camera position (x,y,z)
        0.0, 0.0, 0.0,                // View point (x,y,z)
        0.0, 1.0, 0.0                 // Up-vector (x,y,z)
    );


// **** Draw a circle of points ***

// Save the current modelview matrix on the stack
glPushMatrix();

// Translate (move) the points to the upper left of the display
glTranslatef( -4.0f, 3.0f, 0.0f );

// Rotate the points about the z-axis and the x-axis
glRotatef( 35.0f * (float)t, 0.0f, 0.0f, 1.0f );
glRotatef( 60.0f * (float)t, 1.0f, 0.0f, 0.0f );

// Now draw the points - we use a for-loop to build a circle
glColor3f( 1.0f, 1.0f, 1.0f );
glBegin( GL_POINTS );
for( k = 0; k < 20; k ++ )
{
    glVertex3f( 2.0f * (float)cos( 0.31416 * (double)k ),
                2.0f * (float)sin( 0.31416 * (double)k ),
                0.0f );
}
glEnd();

// Restore modelview matrix
glPopMatrix();


// **** Draw a circle of lines ***

// Save the current modelview matrix on the stack
glPushMatrix();

// Translate (move) the lines to the upper right of the display
glTranslatef( 4.0f, 3.0f, 0.0f );

// Rotate the points about the z-axis and the x-axis
glRotatef( 45.0f * (float)t, 0.0f, 0.0f, 1.0f );
glRotatef( 55.0f * (float)t, 1.0f, 0.0f, 0.0f );

// Now draw the lines - we use a for-loop to build a circle
glBegin( GL_LINE_LOOP );
for( k = 0; k < 20; k ++ )
{
    glColor3f( 1.0f, 0.05f * (float)k, 0.0f );
    glVertex3f( 2.0f * (float)cos( 0.31416 * (double)k ),
                2.0f * (float)sin( 0.31416 * (double)k ),
                0.0f );
}
glEnd();

// Restore modelview matrix
glPopMatrix();


// **** Draw a disc using trinagles ***

// Save the current modelview matrix on the stack
glPushMatrix();

// Translate (move) the triangles to the lower left of the display
glTranslatef( -4.0f, -3.0f, 0.0f );

// Rotate the triangles about the z-axis and the x-axis
glRotatef( 25.0f * (float)t, 0.0f, 0.0f, 1.0f );
glRotatef( 75.0f * (float)t, 1.0f, 0.0f, 0.0f );

// Now draw the triangles - we use a for-loop to build a disc
// Since we are building a triangle fan, we also specify a first
// vertex for the centre point of the disc.
glBegin( GL_TRIANGLE_FAN );
glColor3f( 0.0f, 0.5f, 1.0f );
glVertex3f( 0.0f, 0.0f, 0.0f );
for( k = 0; k < 21; k ++ )
{
    glColor3f( 0.0f, 0.05f * (float)k, 1.0f );
    glVertex3f( 2.0f * (float)cos( 0.31416 * (double)k ),
                2.0f * (float)sin( 0.31416 * (double)k ),
                0.0f );
}
glEnd();

// Restore modelview matrix
glPopMatrix();


// **** Draw a disc using a polygon ***

// Save the current modelview matrix on the stack
glPushMatrix();

// Translate (move) the polygon to the lower right of the display
glTranslatef( 4.0f, -3.0f, 0.0f );

// Rotate the polygon about the z-axis and the x-axis
glRotatef( 65.0f * (float)t, 0.0f, 0.0f, 1.0f );
glRotatef( -35.0f * (float)t, 1.0f, 0.0f, 0.0f );

// Now draw the polygon - we use a for-loop to build a disc
glBegin( GL_POLYGON );
for( k = 0; k < 20; k ++ )
{
    glColor3f( 1.0f, 0.0f, 0.05f * (float)k );
    glVertex3f( 2.0f * (float)cos( 0.31416 * (double)k ),
                2.0f * (float)sin( 0.31416 * (double)k ),
                0.0f );
}
glEnd();

// Restore modelview matrix
glPopMatrix();


// **** Draw a single quad ***

// Save the current modelview matrix on the stack
glPushMatrix();

// Rotate the quad about the y-axis
glRotatef( 60.0f * (float)t, 0.0f, 1.0f, 0.0f );

// Now draw the quad
glBegin( GL_QUADS );
glColor3f( 1.0f, 0.0f, 0.0f );
glVertex3f( -1.5f, -1.5f, 0.0f );
glColor3f( 1.0f, 1.0f, 0.0f );
glVertex3f(  1.5f, -1.5f, 0.0f );
glColor3f( 1.0f, 0.0f, 1.0f );
glVertex3f(  1.5f,  1.5f, 0.0f );
glColor3f( 0.0f, 0.0f, 1.0f );
glVertex3f( -1.5f,  1.5f, 0.0f );
glEnd();

// Restore modelview matrix
glPopMatrix();
}


//----------------------------------------------------------------------
// main() - Program entry point
//----------------------------------------------------------------------

int main( int argc, char **argv )
{
int    ok;             // Flag telling if the window was opened
int    running;        // Flag telling if the program is running

// Initialize GLFW
glfwInit();
// Open window
ok = glfwOpenWindow(
    100, 100,          // Width and height of window
    8, 8, 8,           // Number of red, green, and blue bits for color buffer
    8,                 // Number of bits for alpha buffer
    24,                // Number of bits for depth buffer (Z-buffer)
    0,                 // Number of bits for stencil buffer
    GLFW_WINDOW        // We want a desktop window (could be GLFW_FULLSCREEN)
);

        printf("here");
// If we could not open a window, exit now
if( !ok )
{
    glfwTerminate();
    return 0;
}
printf("not here");


// Set window title
glfwSetWindowTitle( "My OpenGL program" );

// Enable sticky keys
glfwEnable( GLFW_STICKY_KEYS );

// Main rendering loop
do
{
    // Call our rendering function
    Draw();

    // Swap front and back buffers (we use a double buffered display)
    glfwSwapBuffers();

    // Check if the escape key was pressed, or if the window was closed
    running = !glfwGetKey( GLFW_KEY_ESC ) &&
              glfwGetWindowParam( GLFW_OPENED );
}
while( running );

// Terminate GLFW
glfwTerminate();

// Exit program
return 0;
}
#包括//用于malloc()等。
#包括//用于printf()、fopen()等。
#包括//用于sin()、cos()等。
#包括//用于GLFW、OpenGL和GLU
//----------------------------------------------------------------------
//Draw()-调用每个帧的主要OpenGL绘图函数
//----------------------------------------------------------------------
作废取款(作废)
{
int宽度,高度;//窗口尺寸
双t;//时间(秒)
int k;//循环计数器
//获取当前时间
t=glfwGetTime();
//获取窗口大小
GLFWGetWindowsSize(宽度和高度);
//确保高度不为零,以避免被零除
高度=高度<1?1:高度;
//设置视口
glViewport(0,0,宽度,高度);
//清除颜色和深度缓冲区
glClearColor(0.0f、0.0f、0.0f、0.0f);
glClear(GL_颜色_缓冲_位| GL_深度_缓冲_位);
//建立投影矩阵
glMatrixMode(GL_投影);//选择投影矩阵
glLoadIdentity();//从一个标识矩阵开始
gluPerspective(//设置透视视图
65.0,//视野=65度
(双)宽/(双)高,//窗宽(假定为正方形像素)
1.0,//近Z剪裁平面
100.0//远Z剪切平面
);
//设置模型视图矩阵
glMatrixMode(GL_MODELVIEW);//选择MODELVIEW矩阵
glLoadIdentity();//从一个标识矩阵开始
gluLookAt(//设置相机位置和方向
0.0,0.0,10.0,//摄像机位置(x,y,z)
0.0,0.0,0.0,//视点(x,y,z)
0.0,1.0,0.0//上方向向量(x,y,z)
);
//****画一个点圆***
//将当前modelview矩阵保存在堆栈上
glPushMatrix();
//将点平移(移动)到显示屏的左上角
GLTRANSTEF(-4.0f,3.0f,0.0f);
//围绕z轴和x轴旋转点
glRotatef(35.0f*(浮动)t、0.0f、0.0f、1.0f);
glRotatef(60.0f*(浮动)t、1.0f、0.0f、0.0f);
//现在画点-我们使用for循环来构建一个圆
GL3F(1.0f,1.0f,1.0f);
glBegin(总分);
对于(k=0;k<20;k++)
{
glVertex3f(2.0f*(浮动)cos(0.31416*(双)k),
2.0f*(浮动)sin(0.31416*(双)k),
0.0f);
}
格伦德();
//恢复模型视图矩阵
glPopMatrix();
//****画一圈线***
//将当前modelview矩阵保存在堆栈上
glPushMatrix();
//将线平移(移动)到显示屏的右上角
GLTRANSTEF(4.0f、3.0f、0.0f);
//围绕z轴和x轴旋转点
glRotatef(45.0f*(浮动)t、0.0f、0.0f、1.0f);
glRotatef(55.0f*(浮动)t、1.0f、0.0f、0.0f);
//现在画线-我们使用for循环来构建一个圆
glBegin(GL_线_环);
对于(k=0;k<20;k++)
{
glColor3f(1.0f,0.05f*(浮动)k,0.0f);
glVertex3f(2.0f*(浮动)cos(0.31416*(双)k),
2.0f*(浮动)sin(0.31416*(双)k),
0.0f);
}
格伦德();
//恢复模型视图矩阵
glPopMatrix();
//****使用trinagles绘制光盘***
//将当前modelview矩阵保存在堆栈上
glPushMatrix();
//将三角形平移(移动)到显示屏的左下角
GLTRANSTEF(-4.0f,-3.0f,0.0f);
//围绕z轴和x轴旋转三角形
glRotatef(25.0f*(浮动)t、0.0f、0.0f、1.0f);
glRotatef(75.0f*(浮动)t、1.0f、0.0f、0.0f);
//现在绘制三角形-我们使用for循环来构建光盘
//因为我们正在构建一个三角形风扇,所以我们还指定了第一个
//圆盘中心点的顶点。
glBegin(GLU三角形风扇);
GL3F(0.0f、0.5f、1.0f);
glVertex3f(0.0f,0.0f,0.0f);
对于(k=0;k<21;k++)
{
glColor3f(0.0f,0.05f*(浮动)k,1.0f);
glVertex3f(2.0f*(浮动)cos(0.31416*(双)k),
2.0f*(浮动)sin(0.31416*(双)k),
0.0f);
}
格伦德();
//恢复模型视图矩阵
glPopMatrix();
//****使用多边形绘制光盘***
//将当前modelview矩阵保存在堆栈上
glPushMatrix();
//将多边形平移(移动)到显示器的右下角
GLTRANSTEF(4.0f,-3.0f,0.0f);
//围绕z轴和x轴旋转多边形
glRotatef(65.0f*(浮动)t、0.0f、0.0f、1.0f);
glRotatef(-35.0f*(浮动)t、1.0f、0.0f、0.0f);
//现在绘制多边形-我们使用for循环来构建光盘
glBegin(GL_多边形);
对于(k=0;k<20;k++)
{
glColor3f(1.0f、0.0f、0.05f*(浮动)k);
glVertex3f(2.0f*(浮动)cos(0.31416*(双)k),
2.0f*(浮动)sin(0.31416*(双)k),
0.0f);
}
格伦德();
//恢复模型视图矩阵
glPopMatrix();
//****绘制单个四边形***
//将当前modelview矩阵保存在堆栈上
glPushMatrix();
//围绕y轴旋转四边形
glRotatef(60.0f*(浮动)t、0.0f、1.0f、0.0f);
//现在画正方形
glBegin(GL_QUADS);
GL3F(1.0f,0.0f,0.0f);
glVertex3f(-1.5f,-1.5f,0.0f);
GL3F(1.0f,1.0f,0.0f);
glVertex3f(1.5f,-1.5f,0.0f);
GL3F(1.0f,0.0f,1.0f);
glVertex3f(1.5f,1.5f,0.0f);
GL3F(0.0f、0.0f、1.0f);
glVertex3f(-1.5f,1.5f,0.0f);
格伦德();
//恢复模型视图矩阵
glPopMatrix();
}
//----------------------------------------------------------------------
//main()-程序入口点
//----------------------------------------------------------------------
int main(int argc,字符**argv
GLFWvidmode dvm;
glfwGetDesktopMode(&dvm);
glfwOpenWindow(winWidth, winHeight, dvm.RedBits, dvm.GreenBits, dvm.BlueBits, 0, 0, 0, GLFW_WINDOW);