- Timestamp:
- Jun 29, 2010, 8:53:30 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile
r18 r20 11 11 12 12 clean: 13 rm -f test-map13 rm -f *.o test-map 14 14 -
trunk/src/test-map.cpp
r18 r20 16 16 #include <SDL_image.h> 17 17 18 #include <stdio.h> 18 19 #include <math.h> 19 20 … … 25 26 /* Storage for 3 vertex buffers */ 26 27 GLuint buflist[3]; 28 29 /* Storage for map layers */ 30 int *layers[128]; 31 int width = 32, height = 32; 32 int nlayers = 0; 27 33 28 34 // Load Bitmaps And Convert To Textures … … 52 58 } 53 59 54 void PutMap(int const *themap) 60 void LoadMap(void) 61 { 62 FILE *fp = popen("grep '^ ' maps/testmap.tmx | while read i; do echo -n \"$i\" | perl -MMIME::Base64 -ne 'print decode_base64($_)' | gunzip; done", "r"); 63 while (fp && !feof(fp)) 64 { 65 layers[nlayers] = (int *)malloc(width * height * sizeof(int)); 66 fread(layers[nlayers], sizeof(int), width * height, fp); 67 if (feof(fp)) 68 { 69 free(layers[nlayers]); 70 layers[nlayers] = 0; 71 fclose(fp); 72 break; 73 } 74 for (int n = 0; n < width * height; n++) 75 { 76 unsigned int i = layers[nlayers][n]; 77 //i = (i >> 24) | ((i >> 8) & 0xff00) | ((i << 8) & 0xff0000) | (i << 24); 78 layers[nlayers][n] = i ? i - 1 : 0; 79 } 80 nlayers++; 81 } 82 } 83 84 void PutMap(int const *themap, int width, int height) 55 85 { 56 86 // Put map 57 float uvs[8 * 20 * 15];58 59 for (int y = 0; y < 15; y++)60 for (int x = 0; x < 20; x++)61 { 62 int tile = themap[ 20* y + x];87 float uvs[8 * width * height]; 88 89 for (int y = 0; y < height; y++) 90 for (int x = 0; x < width; x++) 91 { 92 int tile = themap[width * y + x]; 63 93 float ty = .0625f * (tile / 16); 64 94 float tx = .0625f * (tile % 16); 65 uvs[8 * ( 20* y + x) + 0] = tx;66 uvs[8 * ( 20* y + x) + 1] = ty;67 uvs[8 * ( 20* y + x) + 2] = tx + .0625f;68 uvs[8 * ( 20* y + x) + 3] = ty;69 uvs[8 * ( 20* y + x) + 4] = tx + .0625f;70 uvs[8 * ( 20* y + x) + 5] = ty + .0625f;71 uvs[8 * ( 20* y + x) + 6] = tx;72 uvs[8 * ( 20* y + x) + 7] = ty + .0625f;95 uvs[8 * (width * y + x) + 0] = tx; 96 uvs[8 * (width * y + x) + 1] = ty; 97 uvs[8 * (width * y + x) + 2] = tx + .0625f; 98 uvs[8 * (width * y + x) + 3] = ty; 99 uvs[8 * (width * y + x) + 4] = tx + .0625f; 100 uvs[8 * (width * y + x) + 5] = ty + .0625f; 101 uvs[8 * (width * y + x) + 6] = tx; 102 uvs[8 * (width * y + x) + 7] = ty + .0625f; 73 103 } 74 104 glBindBuffer(GL_ARRAY_BUFFER, buflist[1]); 75 105 glBufferData(GL_ARRAY_BUFFER, 76 8 * 20 * 15* sizeof(float), uvs, GL_STATIC_DRAW);77 78 float vertices[8 * 20 * 15];79 for (int y = 0; y < 15; y++)80 for (int x = 0; x < 20; x++)81 { 82 vertices[8 * ( 20* y + x) + 0] = x * 32;83 vertices[8 * ( 20* y + x) + 1] = y * 32;84 vertices[8 * ( 20* y + x) + 2] = x * 32 + 32;85 vertices[8 * ( 20* y + x) + 3] = y * 32;86 vertices[8 * ( 20* y + x) + 4] = x * 32 + 32;87 vertices[8 * ( 20* y + x) + 5] = y * 32 + 32;88 vertices[8 * ( 20* y + x) + 6] = x * 32;89 vertices[8 * ( 20* y + x) + 7] = y * 32 + 32;106 8 * width * height * sizeof(float), uvs, GL_STATIC_DRAW); 107 108 float vertices[8 * width * height]; 109 for (int y = 0; y < height; y++) 110 for (int x = 0; x < width; x++) 111 { 112 vertices[8 * (width * y + x) + 0] = x * 32; 113 vertices[8 * (width * y + x) + 1] = y * 32; 114 vertices[8 * (width * y + x) + 2] = x * 32 + 32; 115 vertices[8 * (width * y + x) + 3] = y * 32; 116 vertices[8 * (width * y + x) + 4] = x * 32 + 32; 117 vertices[8 * (width * y + x) + 5] = y * 32 + 32; 118 vertices[8 * (width * y + x) + 6] = x * 32; 119 vertices[8 * (width * y + x) + 7] = y * 32 + 32; 90 120 } 91 121 glBindBuffer(GL_ARRAY_BUFFER, buflist[0]); 92 122 glBufferData(GL_ARRAY_BUFFER, 93 8 * 20 * 15* sizeof(float), vertices, GL_STATIC_DRAW);94 95 int indices[4 * 20 * 15];96 for (int n = 0; n < 4 * 20 * 15; n++)123 8 * width * height * sizeof(float), vertices, GL_STATIC_DRAW); 124 125 int indices[4 * width * height]; 126 for (int n = 0; n < 4 * width * height; n++) 97 127 indices[n] = n; 98 128 glBindBuffer(GL_ARRAY_BUFFER, buflist[2]); 99 129 glBufferData(GL_ARRAY_BUFFER, 100 4 * 20 * 15* sizeof(int), indices, GL_STATIC_DRAW);130 4 * width * height * sizeof(int), indices, GL_STATIC_DRAW); 101 131 102 132 glEnableClientState(GL_VERTEX_ARRAY); … … 113 143 glIndexPointer(GL_INT, 0, NULL); 114 144 115 glDrawArrays(GL_QUADS, 0, 4 * 20 * 15);145 glDrawArrays(GL_QUADS, 0, 4 * width * height); 116 146 117 147 glDisableClientState(GL_VERTEX_ARRAY); … … 123 153 void DrawScene() 124 154 { 155 /* 125 156 int ground[20 * 15] = 126 157 { … … 152 183 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 153 184 0, 0, 0, 0, 49, 49, 49, 49, 49, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 154 0, 0, 0, 0, 0, 49, 49, 49, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,155 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, 32, 49, 0, 0, 0,156 0, 0, 0, 49, 49, 32, 0, 50, 0, 0, 0, 48, 0, 64, 0, 49, 49, 0, 0, 0,157 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0,158 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0,159 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,185 0, 0, 0, 0, 0, 49, 49, 49, 49, 0, 0, 0, 0, 25, 9, 9, 9, 8, 0, 0, 186 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 54, 40, 39, 39, 41, 0, 0, 187 0, 0, 0, 49, 49, 32, 0, 50, 0, 0, 0, 48, 0, 24, 23, 54, 40, 55, 0, 0, 188 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 64, 0, 24, 23, 24, 23, 7, 0, 0, 189 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 38, 24, 23, 7, 0, 0, 190 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 38, 22, 0, 0, 160 191 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 161 192 }; 193 */ 162 194 163 195 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 164 196 glLoadIdentity(); 165 197 166 PutMap(ground); 167 //glTranslatef(10.0f * sinf(0.16f * frames), 10.0f * cosf(0.16f * frames), 0.0f); 168 PutMap(l1objects); 198 for (int i = 0; i < nlayers; i++) 199 PutMap(layers[i], width, height); 169 200 } 170 201 … … 178 209 LoadGLTextures(); 179 210 MakeVBOs(); 211 LoadMap(); 180 212 181 213 done = 0;
Note: See TracChangeset
for help on using the changeset viewer.