26#define NEBULA_PUFF_BUFFER 300
38static int nebu_dofbo = 0;
39static GLuint nebu_fbo = GL_INVALID_VALUE;
40static GLuint nebu_tex = GL_INVALID_VALUE;
41static GLfloat nebu_render_w= 0.;
42static GLfloat nebu_render_h= 0.;
43static mat4 nebu_render_P;
50typedef struct NebulaPuff_ {
59static double puff_x = 0.;
60static double puff_y = 0.;
95 if (scale ==
nebu_scale && fbo_w == nebu_render_w && fbo_h == nebu_render_h)
99 nebu_render_w = fbo_w;
100 nebu_render_h = fbo_h;
102 glDeleteTextures( 1, &nebu_tex );
103 glDeleteFramebuffers( 1, &nebu_fbo );
106 gl_fboCreate( &nebu_fbo, &nebu_tex, nebu_render_w, nebu_render_h );
110 mat4_translate( &nebu_render_P, -nebu_render_w/2., -nebu_render_h/2., 0. );
111 mat4_scale( &nebu_render_P, nebu_render_w, nebu_render_h, 1. );
112 glUseProgram(shaders.nebula_background.program);
113 gl_uniformMat4(shaders.nebula_background.projection, &nebu_render_P);
114 glUseProgram(shaders.nebula.program);
115 gl_uniformMat4(shaders.nebula.projection, &nebu_render_P);
137 glDeleteFramebuffers( 1, &nebu_fbo );
138 glDeleteTextures( 1, &nebu_tex );
164 glBindFramebuffer(GL_FRAMEBUFFER, nebu_fbo);
165 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
169 glUseProgram(shaders.nebula_background.program);
173 glUniform1f(shaders.nebula_background.time,
nebu_time);
177 glEnableVertexAttribArray( shaders.nebula_background.vertex );
179 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
183 glDisableVertexAttribArray( shaders.nebula_background.vertex );
198 glUseProgram(shaders.texture.program);
200 glBindTexture( GL_TEXTURE_2D, nebu_tex );
202 glEnableVertexAttribArray( shaders.texture.vertex );
207 gl_uniformColour(shaders.texture.colour, &cWhite);
211 gl_uniformMat4( shaders.texture.projection, &ortho );
212 gl_uniformMat4( shaders.texture.tex_mat, &I );
215 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
218 glDisableVertexAttribArray( shaders.texture.vertex );
289 glBindFramebuffer(GL_FRAMEBUFFER, nebu_fbo);
290 glClearColor( 0., 0., 0., 0. );
291 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
295 glUseProgram(shaders.nebula.program);
300 glUniform1f(shaders.nebula.time,
nebu_time);
304 glEnableVertexAttribArray(shaders.nebula.vertex);
306 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
310 glDisableVertexAttribArray( shaders.nebula.vertex );
311 glClearColor( 0., 0., 0., 1. );
337 if ((!below_player && (puff->
height < 1.)) ||
338 (below_player && (puff->
height > 1.)))
346 if ((x < -s) || (x > SCREEN_W+s) ||
347 (y < -s) || (y > SCREEN_H+s))
351 glUseProgram( shaders.nebula_puff.program );
353 projection = gl_view_matrix;
356 glEnableVertexAttribArray(shaders.nebula_puff.vertex);
360 gl_uniformMat4( shaders.nebula_puff.projection, &projection );
361 glUniform1f( shaders.nebula_puff.time,
nebu_time / 1.5 );
362 glUniform2f( shaders.nebula_puff.r, puff->
rx, puff->
ry );
364 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
366 glDisableVertexAttribArray(shaders.nebula_puff.vertex);
379void nebu_prep(
double density,
double volatility,
double hue )
385 glUseProgram(shaders.nebula.program);
386 glUniform1f(shaders.nebula.hue,
nebu_hue);
387 glUseProgram(shaders.nebula_background.program);
388 glUniform1f(shaders.nebula_background.hue,
nebu_hue);
389 glUniform1f(shaders.nebula_background.volatility, volatility);
393 glUseProgram(shaders.trail.program);
394 glUniform3f( shaders.trail.nebu_col, col.r, col.g, col.b );
398 glUseProgram(shaders.nebula_puff.program);
399 glUniform3f( shaders.nebula_puff.nebu_col, col.r, col.g, col.b );
407 nebu_dt = (2.*density + 200.) / 10e3;
408 nebu_dx = 15e3 / pow(density, 1./3.);
422 np->
height = RNGF() + 0.2;
425 np->
rx = RNGF()*2000.-1000.;
426 np->
ry = RNGF()*2000.-1000.;
void cam_getDPos(double *dx, double *dy)
Gets the camera position differential (change in last frame).
double cam_getZoom(void)
Gets the camera zoom.
void col_hsv2rgb(glColour *c, float h, float s, float v)
Changes colour space from HSV to RGB.
void gui_getOffset(double *x, double *y)
Gets the GUI offset.
void mat4_translate(mat4 *m, double x, double y, double z)
Translates a homogenous transformation matrix.
mat4 mat4_identity(void)
Creates an identity matrix.
void mat4_scale(mat4 *m, double x, double y, double z)
Scales a homogeneous transformation matrix.
mat4 mat4_ortho(double left, double right, double bottom, double top, double nearVal, double farVal)
Creates an orthographic projection matrix.
Header file with generic functions and naev-specifics.
void nebu_update(double dt)
Updates visibility and stuff.
void nebu_exit(void)
Cleans up the nebu subsystem.
static NebulaPuff * nebu_puffs
int nebu_resize(void)
Handles a screen s.
#define NEBULA_PUFF_BUFFER
static void nebu_renderPuffs(int below_player)
Renders the puffs.
void nebu_renderOverlay(const double dt)
Renders the nebula overlay (hides what player can't see).
double nebu_getSightRadius(void)
Gets the nebula view radius.
void nebu_render(const double dt)
Renders the nebula.
static void nebu_blitFBO(void)
If we're drawing the nebula buffered, copy to the screen.
static double nebu_density
void nebu_prep(double density, double volatility, double hue)
Prepares the nebualae to be rendered.
int nebu_init(void)
Initializes the nebula.
static void nebu_renderBackground(const double dt)
Renders the nebula using the multitexture approach.
int gl_fboCreate(GLuint *fbo, GLuint *tex, GLsizei width, GLsizei height)
Creates a framebuffer and its associated texture.
void gl_vboActivateAttribOffset(gl_vbo *vbo, GLuint index, GLuint offset, GLint size, GLenum type, GLsizei stride)
Activates a VBO's offset.
int space_isSimulation(void)
returns whether we're just simulating.
Represents a nebula puff.
double nebu_nonuniformity