From 42a57d09e9ff6dfdc07a0972386ddf0f82bbfd4c Mon Sep 17 00:00:00 2001 From: Allanis Date: Sun, 21 Jul 2013 11:13:53 +0100 Subject: [PATCH] [Add] space_renderOverlay(). --- src/lephisto.c | 1 + src/nebulae.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++- src/nebulae.h | 6 ++-- src/space.c | 12 +++++-- src/space.h | 32 ++++++++++-------- 5 files changed, 121 insertions(+), 19 deletions(-) diff --git a/src/lephisto.c b/src/lephisto.c index 417b177..3f639b0 100644 --- a/src/lephisto.c +++ b/src/lephisto.c @@ -369,6 +369,7 @@ static void render_all(void) { pilots_render(); weapons_render(WEAPON_LAYER_FG); spfx_render(SPFX_LAYER_BACK); + space_renderOverlay(); /* FG. */ player_render(); spfx_render(SPFX_LAYER_FRONT); diff --git a/src/nebulae.c b/src/nebulae.c index c0f0018..6c64efe 100644 --- a/src/nebulae.c +++ b/src/nebulae.c @@ -8,6 +8,7 @@ #include "opengl.h" #include "lfile.h" #include "rng.h" +#include "menu.h" #include "perlin.h" #define NEBU_DT_MAX 5. @@ -15,6 +16,8 @@ #define NEBULAE_Z 16 /* Z plane. */ #define NEBULAE_PATH "gen/nebu_%02d.png" +extern double gui_xoff, gui_yoff; + /* The nebulae textures. */ static GLuint nebu_textures[NEBULAE_Z]; static int nebu_w = 0; @@ -134,6 +137,8 @@ void nebu_render(void) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, nebu_textures[cur_nebu[1]]); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + /* Texture 1. */ glActiveTexture(GL_TEXTURE1); glEnable(GL_TEXTURE_2D); @@ -182,7 +187,6 @@ void nebu_render(void) { glVertex2d(-SCREEN_W/2., SCREEN_H/2.); glEnd(); - /* Clean up. */ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glDisable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); @@ -193,6 +197,89 @@ void nebu_render(void) { gl_checkErr(); } +void nebu_renderOverlay(double density) { +#define ANG45 0.70710678118654757 +#define COS225 0.92387953251128674 +#define SIN225 0.38268343236508978 + glShadeModel(GL_SMOOTH); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glTranslated(gui_xoff, gui_yoff, 0.); + + /* Stuff player partially sees. */ + glBegin(GL_TRIANGLE_FAN); + ACOLOUR(cPurple, 0.); + glVertex2d(0., 0.); + ACOLOUR(cPurple, 1.); + glVertex2d(-density, 0.); + glVertex2d(-density*COS225, density*SIN225); + glVertex2d(-density*ANG45, density*ANG45); + glVertex2d(-density*SIN225, density*COS225); + glVertex2d( 0., density); + glVertex2d( density*SIN225, density*COS225); + glVertex2d( density*ANG45, density*ANG45); + glVertex2d( density*COS225, density*SIN225); + glVertex2d( density, 0.); + glVertex2d( density*COS225, -density*SIN225); + glVertex2d( density*ANG45, -density*ANG45); + glVertex2d( density*SIN225, -density*COS225); + glVertex2d( 0., -density); + glVertex2d(-density*SIN225, -density*COS225); + glVertex2d(-density*ANG45, -density*ANG45); + glVertex2d(-density*COS225, -density*SIN225); + glVertex2d(-density, 0.); + glEnd(); /* GL_TRIANGLE_FAN */ + + glShadeModel(GL_FLAT); + + /* Stuff player can't see. */ + glBegin(GL_TRIANGLE_STRIP); + ACOLOUR(cPurple, 1.); + /* Start at the left. */ + glVertex2d(-density, 0.); + glVertex2d(-density*COS225, density*SIN225); + glVertex2d(-SCREEN_W/2.-gui_xoff, SCREEN_H/2.-gui_yoff); + glVertex2d(-density*ANG45, density*ANG45); + glVertex2d(-density*SIN225, density*COS225); + glVertex2d(-SCREEN_W/2.-gui_xoff, SCREEN_H/2.-gui_yoff); + glVertex2d( SCREEN_W/2.-gui_xoff, SCREEN_H/2.-gui_yoff); + /* Move to the top. */ + glVertex2d( 0., density); + glVertex2d( density*SIN225, density*COS225); + glVertex2d( SCREEN_W/2.-gui_xoff, SCREEN_H/2.-gui_yoff); + glVertex2d( density*ANG45, density*ANG45); + glVertex2d( density*COS225, density*SIN225); + glVertex2d( SCREEN_W/2.-gui_xoff, SCREEN_H/2.-gui_yoff); + /* Down to the right. */ + glVertex2d( density, 0.); + glVertex2d( SCREEN_W/2.-gui_xoff, -SCREEN_H/2.-gui_yoff); + glVertex2d( density*COS225, -density*SIN225); + glVertex2d( SCREEN_W/2.-gui_xoff, -SCREEN_H/2.-gui_yoff); + glVertex2d( density*ANG45, -density*ANG45); + glVertex2d( density*SIN225, -density*COS225); + glVertex2d( SCREEN_W/2.-gui_xoff, -SCREEN_H/2.-gui_yoff); + glVertex2d( -SCREEN_W/2.-gui_xoff, -SCREEN_H/2.-gui_yoff); + /* At the bottom. */ + glVertex2d( 0., -density); + glVertex2d(-density*SIN225, -density*COS225); + glVertex2d(-SCREEN_W/2.-gui_xoff, -SCREEN_H/2.-gui_yoff); + glVertex2d(-density*ANG45, -density*ANG45); + glVertex2d(-density*COS225, -density*SIN225); + glVertex2d(-SCREEN_W/2.-gui_xoff, -SCREEN_H/2.-gui_yoff); + /* Back to origin. */ + glVertex2d(-density, 0.); + glVertex2d(-SCREEN_W/2.-gui_xoff, SCREEN_H/2.-gui_yoff); + glEnd(); /* GL_QUAD_STRIP */ + + glPopMatrix(); + + gl_checkErr(); + +#undef ANG45 +#undef COS225 +#undef SIN225 +} + /* Force generation of new nebulae. */ void nebu_forceGenerate(void) { nebu_w = nebu_h = -9; diff --git a/src/nebulae.h b/src/nebulae.h index 8355644..b32c043 100644 --- a/src/nebulae.h +++ b/src/nebulae.h @@ -1,11 +1,13 @@ #pragma once -/* Try to find nebulae to load, or generate if there isn't any. */ +/* Init/Exit. */ void nebu_init(void); - void nebu_exit(void); +/* Render. */ void nebu_render(void); +void nebu_renderOverlay(double density); +/* Misc. */ void nebu_forceGenerate(void); diff --git a/src/space.c b/src/space.c index 1c83d44..8cd20ba 100644 --- a/src/space.c +++ b/src/space.c @@ -792,8 +792,16 @@ int space_load(void) { /* Render the system. -- Just playing god now. */ void space_render(double dt) { - space_renderStars(dt); - /* nebu_render(); */ + if(cur_system->nebu_density > 0.) + nebu_render(); + else + space_renderStars(dt); +} + +/* Render the overlay. */ +void space_renderOverlay(void) { + if(cur_system->nebu_density > 0.) + nebu_renderOverlay(cur_system->nebu_density); } /* Render stars. */ diff --git a/src/space.h b/src/space.h index d094b0a..cc36881 100644 --- a/src/space.h +++ b/src/space.h @@ -81,28 +81,31 @@ typedef struct Planet_ { /* Star systems. */ typedef struct SystemFleet_ { - Fleet* fleet; /* Fleet to appear. */ - int chance; /* Chance of fleet appearing in the system. */ + Fleet* fleet; /* Fleet to appear. */ + int chance; /* Chance of fleet appearing in the system. */ } SystemFleet; typedef struct StarSystem_ { - char* name; /* Star system identifier. */ - Vec2 pos; /* Position. */ - int stars, asteroids; /* Un numero! */ - double interference; /* Un uh.. Percentage. */ + char* name; /* Star system identifier. */ + Vec2 pos; /* Position. */ + int stars, asteroids; /* Un numero! */ + double interference; /* Un uh.. Percentage. */ - int faction; /* Overall faction. */ + int faction; /* Overall faction. */ - Planet* planets; /* Planets. */ - int nplanets; /* Total number of planets. */ + Planet* planets; /* Planets. */ + int nplanets; /* Total number of planets. */ - SystemFleet* fleets; /* Fleets that can appear in the current system. */ - int nfleets; /* Total number of fleets. */ + SystemFleet* fleets; /* Fleets that can appear in the current system. */ + int nfleets; /* Total number of fleets. */ - int* jumps; /* Adjacent star system index number. */ - int njumps; /* Number of adjacent jumps. */ + int* jumps; /* Adjacent star system index number. */ + int njumps; /* Number of adjacent jumps. */ - unsigned int flags; /* Flags for system properties. */ + double nebu_density; /* Nebulae density. */ + double nebu_volatility; /* Nebulae volatility - Not used yet. */ + + unsigned int flags; /* Flags for system properties. */ } StarSystem; extern StarSystem* cur_system; /* Current star system. */ @@ -118,6 +121,7 @@ Planet* planet_get(char* planetname); /* Render. */ void space_render(double dt); +void space_renderOverlay(void); void planets_render(void); /* Update. */