Thread: Calling Audio/Graphic Files

  1. #1
    Games!? pujuman's Avatar
    Join Date
    Dec 2004
    Location
    Idaho, U.S.A.
    Posts
    14

    Calling Audio/Graphic Files

    I was just wondering if there is any way at all that I could call a sound (.wav, .mp3, etc.) and/or a graphic (.jpg, .gif, .bmp, etc.) via my C++ program. I looked in the OpenGL tutorials, but it's not what I wanted per-say (I might delve into that later).

    Here's an example of what I would use it for:

    Code:
    cout<<"It's a goblin, hurry attack."<<endl;
    			while (gob > 0){	//Battle Loop
    				attack = rand() % (HIGH - LOW + 1) + LOW;
    				cout<<"***Slash***"<<endl;
    				Sleep(1000);
    				cout<<"The Goblin has "<<gob - attack<<" life left!"<<endl;
    				gob = gob - attack;
    				Sleep(1500);
    				gobattack = rand() % (gobhi - goblo +1) + goblo;
    				if(gob > 0){
    				cout<<"***Whack***"<<endl;
    				Sleep(1000);
    				cout<<"You have "<<player - gobattack<<" life left!"<<endl;
    				player = player - gobattack;
    				Sleep(1500);
    				}
    			}
    And during this bit of the code I would like it to call an audio file (battle music, I guess). Is there any way I could do this?

    By the way, I am using Microsoft Visual Studio .NET 2003.

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    SDL (my favourite) has facilities for playing sound files quite easily, and they are covered quite thoroughly in the documentation. Direct link to sound stuff.

    To download SDL, go here and click SDL-devel-1.2.8-VC6.zip (Visual C++ 5,6,7), and then follow the instructions contained in the archive.
    Last edited by Brian; 01-07-2005 at 05:52 PM.

  3. #3
    Games!? pujuman's Avatar
    Join Date
    Dec 2004
    Location
    Idaho, U.S.A.
    Posts
    14
    Thanks for the help, I'll try it out and see if it's what I'm looking for (probably is, but you never know).

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Perhaps you can also look into PlaySound(), I believe it's in <windows.h>. You'll probably have to link some extra libs n stuff, but it's a straightforward way of playing a wave file. The graphics will be somewhat more difficult, and you'll need to either delve into a 3rd party library or learn some Windows API code (very messy stuff).
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #5
    Games!? pujuman's Avatar
    Join Date
    Dec 2004
    Location
    Idaho, U.S.A.
    Posts
    14
    Yeah, I looked into the graphics tutorials and my head got all muddy just trying to read it, so I gave up on that. For now, I'm just going to go one step at a time.

    That SDL thing is confusing, I didn't understand what it was talking about at all. I think I'll try looking through the help library in Visual, it might have an answer.

    For the PlaySound(), how would that be used in context of my program. Maybe you could give me some sort of example of how you think/know it would be used. I tend to learn best if I see it used atleast once, then I usually just copy from that and modify it to how I use it.
    Last edited by pujuman; 01-07-2005 at 07:16 PM.

  6. #6
    Games!? pujuman's Avatar
    Join Date
    Dec 2004
    Location
    Idaho, U.S.A.
    Posts
    14
    Alright, I've figured out the audio part, now I need someone to help me with calling up a picture.

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Just browse the tutorials at that site - they give you example source code of all the common tasks like that. Just keep in mind that SDL is more suite to C programmers. It works in C++, but the example source code will just tend to use a different "style" than most C++ programmers.

  8. #8
    Games!? pujuman's Avatar
    Join Date
    Dec 2004
    Location
    Idaho, U.S.A.
    Posts
    14
    Well, I don't think I'm going to worry about graphics for a while, once I get the majority of C++ down, I think I'll move onto OpenGL and who knows where from there.

  9. #9
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Well, wish ya good luck and prosperity in all that you do Code, have fun, blow up a computer.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading .dat files from a folder in current directory...
    By porsche911nfs in forum C++ Programming
    Replies: 7
    Last Post: 04-04-2009, 09:52 PM
  2. Working with muliple source files
    By Swarvy in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2008, 08:36 AM
  3. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  4. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  5. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM