【OpenGL】OpenGL过程式纹理及Mipmap效果

【OpenGL】OpenGL过程式纹理及Mipmap效果

1.绘制目标

  1. 生成如下图所示的各级Mipmap图像
  2. 通过glTexImage2D设置各个Mipmap等级对应的纹理

在这里插入图片描述

2.核心代码

 TO DO 
    // 创建Mipmap Level 1 对应的纹理图像
    for (i = 0; i < 32; i++) {
        for (j = 0; j < 32; j++) {
            mipmapRes32[i][j][0] = 0x00;
            mipmapRes32[i][j][1] = 0xFF;
            mipmapRes32[i][j][2] = 0xFF;
        }
    }
    // 创建Mipmap Level 2 对应的纹理图像
    for (i = 0; i < 16; i++) {
        for (j = 0; j < 16; j++) {
            mipmapRes16[i][j][0] = 0xFF;
            mipmapRes16[i][j][1] = 0x00;
            mipmapRes16[i][j][2] = 0xFF;
        }
    }
    // 创建Mipmap Level 3 对应的纹理图像
    for (i = 0; i < 8; i++) {
        for (j = 0; j < 8; j++) {
            mipmapRes8[i][j][0] = 0xFF;
            mipmapRes8[i][j][1] = 0xFF;
            mipmapRes8[i][j][2] = 0x00;
        }
    }
    // 创建Mipmap Level 4 对应的纹理图像
    for (i = 0; i < 4; i++) {
        for (j = 0; j < 4; j++) {
            mipmapRes4[i][j][0] = 0xFF;
            mipmapRes4[i][j][1] = 0x00;
            mipmapRes4[i][j][2] = 0x00;
        }
    }
    // 创建Mipmap Level 5 对应的纹理图像
    for (i = 0; i < 2; i++) {
        for (j = 0; j < 2; j++) {
            mipmapRes2[i][j][0] = 0x00;
            mipmapRes2[i][j][1] = 0xFF;
            mipmapRes2[i][j][2] = 0x00;
        }
    }
    // 创建Mipmap Level 6 对应的纹理图像
    for (i = 0; i < 1; i++) {
        for (j = 0; j < 1; j++) {
            mipmapRes1[0][0][0] = 0x00;
            mipmapRes1[0][0][1] = 0x00;
            mipmapRes1[0][0][2] = 0x00;
        }
    }


/ TO DO 
//通过glTexImage2D设置各个Mipmap等级的纹理图像/
    //设置Mipmap等级0的纹理图像
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, mipmapRes64);
    //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, mipmapRes64[0]);
    //设置Mipmap等级1的纹理图像
    glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, mipmapRes32);
    //glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, mipmapRes32[0]);
    //设置Mipmap等级2的纹理图像
    glTexImage2D(GL_TEXTURE_2D, 2, GL_RGB, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, mipmapRes16);
    //glTexImage2D(GL_TEXTURE_2D, 2, GL_RGB, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, mipmapRes16[0]);
    //设置Mipmap等级3的纹理图像
    glTexImage2D(GL_TEXTURE_2D, 3, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, mipmapRes8);
    //glTexImage2D(GL_TEXTURE_2D, 3, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, mipmapRes8[0]);
    //设置Mipmap等级4的纹理图像
    glTexImage2D(GL_TEXTURE_2D, 4, GL_RGB, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, mipmapRes4);
    //glTexImage2D(GL_TEXTURE_2D, 4, GL_RGB, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, mipmapRes4[0]);
    //设置Mipmap等级5的纹理图像
    glTexImage2D(GL_TEXTURE_2D, 5, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, mipmapRes2);
    //glTexImage2D(GL_TEXTURE_2D, 5, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, mipmapRes2[0]);
    //设置Mipmap等级6的纹理图像
    glTexImage2D(GL_TEXTURE_2D, 6, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, mipmapRes1);
    //glTexImage2D(GL_TEXTURE_2D, 6, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, mipmapRes1[0]);
    /

3.运行结果

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

敲代码两年半的练习生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值