Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/nico/src/heightMap/heightMapTerrain.cpp @ 3381

Last change on this file since 3381 was 3381, checked in by nico, 19 years ago

developing heightMap

File size: 2.6 KB
Line 
1/*
2 *  ldrawparser.cpp
3 *  legotown3d
4 *
5 *  Created by Nico Bernold on 08.01.05.
6 *  Copyright 2005 __MyCompanyName__. All rights reserved.
7 *
8 */
9
10#include "heightMapTerrain.h"
11
12HeightMapTerrain::HeightMapTerrain()
13{       
14}
15
16HeightMapTerrain::~HeightMapTerrain()
17{
18}
19
20bool HeightMapTerrain::loadBitmap(char* fileName)
21{
22        return bitmap = SDL_LoadBMP(fileName); 
23}
24
25bool HeightMapTerrain::createDisplayLists(int width, int height, int levelOfDetail)
26{
27        if (bitmap == NULL) return false;
28       
29        cout << "bitmap-dimensions: " << bitmap->w << "x" << bitmap->h << endl;
30       
31        if (bitmap->w % width != 0) return false;
32        if (bitmap->h % height != 0) return false;
33       
34        if (levelOfDetail < 1 || levelOfDetail > 10) return false;
35       
36        int howManyListsWide = bitmap->w / width;
37        int howManyListsHigh = bitmap->h / height;
38       
39        // calculate how many displayLists we'll create
40        displayListCount = howManyListsWide * howManyListsHigh; 
41
42        cout << "lists-information: " << howManyListsWide << " * " << howManyListsHigh << " = " << displayListCount << " display lists." << endl;
43       
44        displayListStart = glGenLists(displayListCount);
45        if (displayListStart == 0)
46        {
47                cout << "could not generate " << displayListCount << " display lists. exiting. " << endl;
48                return false;
49        }
50
51        int i,j;
52       
53        for (i=0; i<howManyListsHigh; i++)
54        {
55                for (j=0; j<howManyListsWide; j++)
56                {
57                        if (readIntoList(j*width,i*height,width,height,levelOfDetail,i*howManyListsHigh + j) == false)
58                        {
59                                cout << "error while generating display lists. exiting. " << endl;
60                                return false;
61                        }
62
63                }
64        }
65       
66        return true;
67}
68
69bool HeightMapTerrain::readIntoList(int left, int top, int width, int height, int levelOfDetail, GLuint displayListNr)
70{
71        // y is the height value in OpenGL convention
72        GLuint x,y,z;
73        GLfloat col;
74       
75        cout << "creating list Nr " << displayListNr << endl;
76        cout << "left, top, width, height: " << left << ", " << top << ", " << width << ", " << height << endl; 
77       
78        glNewList(displayListNr,GL_COMPILE);
79        {
80                for (z=top; z<top+height; z++)
81                {
82                        glBegin(GL_QUAD_STRIP);
83                        {
84                                for (x=left; x<left+width; x++)
85                                {
86                                        y = heightValue(x,z+1);
87                                        col = y / 256.0;
88                                        glColor3f(1.0,0.0,0.0);
89                                        glVertex3i(x,y,z+1);
90                                       
91                                        y = heightValue(x,z);
92                                        col = y / 256.0;
93                                        glColor3f(1.0,0.0,0.0);
94                                        glVertex3i(x,y,z);
95                                }
96                        }
97                        glEnd();
98                }
99               
100        }
101        glEndList();
102       
103        return true;
104}
105
106GLint HeightMapTerrain::heightValue(Uint8 x, Uint8 z)
107{
108        return 100;
109       
110        /*
111        if (bitmap == NULL) return 0;
112       
113        Uint8 index;
114        SDL_Color* color = NULL;
115       
116       
117        SDL_LockSurface(bitmap);
118       
119        index = *((Uint8*)bitmap->pixels[z * bitmap->h + x]);
120        color = &bitmap->format->palette->colors[index];
121       
122        SDL_UnlockSurface(bitmap);
123
124        return color->r;
125         */
126}
Note: See TracBrowser for help on using the repository browser.