零基础学习SDL开发之在Android使用SDL2.0显示BMP叠加图

本文介绍了如何在Android设备上利用SDL2.0库加载并显示BMP图像,同时实现图像叠加效果。作者在Ubuntu 14.04环境下,使用Eclipse和NDK进行开发,将BMP加载功能封装为单独的函数,作为对先前移植SDL2.0工作的拓展。
摘要由CSDN通过智能技术生成

在这篇文章我们主要使用SDL2.0来加载一张BMP图来渲染显示,同时叠加一张图作为背景图。

博主的开发环境:Ubuntu 14.04 64位,Eclipse + CDT + ADT+NDK

在前面两篇文章我们知道了如何移植SDL2.0到android上面来,并且可以在Android上面来显示一张图片,这篇文章就是在前两篇文章的基础上来进行继续开发。

一、将功能模块化,将加载BMP的功能封装到一个函数中:

/*
 * SDL_Lesson.c
 *
 *  Created on: Aug 12, 2014
 *      Author: clarck
 */
#include <jni.h>
#include "SDL.h"
#include "SDL_logger.h"
#include "SDL_main.h"
#include "SDL_cleanup.h"

//The attributes of the screen
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

struct SDL_Window *window = NULL;
struct SDL_Renderer *render = NULL;

struct SDL_Texture *background = NULL;
struct SDL_Texture *image = NULL;

struct SDL_Surface *bmp = NULL;

/*
 * Loads a BMP image into a texture on the rendering device
 * @param file The BMP image file to load
 * @param ren The renderer to load the texture onto
 * @return the loaded texture, or NULL if something went wrong.
 */
SDL_Texture* loadTexture(const char *file, SDL_Renderer *render) {
    struct SDL_Texture *texture = NULL;
    //Load the image
    bmp = SDL_LoadBMP(file);

    if (bmp == NULL) {
        LOGE("SDL_LoadBMP failed %s", SDL_GetError());
    }
    //If the loading went ok, convert to texture and return the texture
    texture = SDL_CreateTextureFromSurface(render, bmp);
    SDL_FreeSurface(bmp);

    if (texture == NULL) {
        LOGE("SDL_CreateTextureFromSurf
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值