Raylib 3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.5 KiB

//Standard lib
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
//Third party
#include "raylib.h"
//Our own files
#include "constants.h"
#include "programstate.h"
#include "drawhelper.h"
#include "draw.h"
//Drawing Routines
#include "draw_xpitches_yports.h"
#include "draw_xports_ypitches.h"
#include "draw_port_grids.h"
#include "draw_meterbridge.h"
#include "draw_activity.h"
//Effect Routines
#include "effect_starfield.h"
#define GLSL_VERSION 330
extern ProgramState programState;
Effect effects[NR_OF_EFFECTS] = {
{ false, "Starfield", false, 1.0f, 1, 2, effect_starfield},
{ false, "Snow Fall", false, 1.0f, 1, 3, effect_starfield},
{ false, "Falling Leafs", false, 1.0f, 1, 4, effect_starfield},
{ false, "Rain", false, 1.0f, 1, 5, effect_starfield},
{ false, "Embers", false, 1.0f, 1, 5, effect_starfield},
//This needs to be manually synced to gui.c combox
//This order is permanent. No re-ordering after the first release!
//The save file and the GUI depend on it.
void (*drawFunctions[5])() = {
static Texture2D backgroundTexture;
static RenderTexture2D renderTarget;
static Shader shader;
void loadBackgroundImage(char * path, bool newImage) {
if (programState.nsm) {
char * temporaryAbsolutePath = malloc (sizeof(char) * 4096); //4096 is the max path length in linux
snprintf(temporaryAbsolutePath, (sizeof(char) * 4096), "%s/%s", programState.nsmDirectory, "background.png");
if (newImage) { //User clicked on the GUI button and chose a file
symlink(path, temporaryAbsolutePath); //source-file, link
programState.pathBackgroundImage = "background.png";
backgroundTexture = LoadTexture(temporaryAbsolutePath);
else {
programState.pathBackgroundImage = path;
backgroundTexture = LoadTexture(programState.pathBackgroundImage);
void init_draw() {
renderTarget = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
shader = LoadShader(0, FormatText("glsl%i/bloom.fs", GLSL_VERSION)); //vs file, fs file
void mainLoop_draw(Note *allGUINotes) {
if (IsWindowResized()) {
//printf("Window resized to: %i x %i\n", GetScreenWidth(), GetScreenHeight());
programState.guiRedrawNeeded = true;
//Drawing Layers from bottom to top:
//Background Image (or plain color)
//Background Sprites (internal Z-Order = Y)
//Background Effects (e.g. Starfield)
//Main Visualization (Notes)
//Foreground Sprites (internal Z-Order = Y)
//Foreground Effects (e.g. Rain)
if (programState.showBackgroundImageLayer) {
//void DrawTexture(Texture2D texture, int posX, int posY, Color tint);
//Draw centered but not scaled.
DrawTexture(backgroundTexture, GetScreenWidth()/2-backgroundTexture.width/2, GetScreenHeight()/2-backgroundTexture.height/2, WHITE);
//BeginTextureMode(renderTarget); // Enable drawing to texture
//ClearBackground(BLACK); //Texture background
//Background Effects Pass
if (programState.showEffectLayer) {
for (int i=0; i<NR_OF_EFFECTS; i++) {
if (effects[i].enabled && !effects[i].foreground) {
effects[i].function(programState.guiRedrawNeeded, effects[i].opacity, effects[i].speed, effects[i].size);
//EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
// DrawTextureRec(renderTarget.texture, (Rectangle){ 0, 0, renderTarget.texture.width, -renderTarget.texture.height }, (Vector2){ 0, 0 }, WHITE);
if (programState.showDrawMode) {
drawFunctions[programState.drawMode](allGUINotes, programState.guiRedrawNeeded); //One Mode at a time
//Foreground Effects Pass
if (programState.showEffectLayer) {
for (int i=0; i<NR_OF_EFFECTS; i++) {
if (effects[i].enabled && effects[i].foreground) {
effects[i].function(programState.guiRedrawNeeded, effects[i].opacity, effects[i].speed, effects[i].size);
//DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, 10, RAYWHITE); //show center point
programState.guiRedrawNeeded = false;