问题描述
- SDL 在iOS下使用的问题,求解
-
刚开始接触SDL,看到sdl_drawline.h里有画线的方法int SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color);
然后我就用来试着拿来画线,没法画出,你们是用sdl是怎么画线的,求个栗子
解决方案
是不是SDL依赖的库等在你的IOS上能不能正确工作,代码本身应该没啥问题,估计还是环境依赖
解决方案二:
上次问题加载背景图的正确做法是
//
// loadBackgroundBMP.c
// text
//
// Created by liu on 15/9/7.
// Copyright (c) 2015年 Fcar. All rights reserved.
//
#include "loadBackgroundBMP.h"
#include "common.h"
static SDL_Texture *texture = 0;
///更新界面
void render(SDL_Renderer *renderer) {
/* fill background in with black */
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
/* update screen */
SDL_RenderPresent(renderer);
}
///初始化纹理
void initializeTexture(SDL_Renderer *renderer) {
SDL_Surface *bmp_surface;
/* load the bmp */
bmp_surface = SDL_LoadBMP("space.bmp");
if (bmp_surface == NULL) {
fatalError("could not load bmp");
}
texture = SDL_CreateTextureFromSurface(renderer, bmp_surface);
if (texture == 0) {
fatalError("could not create texture");
}
SDL_SetColorKey(bmp_surface, 1,
SDL_MapRGB(bmp_surface->format, 0, 0, 255));
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
/* free up allocated memory */
SDL_FreeSurface(bmp_surface);
}
void loadBMP(void) {
SDL_Window *window;
SDL_Renderer *renderer;
/* 初始化 SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fatalError("Could not initialize SDL");
}
/* 创建window */
window = SDL_CreateWindow("加载背景图", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
/* 设置渲染器 */
renderer = SDL_CreateRenderer(window, -1, 0);
initializeTexture(renderer);
int done = 0;
while (!done) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
done = 1;
}
}
render(renderer);
SDL_Delay(1000);
}
/* cleanup */
SDL_DestroyTexture(texture);
/* shutdown SDL */
SDL_Quit();
}
时间: 2024-09-07 14:22:33