#include <stdlib.h> #include <stdio.h> #include <math.h> #include "SDL.h" #include "CGSdlRender.h" using namespace ChunGen::Client::Player; int width = 1280; int height = 720; int frame_size_y = width * height; int frame_size_uv = ((width + 1) >> 1) * ((height + 1) >> 1); int frame_size = frame_size_y + 2 * frame_size_uv; char buf[1280 * 720 * 2] = { 0 };//实际用不了这么多 int main(int argc, char* argv[]) { std::shared_ptr<CGSDLRender> sdlRender = std::make_shared<CGSDLRender>(); sdlRender->InitVideo(0); sdlRender->CreateVideoSurface(width, height); int mSize = frame_size; BYTE* data[3] = { NULL }; int linesize[5] = { 1280,640,640,0,0 }; int color = 0; data[0] = (BYTE*)buf; data[1] = (BYTE*)(buf + frame_size_y); data[2] = (BYTE*)(buf + frame_size_y + frame_size_uv); memset(data[1], 128, frame_size_y); while (color <25 ) { //mSize = fread(buf, frame_size, 1, f); memset(buf,color*10, frame_size_y); color++; sdlRender->Display((uint8_t**)data, linesize); SDL_Delay(500); printf("myplay --%d\n",color); }; return 0; }
比如画正弦波形
data[0] = (BYTE*)buf; data[1] = (BYTE*)(buf + frame_size_y); data[2] = (BYTE*)(buf + frame_size_y + frame_size_uv); memset(buf,0, frame_size_y); memset(data[1], 128, frame_size_y); for (int j = 0; j < 720; j++) { for (int i = 0; i < 1280; i++) { if (j < 240 - 240 * sin(3.14 * i / 180)) buf[j * 1280 + i] = 255; else buf[j * 1280 + i] = 0; } }
sdl mac---