Object loading patch
[crack-attack.git] / src / obj_block.cxx
blob4e55d3256c08e46ccb7da29c668d44785ca5e9a9
1 /*
2 * block.cxx
3 * Daniel Nelson - 8/31/0
5 * Copyright (C) 2006 Bjørn Lindeijer
6 * Copyright (C) 2000 Daniel Nelson
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * Daniel Nelson - aluminumangel.org
23 * 174 W. 18th Ave.
24 * Columbus, OH 43210
26 * Generates the block's two display lists.
29 #include <GL/glut.h>
31 #include "glext.h"
33 #include <cstring>
35 #include "Game.h"
36 #include "Displayer.h"
37 #include "OBJModel.h"
39 GLuint Displayer::block_list;
40 GLuint Displayer::small_block_list;
41 GLuint Displayer::special_block_list;
43 GLuint Displayer::special_block_lightmap;
45 void Displayer::generateBlockDisplayList ( )
47 OBJModel *block_model = NULL;
48 OBJModel *block_model_tex = NULL;
50 if (MetaState::mode & CM_LOW_GRAPHICS) {
51 block_model = new OBJModel(GC_MODEL_DIRECTORY("crackattackcubemedres.obj"));
52 block_model_tex = new OBJModel(GC_MODEL_DIRECTORY("crackattackcubemedres_tex.obj"));
53 } else {
54 block_model = new OBJModel(GC_MODEL_DIRECTORY("crackattackcubehires.obj"));
55 block_model_tex = new OBJModel(GC_MODEL_DIRECTORY("crackattackcubehires_tex.obj"));
57 block_list = glGenLists(1);
58 glNewList(block_list, GL_COMPILE);
59 block_model->render();
60 glEndList();
62 // Now let's make one for pulsing blocks (has texture coordinates)
64 special_block_list = glGenLists(1);
65 glNewList(special_block_list, GL_COMPILE);
66 block_model_tex->render();
67 glEndList();
69 delete block_model;
70 delete block_model_tex;
72 // Now let's make one at half that size and rotated
74 small_block_list = glGenLists(1);
75 glNewList(small_block_list, GL_COMPILE);
76 glPushMatrix();
77 glRotatef(45.0f, 1.0f, 0.0f, 0.0f);
78 glRotatef(45.0f, 0.0f, 1.0f, 0.0f);
79 glScalef(0.5f, 0.5f, 0.5f);
80 glEnable(GL_NORMALIZE);
81 glCallList(block_list);
82 glDisable(GL_NORMALIZE);
83 glPopMatrix();
84 glEndList();
86 // Now we build the special color blocks' gleam texture. A texture value of
87 // 0.6f seems to cause the special color blocks to match their standard
88 // siblings, given the specials' double color values.
90 GLubyte texture[32];
91 for (int n = 32; n--; )
92 texture[n]
93 = (GLubyte) (255.0f * (0.8f - 0.2f * cos((2.0f * PI / 32.0f) * n)));
95 glGenTextures(1, &special_block_lightmap);
97 glBindTexture(GL_TEXTURE_1D, special_block_lightmap);
99 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
100 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
101 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
103 const GLubyte* renderer = glGetString(GL_RENDERER);
104 if (strstr((char*) renderer, "DRI 20020221 Voodoo3")) {
105 cerr << "**********\nWARNING:"
106 "disabling call to 1d texturing on DRI 20020221 Voodoo3 renderer "
107 "since it segfaults\n**********" << endl;
108 delete[] tex_coords;
109 return;
111 if (strstr((char*) renderer, "865G 20021115")) {
112 cerr << "**********\nWARNING:"
113 "disabling call to 1d texturing on 865G 20021115 renderer "
114 "since it segfaults\n**********" << endl;
115 delete[] tex_coords;
116 return;
119 glTexImage1D(GL_TEXTURE_1D, 0, GL_LUMINANCE, 32, GL_FALSE, GL_LUMINANCE,
120 GL_UNSIGNED_BYTE, texture);
121 delete[] tex_coords;