OpenGl and C++ music - How to play 2 music at the same time?

Hi guys I'm wondering if you guys know anything about how to play 2 sounds the same time? Currrently I'm using irrKlang and i dont think that i can play 2 sounds at the same time. Or maybe it could be my code that has a problem? Btw I'm using openGl and im currently trying to do a theme park/carnival. Im now currently doing my drop tower ride.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// this is in main.cpp
// i declared dt1 in main.cpp
// dt1 is a dropTower object
void doMainLoop()
{
	dt1.update_move();
}

void main (int argc, char * argv[])
{
	glutInit (&argc, argv);
	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize (800, 600);
	glutInitWindowPosition (100, 100);
	glutCreateWindow ("Pir4tes!");
	glutDisplayFunc (MyDisplay);
	glutReshapeFunc (rescale); // to be called when window size has changed
	glutMouseFunc (onMouseClick);
	glutMotionFunc (onMouseMove);
	glutKeyboardFunc (keyboard);
	glutIdleFunc(doMainLoop);
	bgm(); // my background music


	init ();
	glutMainLoop ();
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//this is in dropTower.h
#pragma once

#include <iostream>
#include "vec3D.h"
#include "gl/freeglut.h"

class dropTower {
private:
	vec3D pos; // position
	float elevator_move; // elevator motion
	bool elevator_flag;
public:
	dropTower();
	vec3D get_pos (void); // get current position
	void draw_base (void);
	void draw_support (void);
	void draw_elevator (void);
	void draw_seat (void);

	void update_move (void); // to update positions
	void draw_tower (void); // draw tower
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// this is in dropTower.cpp
void dropTower::update_move (void) {
	// elevator_flag is used to track whether the elevator is going up or down
	// false = elevator is going down / elevator has reached max height
	// true = elevator is going up / elevator has reached min height
	if (elevator_flag == false) {
		elevator_move-=2;

		if (elevator_move <= 0.0) {
			elevator_flag = true;
		}
	}

	else {
		elevator_move+=0.5;

		if (elevator_move >= 300.0) {
			elevator_flag = false;
			ride_scream();
		}
	}
};

void dropTower::draw_tower(void) {
        vec3D vecDt(300,300,300); // position of drop tower

	glPushMatrix();
		glColor3f(0,1,0);
		glTranslatef(vecDt.get_x(), vecDt.get_y(), vecDt.get_z());
		draw_base();

		glTranslatef(100.0,30.0,-100.0);
		
		glPushMatrix();
			glRotatef(-90.0, 1, 0, 0);
			draw_support();
		glPopMatrix();

		glPushMatrix(); 
			glTranslatef(0.0, 40.0, 0.0);
			glTranslatef(0.0, elevator_move, 0.0); 
			glRotatef(90,1,0,0);
			draw_elevator();
		glPopMatrix();
	glPopMatrix();
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
// this is in my music_and_sounds.cpp
#include <iostream>
#include <windows.h>    
#include <string>
#pragma comment(lib, "winmm.lib") 
using namespace std;

void ride_scream (void) {
	PlaySound(TEXT("music_and_sounds/many_girls_screaming"),NULL, SND_ASYNC);
};

void bgm (void) {
	PlaySound(TEXT("music_and_sounds/hikariE"),NULL, SND_ASYNC | SND_LOOP);
};


I had no problem playing just the ride_scream() as when the elevator drops down it does play the music. the only problem is when i added the bgm(). I think that its because of irrKlang but i could be wrong...
Hi,

No idea . no experiences with OpenGL
Topic archived. No new replies allowed.