맥 OpenGL을 빌드로 001 환경과 안녕하세요, 세계

맥 OS, 다음에서 1. CommandLineTool 해당하는 토목
첫 번째 단계

2. 프로젝트 이름을 입력하고, ++ 언어 C를 선택한 다음
2rd 단계
프로젝트 이름을 클릭합니다 빌드를 선택 페이즈, OpenGL.framework 및 GLUT.framework 추가, 링크 바이너리 라이브러리를 선택
3 단계
미리 컴파일 된 매크로를 추가, 4. 매크로 레이블을 설정 빌드에서 검색을 경고의 후속 제거는 OpenGL 기능
제 4 회 단계
위에 5. 환경 네 단계. 다음과 같이 MAIN.CPP 다음 코드를 수정 :

#include <iostream>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>

void myDisplay(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
    glFlush();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(400, 400);
    glutCreateWindow("第一个OpenGL程序");
    glutDisplayFunc(&myDisplay);

    const GLubyte* vendorName = glGetString(GL_VENDOR);    //返回负责GL实现的厂商名字
    const GLubyte* renderName = glGetString(GL_RENDERER);  //返回渲染器名称,通常是个硬件平台
    const GLubyte* OpenGLVersion =glGetString(GL_VERSION); //返回OpenGL版本号
    const GLubyte* gluVersion= gluGetString(GLU_VERSION);  //返回GLU工具库版本
    printf("GL实现的厂商名字:%s\n", vendorName);
    printf("渲染器名称:%s\n", renderName);
    printf("OpenGL版本号:%s\n",OpenGLVersion );
    printf("GLU工具库版本:%s\n", gluVersion);

    glutMainLoop();
    return 0;
}

6. 실행 결과보기는 사각형을 그립니다 :
5rd 단계

7. 당신은 또한 라이브러리 개발 glfw에 사용할 수있는
라이브러리 glfw를 설치하는 것을 잊지 필요
6rd 단계

#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>

int main(void)
{
    GLFWwindow* window;
    
    /* Initialize the library */
    if (!glfwInit())
        return -1;
    
    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Show Me Window", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }
    
    fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
    
    glfwMakeContextCurrent(window);
    const GLubyte* OpenGLVersion =glGetString(GL_VERSION); //返回OpenGL版本号
    printf("OpenGL版本号:%s\n",OpenGLVersion );
    /* Initialize the library */
    GLenum err = glewInit();
    if (GLEW_OK != err) {
        fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
    }
    if (GLEW_VERSION_4_1) {
        std::cout << "Yay! OpenGL 4.1 is supported!" << std::endl;
    }
    
    while (!glfwWindowShouldClose(window))
    {
        glClear(GL_COLOR_BUFFER_BIT);
        
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    
    glfwTerminate();
    return 0;
}

8. 통상 누름 버튼 지지체를 테스트하는 데 필요한 다음 보정 처리 설정 키이다 glfw

static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    // 设置按键
    if( key == GLFW_KEY_ESCAPE && action == GLFW_PRESS )
        glfwSetWindowShouldClose(window, GL_TRUE);
    else if(key == GLFW_KEY_A && action == GLFW_RELEASE)
        printf("key A is released");
}

glfwSetKeyCallback(window, key_callback);
게시 90 개 원래 기사 · 원 찬양 26 ·은 10 만 + 조회수

추천

출처blog.csdn.net/sky_person/article/details/100765370