dungeon_crawler
view prototype/src/renderer.cc @ 46:f3030df27110
debugging the particles
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Thu, 13 Sep 2012 06:33:51 +0300 |
parents | c45c42c3d32e |
children | d57df51f6b50 |
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 glUseProgram(sdrprog);
90 glEnable(GL_LIGHTING);
91 level->draw();
93 glUseProgram(0);
94 level->draw_post();
96 glPopAttrib();
97 }
99 static unsigned int load_sdr(const char *vfname, const char *pfname)
100 {
101 char vsfile[PATH_MAX], psfile[PATH_MAX];
102 const char *fname;
103 unsigned int prog;
105 if((fname = datafile_path(vfname))) {
106 strcpy(vsfile, fname);
107 } else {
108 vsfile[0] = 0;
109 }
110 if((fname = datafile_path(pfname))) {
111 strcpy(psfile, fname);
112 } else {
113 psfile[0] = 0;
114 }
115 if(!(prog = create_program_load(vsfile, psfile))) {
116 fprintf(stderr, "failed to load shader program (%s, %s)\n", vsfile, psfile);
117 return 0;
118 }
119 return prog;
120 }