• 大小: 3KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-05
  • 语言: 其他
  • 标签: OpenGL  透视投影  

资源简介

本程序提供给OpenGL初学者使用, 该程序中描述了如何实现透视投影。代码中如有疑问请指出,会为你一一解答。

资源截图

代码片段和文件信息

#include 
#include 
#include 
#include 
#include 

#ifdef __APPLE__
#include           // OS X version of GLUT
#else
#define FREEGLUT_STATIC
#include             // Windows FreeGlut equivalent
#endif

#include 
using namespace std;

const float PI = 3.14159265358979323846;

/************************************************************************************/
void ChangeSize(int w int h)
{
    glViewport(0 0 w h);
}

/************************************************************************************/
#include 
#include 
#define MAX_SHADER_LENGTH 8192
#define MAX_TARGET_NUM  10

GLchar shaderText[MAX_SHADER_LENGTH];

void gltLoadShaderSrc(const char *szShaderSrc GLuint shader)
{
    GLchar *fsStringPtr[1];

    fsStringPtr[0] = (GLchar *)szShaderSrc;
    glShaderSource(shader 1 (const GLchar **)fsStringPtr NULL);
}

bool gltLoadShaderFile(const char *szFile GLuint shader)
{
    GLint shaderLength = 0;
    FILE *fp;

    // Open the shader file
    fp = fopen(szFile “r“);
    if(fp != NULL)
    {
        // See how long the file is
        while (fgetc(fp) != EOF)
            shaderLength++;

        // Allocate a block of memory to send in the shader
        assert(shaderLength < MAX_SHADER_LENGTH);   // make me bigger!
        if(shaderLength > MAX_SHADER_LENGTH)
        {
            fclose(fp);
            return false;
        }

        // Go back to beginning of file
        rewind(fp);

        // Read the whole file in
        if (shaderText != NULL)
            fread(shaderText 1 shaderLength fp);

        // Make sure it is null terminated and close the file
        shaderText[shaderLength] = ‘\0‘;
        fclose(fp);
    }
    else
        return false;

    // Load the string
    gltLoadShaderSrc((const char *)shaderText shader);

    return true;
}

GLuint vao;
GLuint vertex_bufferindex_buffer;
GLuint vert_shader frag_shader;
GLuint program;


GLfloat vVerts[12] = { -500.0f -500.0f -800.0f
                                        500.0f -500.0f -800.0f
                                            0.0f   500.0f -800.0f
                                            0.0f       0.0f -300.0f };

GLuint element_index[] = {  0 1 2
                                               0 1 3
                                               0 3 2
                                               1 2 3  };

GLfloat modelMatrix[16] = {1.0 0.0 0.0 0.0
                                                0.0 1.0 0.0 0.0
                                                0.0 0.0 1.0 0.0
                                                0.0 0.0 0.0 1.0};

GLfloat viewMatrix[16] =  {1.0 0.0 0.0 0.0
                                               0.0 1.0 0.0 0.0
                                               0.0 0.0 1.0 0.0
                                               0.0 0.0 0.0 1.0};

GLfloat projectionMat

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-04-14 13:16  SetPerspective\
     文件         202  2016-09-23 10:56  SetPerspective\Identity.fp
     文件         310  2016-09-23 14:11  SetPerspective\Identity.vp
     文件        6878  2016-10-10 13:13  SetPerspective\main.cpp
     文件         322  2016-10-09 15:52  SetPerspective\Triangle.pro

评论

共有 条评论