-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
152 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "audio.h" | ||
|
||
Audio::Audio() | ||
{ | ||
if(SDL_Init(SDL_INIT_AUDIO) < 0) | ||
printf("{E}: Audio init failed! %s", SDL_GetError()); | ||
|
||
SDL_zero(wanted); | ||
wanted.freq = 15360; | ||
wanted.samples = 256; | ||
wanted.format = AUDIO_S8; | ||
wanted.channels = 1; | ||
|
||
SDL_OpenAudio(&wanted, NULL); | ||
|
||
SDL_PauseAudio(0); | ||
} | ||
|
||
void Audio::push(int8_t* where, int32_t size) | ||
{ | ||
SDL_QueueAudio(1, where, size); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef AUDIO_H | ||
#define AUDIO_H | ||
|
||
#include <SDL.h> | ||
#include <iostream> | ||
|
||
class Audio | ||
{ | ||
private: | ||
SDL_AudioSpec wanted; | ||
public: | ||
Audio(); | ||
void push(int8_t *from, int32_t size); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "renderer.h" | ||
|
||
void SoftwareRenderer::drawStart() | ||
{ | ||
SDL_FillRect(SDL_GetWindowSurface(parentWin), NULL, 0x000000); | ||
} | ||
|
||
void SoftwareRenderer::render(SDL_Surface* surf) | ||
{ | ||
SDL_BlitSurface(surf, NULL, SDL_GetWindowSurface(parentWin), NULL); | ||
} | ||
|
||
void SoftwareRenderer::drawEnd() | ||
{ | ||
SDL_UpdateWindowSurface(parentWin); | ||
} | ||
|
||
void AcceleratedRenderer::render(SDL_Surface* surf) | ||
{ | ||
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surf); | ||
|
||
SDL_RenderCopy(renderer, texture, NULL, NULL); | ||
|
||
SDL_DestroyTexture(texture); | ||
} | ||
|
||
void AcceleratedRenderer::drawStart() | ||
{ | ||
SDL_RenderClear(renderer); | ||
} | ||
|
||
void AcceleratedRenderer::drawEnd() | ||
{ | ||
SDL_RenderPresent(renderer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifndef RENDERER_H | ||
#define RENDERER_H | ||
|
||
#include <iostream> | ||
#include <SDL.h> | ||
|
||
class Renderer | ||
{ | ||
protected: | ||
SDL_Window* parentWin = NULL; | ||
public: | ||
Renderer(SDL_Window* win){ | ||
parentWin = win; | ||
} | ||
virtual void render(SDL_Surface* surf) = 0; | ||
virtual void drawStart() = 0; | ||
virtual void drawEnd() = 0; | ||
}; | ||
|
||
class SoftwareRenderer : public Renderer | ||
{ | ||
public: | ||
void render(SDL_Surface* surf) override; | ||
void drawStart() override; | ||
void drawEnd() override; | ||
SoftwareRenderer(SDL_Window* win) : Renderer(win) {}; | ||
}; | ||
|
||
class AcceleratedRenderer : public Renderer | ||
{ | ||
private: | ||
SDL_Renderer* renderer = nullptr; | ||
public: | ||
void render(SDL_Surface* surf) override; | ||
void drawStart() override; | ||
void drawEnd() override; | ||
AcceleratedRenderer(SDL_Window* win) : Renderer(win) { | ||
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); | ||
if(renderer == nullptr) | ||
printf("{E}: SDL_CreateRenderer Error: %s\n", SDL_GetError()); | ||
} | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters