dungeon_crawler

view prototype/src/renderer.cc @ 61:4472ef41a209

forgot an extra mrt uniform in deferred_omni.p.glsl
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 25 Sep 2012 06:37:56 +0300
parents f3030df27110
children f71381c9e245
line source
1 #include <limits.h>
2 #include "opengl.h"
3 #include "renderer.h"
4 #include "level.h"
5 #include "sdr.h"
6 #include "datapath.h"
8 static unsigned int load_sdr(const char *vfname, const char *pfname);
10 Renderer *rend;
13 Renderer::Renderer()
14 {
15 width = height = 0;
16 }
18 Renderer::~Renderer()
19 {
20 }
22 bool Renderer::init(int xsz, int ysz)
23 {
24 width = xsz;
25 height = ysz;
27 rend = this;
28 return true;
29 }
31 int Renderer::get_tangent_location() const
32 {
33 return -1;
34 }
36 unsigned int Renderer::get_current_program() const
37 {
38 return 0;
39 }
41 void Renderer::resize(int xsz, int ysz)
42 {
43 width = xsz;
44 height = ysz;
45 }
48 // ---- fallback forward renderer ----
49 FwdRenderer::FwdRenderer()
50 {
51 sdrprog = 0;
52 tang_attr = -1;
53 }
55 FwdRenderer::~FwdRenderer()
56 {
57 if(sdrprog) {
58 free_program(sdrprog);
59 }
60 }
62 bool FwdRenderer::init(int xsz, int ysz)
63 {
64 width = xsz;
65 height = ysz;
67 if(glUseProgram && (sdrprog = load_sdr("fallback.v.glsl", "fallback.p.glsl"))) {
68 tang_attr = get_attrib_loc(sdrprog, "attr_tangent");
69 set_uniform_int(sdrprog, "tex_dif", 0);
70 set_uniform_int(sdrprog, "tex_norm", 1);
71 }
72 return true;
73 }
75 int FwdRenderer::get_tangent_location() const
76 {
77 return tang_attr;
78 }
80 unsigned int FwdRenderer::get_current_program() const
81 {
82 return sdrprog;
83 }
85 void FwdRenderer::render(const Level *level) const
86 {
87 glPushAttrib(GL_ENABLE_BIT);
88 glEnable(GL_LIGHTING);
89 glEnable(GL_FOG);
90 glFogi(GL_FOG_MODE, GL_LINEAR);
91 glFogf(GL_FOG_START, 3.0f);
92 glFogf(GL_FOG_END, 6.0f);
94 glUseProgram(sdrprog);
96 level->draw();
98 glUseProgram(0);
99 level->draw_post();
101 glPopAttrib();
102 }
104 static unsigned int load_sdr(const char *vfname, const char *pfname)
105 {
106 char vsfile[PATH_MAX], psfile[PATH_MAX];
107 const char *fname;
108 unsigned int prog;
110 if((fname = datafile_path(vfname))) {
111 strcpy(vsfile, fname);
112 } else {
113 vsfile[0] = 0;
114 }
115 if((fname = datafile_path(pfname))) {
116 strcpy(psfile, fname);
117 } else {
118 psfile[0] = 0;
119 }
120 if(!(prog = create_program_load(vsfile, psfile))) {
121 fprintf(stderr, "failed to load shader program (%s, %s)\n", vsfile, psfile);
122 return 0;
123 }
124 return prog;
125 }