Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualdreamslayerx

Posted 24 October 2012 - 07:47 PM

Hey guys.  My problem may be pretty simple.  I am writing some code for a world.  I have it where opengl renders and sdl does everything else.  The problem is that SDL wants to render before opengl, and if It doesn't create a screen I can't control my audio sound effect events.  Does anyone know how to make SDL no render and give me only audio and controls with opengl doing the rendering thanks.

I will attach the current code of the audio for sdl.  The issue is that if I don't have
SDL_Surface *screen;
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

uncommented out; I am not able to use my events.  Worse it will not let opengl render over SDL.

I will not let me upload the file so here is the code.


/*This program is a test program for using SDL Mixer to create sound in programs
Music and file loading on program works great.  I just need to figure out how to control audio effect events without
SDL needing to create a screen.
I also need to put this into a function
Note:  The only issue with the program is that I can't controly my audio effect events unless I let SDL create a screen*/

#include <SDL/SDL.h>
#include "SDL_mixer.h" //This include library directory may change on different machines


//SDL sound function
void SDL_Sound()
{
SDL_Init(SDL_INIT_AUDIO);
SDL_Surface *screen; //test
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE); //test
Mix_Chunk* effect1; //new varible to create effects from SDL lib
Mix_Music* music; //used to create the music

//Open Audio
Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT,2, 4096);//require 4 parameters ( references (default 22050 or 41000), format(how to open,number of channels , chunk size)

//Loading Music
music = Mix_LoadMUS("Train.wav"); //assigns music to load Mix_LoadMUS(filenam. filetype)

//Assiging music to load
effect1=Mix_LoadWAV("TrainHorn.wav");

//Playing the music
Mix_PlayMusic(music,-1);//Telling program to play the music (play music file, how long to play 0 = play once, -1 = repeat, 1 = will repeat once)


//now to control the effect when key is pressed
bool running=true;  //boolean expression to make true
Uint32 start;
//SDL_Event event;
while(running)
{

  start=SDL_GetTicks();
  SDL_Event event;
  while(SDL_PollEvent(&event))
  {

   switch(event.type)
   {
   case SDL_QUIT:
running=false;
break;
   case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{

case SDLK_1:  //number key 1 can be pressed
Mix_PlayChannel(-1, effect1, 0);// there are a total of 8 channels (channel, effect to play, how to repeat)
break;
case SDLK_2:  //number key 1 can be pressed
running = false;
break;
}
   }
  }

};
Mix_FreeChunk(effect1);
Mix_FreeMusic(music);
}



int main(int argc,char** argv)
{


SDL_Sound();


//Closing Audio
Mix_CloseAudio();
SDL_Quit();
return 0;
}

#1dreamslayerx

Posted 24 October 2012 - 07:45 PM

Hey guys.  My problem may be pretty simple.  I am writing some code for a world.  I have it where opengl renders and sdl does everything else.  The problem is that SDL wants to render before opengl, and if It doesn't create a screen I can't control my audio sound effect events.  Does anyone know how to make SDL no render and give me only audio and controls with opengl doing the rendering thanks.

I will attach the current code of the audio for sdl.  The issue is that if I don't have
SDL_Surface *screen;
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

uncommented out; I am not able to use my events.  Worse it will not let opengl render over SDL.

I will not let me upload the file so here is the code.


/*This program is a test program for using SDL Mixer to create sound in programs
Music and file loading on program works great.  I just need to figure out how to control audio effect events without
SDL needing to create a screen.
I also need to put this into a function
Note:  The only issue with the program is that I can't controly my audio effect events unless I let SDL create a screen*/

#include <SDL/SDL.h>
#include "SDL_mixer.h" //This include library directory may change on different machines


//SDL sound function
void SDL_Sound()
{
SDL_Init(SDL_INIT_AUDIO);
SDL_Surface *screen; //test
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE); //test
Mix_Chunk* effect1; //new varible to create effects from SDL lib
Mix_Music* music; //used to create the music

//Open Audio
Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT,2, 4096);//require 4 parameters ( references (default 22050 or 41000), format(how to open,number of channels , chunk size)

//Loading Music
music = Mix_LoadMUS("Train.wav"); //assigns music to load Mix_LoadMUS(filenam. filetype)

//Assiging music to load
effect1=Mix_LoadWAV("TrainHorn.wav");

//Playing the music
Mix_PlayMusic(music,-1);//Telling program to play the music (play music file, how long to play 0 = play once, -1 = repeat, 1 = will repeat once)


//now to control the effect when key is pressed
bool running=true;  //boolean expression to make true
Uint32 start;
//SDL_Event event;
while(running)
{

  start=SDL_GetTicks();
  SDL_Event event;
  while(SDL_PollEvent(&event))
  {

   switch(event.type)
   {
   case SDL_QUIT:
running=false;
break;
   case SDL_KEYDOWN:
    switch(event.key.keysym.sym)
    {

    case SDLK_1:  //number key 1 can be pressed
Mix_PlayChannel(-1, effect1, 0);// there are a total of 8 channels (channel, effect to play, how to repeat)
break;
    case SDLK_2:  //number key 1 can be pressed
running = false;
break;
    }
   }
  }

};
Mix_FreeChunk(effect1);
Mix_FreeMusic(music);
}

int main(int argc,char** argv)
{
/*SDL_Init(SDL_INIT_AUDIO);
SDL_Surface *screen; //test
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE); //test
Mix_Chunk* effect1; //new varible to create effects from SDL lib
Mix_Music* music; //used to create the music

//Open Audio
Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT,2, 4096);//require 4 parameters ( references (default 22050 or 41000), format(how to open,number of channels , chunk size)

//Loading Music
music = Mix_LoadMUS("Train.wav"); //assigns music to load Mix_LoadMUS(filenam. filetype)

//Assiging music to load
effect1=Mix_LoadWAV("TrainHorn.wav");

//Playing the music
Mix_PlayMusic(music,-1);//Telling program to play the music (play music file, how long to play 0 = play once, -1 = repeat, 1 = will repeat once)


//now to control the effect when key is pressed
bool running=true;  //boolean expression to make true
Uint32 start;
SDL_Event event;
while(running)
{

  start=SDL_GetTicks();
  SDL_Event event;
  while(SDL_PollEvent(&event))
  {

   switch(event.type)
   {
   case SDL_QUIT:
running=false;
break;
   case SDL_KEYDOWN:
    switch(event.key.keysym.sym)
    {

    case SDLK_1:  //number key 1 can be pressed
Mix_PlayChannel(-1, effect1, 0);// there are a total of 8 channels (channel, effect to play, how to repeat)
break;
    case SDLK_2:  //number key 1 can be pressed
running = false;
break;
    }
   }
  }

};*/
SDL_Sound();

//Deleteing variables recently created
//Mix_FreeChunk(effect1);
//Mix_FreeMusic(music);

//Closing Audio
Mix_CloseAudio();
SDL_Quit();
return 0;
}

PARTNERS