CHECK opengl version

6 篇文章 0 订阅
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += \
        main.cpp

LIBS += -lGLEW -lGLU -lglut -lGL
#include <GL/glew.h>        // the opengl library wrapped by extended features
#include <GL/freeglut.h>    // library cross-platform toolkit windows and managing input operations
#include <GL/gl.h>
#include <GL/glut.h>
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

/**
* analyse the version
*/
string makeMeString(GLint versionRaw) {
    stringstream ss;
    string str = "\0";

    ss << versionRaw;    // transfers versionRaw value into "ss"
    str = ss.str();        // sets the "str" string as the "ss" value
    return str;
}

/**
* Format the string as expected
*/
void formatMe(string *text) {
    string dot = ".";

    text->insert(1, dot); // transforms 30000 into 3.0000
    text->insert(4, dot); // transforms 3.0000 into 3.00.00
}

/**
* Message
*/
void consoleMessage() {
    char *versionGL = "\0";
    GLint versionFreeGlutInt = 0;

    versionGL = (char *)(glGetString(GL_VERSION));
    versionFreeGlutInt = (glutGet(GLUT_VERSION));

    string versionFreeGlutString = makeMeString(versionFreeGlutInt);
    formatMe(&versionFreeGlutString);

    cout << endl;
    cout << "OpenGL version: " << versionGL << endl << endl;
    cout << "FreeGLUT version: " << versionFreeGlutString << endl << endl;

    cout << "GLEW version: " <<
        GLEW_VERSION << "." << GLEW_VERSION_MAJOR << "." <<
        GLEW_VERSION_MINOR << "." << GLEW_VERSION_MICRO << endl;
}

/**
* Manager error
*/
void managerError() {
    if (glewInit()) { // checks if glewInit() is activated
        cerr << "Unable to initialize GLEW." << endl;
        while (1); // let's use this infinite loop to check the error message before closing the window
        exit(EXIT_FAILURE);
    }
    // FreeConsole();
}

/**
* Manage display (to be implemented)
*/
void managerDisplay(void)
{
    glClear(GL_COLOR_BUFFER_BIT);                // clear the screen
    glutSwapBuffers();
}


/**
* Initialize FREEGLUT
*/
void initFreeGlut(int ac, char *av[]) {
    // A. init
    glutInit(&ac, av);                                // 1. inits glut with arguments from the shell
    glutInitDisplayString("");                        // 2a. sets display parameters with a string (obsolete)
    glutInitDisplayMode(GLUT_SINGLE);                // 2b. sets display parameters with defines
    glutInitWindowSize(600, 600);                    // 3. window size
    glutInitContextVersion(3, 3);                    // 4. sets the version 3.3 as current version (so some functions of 1.x and 2.x could not work properly)
    glutInitContextProfile(GLUT_CORE_PROFILE);        // 5. sets the version 3.3 for the profile core
    glutInitWindowPosition(500, 500);                // 6. distance from the top-left screen

                                                    // B. create window
    glutCreateWindow("BadproG - Hello world :D");    // 7. message displayed on top bar window

}

/**
* Manage keyboard
*/
void managerKeyboard(unsigned char key, int x, int y) {
    if (key == 27) { // 27 = ESC key
        exit(0);
    }
}

/**
* Main, what else?
*/
int main(int argc, char** argv) {
    initFreeGlut(argc, argv);    // inits freeglut
    managerError();                // manages errors
    consoleMessage();            // displays message on the console

    // C. register the display callback function
    glutDisplayFunc(managerDisplay);                        // 8. callback function
    glutKeyboardFunc(managerKeyboard);

    // D. main loop
    glutMainLoop();                                    // 9. infinite loop
    return 0;
}

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值