我不知道为什么,但是最近我使用mmstream库的C ++ OpenGL声音流不断重复,即使控制它们的if语句是假的(使用断点检查)
以下是一段代码:
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutGameModeString("1280x768:32@75");
glutEnterGameMode();
init();
glutIdleFunc(idle);
glutMouseFunc(mouse);
glutReshapeFunc(resize);
glutKeyboardFunc(keyboard);
glutDisplayFunc(myDisplay);
glutPassiveMotionFunc(mouseMove);
glutMainLoop();
return 0;
}
和
void mouseMove(int x, int y)
{
for (i = 0; i < 12; i++)
{
if (!level1.levelOneActive[i])
{
if(x >= originX && x <= ((windowW + resizeWindowW) * 0.25) && y >= originY && y <= (windowH + resizeWindowH))
{
useOnce = true;
PlaySound(TEXT("newGame.wav"), NULL, SND_FILENAME | SND_SYNC);
useOnce = false;
}
if(x >= originX + ((windowW + resizeWindowW) * 0.25) && x <= ((windowW + resizeWindowW) * 0.5) && y >= originY && y <= (windowH + resizeWindowH))
{
useOnce = true;
PlaySound(TEXT("loadGame.wav"), NULL, SND_FILENAME | SND_SYNC);
useOnce = false;
}
if(x >= originX + ((windowW + resizeWindowW) * 0.5) && x <= ((windowW + resizeWindowW) * 0.75) && y >= originY && y <= (windowH + resizeWindowH))
{
useOnce = true;
PlaySound(TEXT("options.wav"), NULL, SND_FILENAME | SND_SYNC);
useOnce = false;
}
if(x >= originX + ((windowW + resizeWindowW) * 0.75) && x <= (windowW + resizeWindowW) && y >= originY && y <= (windowH + resizeWindowH))
{
useOnce = true;
PlaySound(TEXT("exitGame.wav"), NULL, SND_FILENAME | SND_SYNC);
useOnce = false;
}
}
}
}
编辑:这是头文件:
#include <iostream>
#include "gl\glut.h"
#include "levelOne.h"
#include "levelTwo.h"
#include "player.h"
#include "trap.h"
#include <mmstream.h>
using namespace std;
levelOne level1;
levelTwo level2;
player player1;
trap t1;
int windowW = 500, windowH = 500, timer = 60;
int resizeWindowW = 0, resizeWindowH = 0;
int originX = 0, originY = 0, i;
bool useOnce = false;