opengl 开发笔记-绘制纹理

数据定义static Color4F white_color = {1.0f,1.0f,1.0f,1.0f};static Vertex2F rect_vertexes [4] ={    {100,50},{400,50},    {100,280},{400,280}};static Vertex2F texture_coords [4] ={
摘要由CSDN通过智能技术生成
  • 数据定义
    static Color4F white_color = {1.0f,1.0f,1.0f,1.0f};
    
    static Vertex2F rect_vertexes [4] =
    {
        {100,50},{400,50},
        {100,280},{400,280}
    };
    
    static Vertex2F texture_coords [4] =
    {
        {0,1},{1,1},
        {0,0},{1,0},
    };
    
    static GLuint texture_id = 0 ;
    

  • 加载png文件(加载png图片文件到内存,当前默认认为图片是32位的色彩,长宽都是2的n次方)
     
    unsigned char* read_png(const char* path,int& width,int& height){
    
        FILE* file = fopen(path, "rb");
    
        if (!file){
            return NULL;
        }
    
        png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
        png_infop info_ptr = png_create_info_struct(png_ptr);
        setjmp(png_jmpbuf(png_ptr));
    
        png_init_io(png_ptr, file);
        png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_EXPAND, 0);
    
        width = png_get_image_width(png_ptr,info_ptr);
        height = png_get_image_height(png_ptr,info_ptr);
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值