举报

写了一个多线程的程序但是图片无法显示

0

写了一个多线程的程序但是图片无法显示(附上代码)

#include <graphics.h>
#include <iostream>
#include <stdio.h>
#include <string>
#include <thread>

void drawThread()
{

	printf("drawThread start\n");
	initgraph(1280, 720);
	IMAGE backGround;
	loadimage(&backGround, "img/background.png");
	putimage(0, 0, &backGround);

	BeginBatchDraw();

	while (true)
	{
		printf("fram start  ");
		DWORD startTime = GetTickCount();

		cleardevice();
		playerLeft.drawAnim(500, 500);

		FlushBatchDraw();

		DWORD endTime = GetTickCount();
		DWORD runningTime = endTime - startTime;
		if (runningTime < 20)
			Sleep(20 - runningTime);
	}
	EndBatchDraw();
	return;
}
void logicThread()
{
	printf("logicThread start\n");
	while (1)
	{

	}
	return;
}

void messageThread()
{
	printf("messageThread start\n");

	while (1)
	{

	}
	return;
}
int main()
{

	std::thread first(drawThread);
	std::thread second(logicThread);
	std::thread third(messageThread);
	first.detach();
	second.detach();
	third.detach();

	while (true)
	{
		Sleep(60);
	}

	return 0;
}
举报
0

一步一步调试,先试试看在单线程下你的图片显示代码是否有效。

ava
慢羊羊

2024-6-28

技术讨论社区