本文介绍了Ç - GLFW窗口不在Debian上打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上手GLFW Debian的,我已经试过编译并运行一个例子程序,但它拒绝运行。一对夫妇的printf语句的帮助下,我发现,当程序试图打开它没有一个GLFW窗口,然后退出 - 但我不知道为什么。任何帮助将是惊人的。

 的#include<&stdlib.h中GT; //对于malloc()函数等。
#包括LT&;&stdio.h中GT; //像printf(),fopen()函数等。
#包括LT&;&math.h中GT; //因为罪(),COS()等。
#包括LT&; GL / glfw.h> //对于GLFW,OpenGL和GLU
// ------------------------------------------------ ----------------------
//绘制() - 主OpenGL绘图被称为每一帧功能
// ------------------------------------------------ ----------------------void绘制(无效)
{
    INT宽度,高度; //窗口尺寸
    成对的东西; //时间(秒)
    时int k; //循环计数器    //获取当前时间
    T = glfwGetTime();    //获取窗口大小
    glfwGetWindowSize(安培;宽度和放大器;高度);    //确保高度是非零,以避免被零除
    高度=身高< 1? 1:高度;    //设置视
    glViewport(0,0,宽度,高度);    //清除颜色和depht缓冲区
    glClearColor(0.0,0.0,0.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    //设置投影矩阵
    glMatrixMode(GL_PROJECTION); //选择投影矩阵
    glLoadIdentity(); //与单位矩阵开始
    gluPerspective(//设置透视图
        65.0,//视场角= 65度
        (双)宽/(双)高度,//窗口宽高比(假定方形像素)
        1.0,//近端Z剪切平面
        100.0 //远端Z clippling飞机
    );    //设置模型视图矩阵
    glMatrixMode(GL_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)
    );
// ****画点的圆***//保存当前的模型视图矩阵堆栈上
glPushMatrix();//翻译(移动)的点到显示的左上角
的glTranslatef(-4.0f,3.0F,0.0);//绕z轴和x轴的分
glRotatef(35.0f *(浮点)T,0.0,0.0,1.0F);
glRotatef(60.0f *(浮点)T,1.0F,0.0,0.0);//现在绘制点 - 我们使用一个for循环来构建一个圆
glColor3f(1.0F,1.0F,1.0F);
在glBegin(GL_POINTS);
对于(K = 0; K< 20; k ++)
{
    glVertex3f(2.0F *(浮点)COS(0.31416 *(双)K)
                2.0F *(浮点)罪(0.31416 *(双)K)
                0.0);
}
glEnd();//恢复模型视图矩阵
glPopMatrix();
// ****画线的圆***//保存当前的模型视图矩阵堆栈上
glPushMatrix();//翻译(移动)的线到显示屏的右上
的glTranslatef(4.0F,3.0F,0.0);//绕z轴和x轴的分
glRotatef(45.0f *(浮点)T,0.0,0.0,1.0F);
glRotatef(55.0f *(浮点)T,1.0F,0.0,0.0);//现在绘制线条 - 我们使用一个for循环来构建一个圆
在glBegin(GL_LINE_LOOP);
对于(K = 0; K< 20; k ++)
{
    glColor3f(1.0F,0.05f *(浮点)K,0.0);
    glVertex3f(2.0F *(浮点)COS(0.31416 *(双)K)
                2.0F *(浮点)罪(0.31416 *(双)K)
                0.0);
}
glEnd();//恢复模型视图矩阵
glPopMatrix();
// ****使用trinagles绘制盘***//保存当前的模型视图矩阵堆栈上
glPushMatrix();//翻译(移动)的三角形到显示器的左下角
的glTranslatef(-4.0f,-3.0f,0.0);//绕z轴和x轴的三角形
glRotatef(25.0f *(浮点)T,0.0,0.0,1.0F);
glRotatef(75.0f *(浮点)T,1.0F,0.0,0.0);//现在绘制三角形 - 我们使用一个for循环来构建一个盘
//由于我们正在建设一个三角形扇,我们还指定第一
//顶点为盘的中心点。
在glBegin(GL_TRIANGLE_FAN);
glColor3f(0.0,0.5F,1.0F);
glVertex3f(0.0,0.0,0.0);
对于(K = 0; K< 21; k ++)
{
    glColor3f(0.0,0.05f *(浮点)K,1.0F);
    glVertex3f(2.0F *(浮点)COS(0.31416 *(双)K)
                2.0F *(浮点)罪(0.31416 *(双)K)
                0.0);
}
glEnd();//恢复模型视图矩阵
glPopMatrix();
// ****使用多边形绘图光盘***//保存当前的模型视图矩阵堆栈上
glPushMatrix();//翻译(移动)的多边形到显示器的右下角
的glTranslatef(4.0F,-3.0f,0.0);//绕z轴和x轴的多边形
glRotatef(65.0f *(浮点)T,0.0,0.0,1.0F);
glRotatef(-35.0f *(浮点)T,1.0F,0.0,0.0);//现在绘制多边形 - 我们使用一个for循环来构建一个盘
在glBegin(GL_POLYGON);
对于(K = 0; K< 20; k ++)
{
    glColor3f(1.0F,0.0,0.05f *(浮点)K);
    glVertex3f(2.0F *(浮点)COS(0.31416 *(双)K)
                2.0F *(浮点)罪(0.31416 *(双)K)
                0.0);
}
glEnd();//恢复模型视图矩阵
glPopMatrix();
// ****绘制一个四***//保存当前的模型视图矩阵堆栈上
glPushMatrix();//绕y轴的四
glRotatef(60.0f *(浮点)T,0.0,1.0F,0.0);//现在绘制的四
在glBegin(GL_QUADS);
glColor3f(1.0F,0.0,0.0);
glVertex3f(-1.5f,-1.5f,0.0);
glColor3f(1.0F,1.0F,0.0);
glVertex3f(1.5F,-1.5f,0.0);
glColor3f(1.0F,0.0,1.0F);
glVertex3f(1.5F,1.5F,0.0);
glColor3f(0.0,0.0,1.0F);
glVertex3f(-1.5f,1.5F,0.0);
glEnd();//恢复模型视图矩阵
glPopMatrix();
}
// ------------------------------------------------ ----------------------
//主() - 程序入口点
// ------------------------------------------------ ----------------------INT主(INT ARGC,字符** argv的)
{
诠释OK; //标志告诉如果窗口打开
诠释运行; //标志,如果在程序运行告诉//初始化GLFW
glfwInit();
//打开窗口
OK = glfwOpenWindow(
    100,100,//宽度和窗口的高度
    8,8,8,//的色缓冲器的红色,绿色和蓝色的比特数
    8,//用于阿尔法缓冲的位数
    24,//用于深度缓冲的位数(Z缓冲)
    0,//为模板缓存的位数
    GLFW_WINDOW //我们希望有一个桌面窗口(可能是GLFW_FULLSCREEN)
);    的printf(这里);
//如果我们不能打开一个窗口,现在退出
如果(OK!)
{
    glfwTerminate();
    返回0;
}
的printf(不在这里);
//设置窗口标题
glfwSetWindowTitle(我的OpenGL程序);//启用粘滞键
glfwEnable(GLFW_STICKY_KEYS);//主渲染循环

{
    //调用我们呈现函数
    画();    //交换前后缓冲区(我们使用双缓冲显示)
    glfwSwapBuffers();    //检查逃生关键是pressed,或者如果窗口被关闭
    运行= glfwGetKey(GLFW_KEY_ESC)及!&安培;
              glfwGetWindowParam(GLFW_OPENED);
}
而(运行);//终止GLFW
glfwTerminate();//退出程序
返回0;
}


解决方案

您确信这是glfwOpenWindow那是失败的?我不知道为什么,可能是,也许你正在使用过多位为你的Z缓冲区?这是我能想到的唯一的东西。

试试这个

  GLFWvidmode DVM;
glfwGetDesktopMode(安培; DVM);
glfwOpenWindow(winWidth,winHeight,dvm.RedBits,dvm.GreenBits,dvm.BlueBits,0,0,0,GLFW_WINDOW);

,看看它是否仍然失败。

I'm trying to get started with GLFW on Debian, I've tried compiling and running an example program but it refuses to run. With the help of a couple of printf statements I've found that when the program tries to open a GLFW window it fails, then exits - but I don't know why. Any help would be amazing.

#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;
}
解决方案

You're sure it's glfwOpenWindow that's failing? I don't know why that might be, perhaps you're using too many bits for your z-buffer? That's the only thing I can think of.

Try this

GLFWvidmode dvm;
glfwGetDesktopMode(&dvm);
glfwOpenWindow(winWidth, winHeight, dvm.RedBits, dvm.GreenBits, dvm.BlueBits, 0, 0, 0, GLFW_WINDOW);

And see if it still fails.

这篇关于Ç - GLFW窗口不在Debian上打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 21:12