rayzor
changeset 5:5fcf72837b69
fixed the dosemu bit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 06 Apr 2014 02:43:24 +0300 |
parents | 18bdbcbaee81 |
children | a68dbf80d547 |
files | .clang_complete .hgignore GNUmakefile src/dosemu/dosemu.c src/gfx.c src/gfx.h src/m3dimpl.h src/m3drast.c src/main.cc src/min3d.c src/min3d.h src/object.cc src/scene.cc |
diffstat | 13 files changed, 580 insertions(+), 12 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/.clang_complete Sun Apr 06 02:43:24 2014 +0300 1.3 @@ -0,0 +1,3 @@ 1.4 +-Isrc 1.5 +-Isrc/stl 1.6 +-Isrc/dosemu
2.1 --- a/.hgignore Sun Apr 06 01:12:50 2014 +0300 2.2 +++ b/.hgignore Sun Apr 06 02:43:24 2014 +0300 2.3 @@ -1,4 +1,5 @@ 2.4 \.o$ 2.5 +\.d$ 2.6 \.swp$ 2.7 \.obj$ 2.8 \.exe$
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/GNUmakefile Sun Apr 06 02:43:24 2014 +0300 3.3 @@ -0,0 +1,34 @@ 3.4 +modelobj = src/main.o src/min3d.o src/m3drast.o src/logger.o 3.5 +rendobj = src/rend.o src/vmath.o 3.6 +scnobj = src/scene.o src/object.o 3.7 +sysobj = src/dosemu/dosemu.o 3.8 +obj = $(modelobj) $(rendobj) $(scnobj) $(sysobj) 3.9 +dep = $(obj:.o=.d) 3.10 +bin = rayzor 3.11 + 3.12 +dbg = -g 3.13 +#opt = -O3 -ffast-math 3.14 +inc = -Isrc -Isrc/stl -Isrc/dosemu 3.15 + 3.16 +CFLAGS = -pedantic -Wall $(dbg) $(opt) `pkg-config --cflags sdl` $(inc) 3.17 +CXXFLAGS = $(CFLAGS) 3.18 +LDFLAGS = `pkg-config --libs sdl` -lm 3.19 + 3.20 +$(bin): $(obj) 3.21 + $(CXX) -o $@ $(obj) $(LDFLAGS) 3.22 + 3.23 +-include $(dep) 3.24 + 3.25 +%.d: %.c 3.26 + @$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@ 3.27 + 3.28 +%.d: %.cc 3.29 + @$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@ 3.30 + 3.31 +.PHONY: clean 3.32 +clean: 3.33 + rm -f $(obj) $(bin) 3.34 + 3.35 +.PHONY: cleandep 3.36 +cleandep: 3.37 + rm -f $(dep)
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/src/dosemu/dosemu.c Sun Apr 06 02:43:24 2014 +0300 4.3 @@ -0,0 +1,463 @@ 4.4 +/* This file implements all calls made to dos-specific code using SDL */ 4.5 +#include <stdlib.h> 4.6 +#include <assert.h> 4.7 +#include <SDL/SDL.h> 4.8 +#ifdef DOSEMU_CAPTURE 4.9 +#include <imago2.h> 4.10 +#endif 4.11 +#include "gfx.h" 4.12 +#include "mouse.h" 4.13 +#include "keyb.h" 4.14 +#include "timer.h" 4.15 + 4.16 +static void proc_events(void); 4.17 +static void capture_frame(unsigned char *frame); 4.18 + 4.19 +static void init_sdl() 4.20 +{ 4.21 + const SDL_version *ver; 4.22 + 4.23 + if(!SDL_WasInit(SDL_INIT_EVERYTHING)) { 4.24 + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); 4.25 + 4.26 + if((ver = SDL_Linked_Version())) { 4.27 + printf("SDL %d.%d.%d initialized\n", ver->major, ver->minor, ver->patch); 4.28 + } 4.29 + } 4.30 +} 4.31 + 4.32 +/* ----- graphics (gfx.c (vbe) implementation) ----- */ 4.33 +static SDL_Surface *fbsurf; 4.34 +static int scale = 1; 4.35 +static int frames_to_capture; 4.36 + 4.37 +static struct { 4.38 + unsigned char r, g, b; 4.39 +} palette[256]; 4.40 + 4.41 + 4.42 +void *set_video_mode(int xsz, int ysz, int bpp) 4.43 +{ 4.44 + unsigned int sdl_flags = bpp <= 8 ? SDL_HWPALETTE : 0; 4.45 + char *env; 4.46 + 4.47 + if(getenv("DOSEMU_DOUBLESIZE")) { 4.48 + scale = 2; 4.49 + } 4.50 + 4.51 + if((env = getenv("DOSEMU_SCALE"))) { 4.52 + int n = atoi(env); 4.53 + if(n > 0) { 4.54 + scale = n; 4.55 + } 4.56 + } 4.57 + xsz *= scale; 4.58 + ysz *= scale; 4.59 + 4.60 + if(getenv("DOSEMU_FULLSCREEN")) { 4.61 + sdl_flags |= SDL_FULLSCREEN; 4.62 + } 4.63 + 4.64 + init_sdl(); 4.65 + 4.66 + if(!(fbsurf = SDL_SetVideoMode(xsz, ysz, bpp, sdl_flags))) { 4.67 + fprintf(stderr, "failed to set video mode\n"); 4.68 + abort(); 4.69 + } 4.70 + SDL_WM_SetCaption("Rayzor", 0); 4.71 + /*SDL_ShowCursor(0);*/ 4.72 + 4.73 + return fbsurf->pixels; 4.74 +} 4.75 + 4.76 +int set_text_mode(void) 4.77 +{ 4.78 + SDL_ShowCursor(1); 4.79 + SDL_EnableKeyRepeat(0, 0); 4.80 + SDL_Quit(); 4.81 + return 0; 4.82 +} 4.83 + 4.84 +int get_color_depth(void) 4.85 +{ 4.86 + return fbsurf->format->BitsPerPixel; 4.87 +} 4.88 + 4.89 +static int count_bits(unsigned int x) 4.90 +{ 4.91 + int i, count = 0; 4.92 + for(i=0; i<32; i++) { 4.93 + if(x & 1) { 4.94 + count++; 4.95 + } 4.96 + x >>= 1; 4.97 + } 4.98 + return count; 4.99 +} 4.100 + 4.101 +int get_color_bits(int *rbits, int *gbits, int *bbits) 4.102 +{ 4.103 + *rbits = count_bits(fbsurf->format->Rmask); 4.104 + *gbits = count_bits(fbsurf->format->Gmask); 4.105 + *bbits = count_bits(fbsurf->format->Bmask); 4.106 + return *rbits + *gbits + *bbits; 4.107 +} 4.108 + 4.109 +int get_color_shift(int *rshift, int *gshift, int *bshift) 4.110 +{ 4.111 + *rshift = fbsurf->format->Rshift; 4.112 + *gshift = fbsurf->format->Gshift; 4.113 + *bshift = fbsurf->format->Bshift; 4.114 + return 0; 4.115 +} 4.116 + 4.117 +int get_color_mask(unsigned int *rmask, unsigned int *gmask, unsigned int *bmask) 4.118 +{ 4.119 + *rmask = fbsurf->format->Rmask; 4.120 + *gmask = fbsurf->format->Gmask; 4.121 + *bmask = fbsurf->format->Bmask; 4.122 + return 0; 4.123 +} 4.124 + 4.125 + 4.126 +void set_palette(int idx, int r, int g, int b) 4.127 +{ 4.128 + SDL_Color col; 4.129 + col.r = r; 4.130 + col.g = g; 4.131 + col.b = b; 4.132 + 4.133 + if(SDL_SetPalette(fbsurf, SDL_LOGPAL | SDL_PHYSPAL, &col, idx, 1) != 1) { 4.134 + fprintf(stderr, "set_palette failed to set the required color\n"); 4.135 + } 4.136 + 4.137 + palette[idx].r = r; 4.138 + palette[idx].g = g; 4.139 + palette[idx].b = b; 4.140 +} 4.141 + 4.142 +static int copy_frame_called; 4.143 + 4.144 +void copy_frame(void *pixels) 4.145 +{ 4.146 + unsigned char *frame = (unsigned char*)pixels; 4.147 + copy_frame_called = 1; 4.148 + 4.149 + if(SDL_MUSTLOCK(fbsurf)) { 4.150 + SDL_LockSurface(fbsurf); 4.151 + } 4.152 + 4.153 + if(pixels) { 4.154 + if(scale > 1) { 4.155 + int i, j, xsz, ysz; 4.156 + unsigned char *dest = fbsurf->pixels; 4.157 + 4.158 + xsz = fbsurf->w * scale; 4.159 + ysz = fbsurf->h * scale; 4.160 + 4.161 + for(i=0; i<ysz; i++) { 4.162 + for(j=0; j<xsz; j++) { 4.163 + *dest++ = frame[(i / scale) * fbsurf->w + (j / scale)]; 4.164 + } 4.165 + } 4.166 + } else { 4.167 + int num_pixels = fbsurf->w * fbsurf->h; 4.168 + memcpy(fbsurf->pixels, frame, num_pixels * fbsurf->format->BytesPerPixel); 4.169 + } 4.170 + } 4.171 + 4.172 + if(SDL_MUSTLOCK(fbsurf)) { 4.173 + SDL_UnlockSurface(fbsurf); 4.174 + } 4.175 + 4.176 + SDL_Flip(fbsurf); 4.177 + 4.178 + if(frames_to_capture > 0) { 4.179 + capture_frame(pixels); 4.180 + --frames_to_capture; 4.181 + } 4.182 + 4.183 + /* also print fps every second ... */ 4.184 + { 4.185 + static long prev_fps, num_frames; 4.186 + long msec, dt; 4.187 + 4.188 + msec = get_msec(); 4.189 + dt = msec - prev_fps; 4.190 + if(dt >= 1000) { 4.191 + float fps = (float)num_frames / ((float)dt / 1000.0f); 4.192 + printf("framerate: %.1f \r", fps); 4.193 + fflush(stdout); 4.194 + num_frames = 0; 4.195 + prev_fps = msec; 4.196 + } else { 4.197 + num_frames++; 4.198 + } 4.199 + } 4.200 +} 4.201 + 4.202 +#define spin_delay(ms) \ 4.203 + do { \ 4.204 + unsigned int end = SDL_GetTicks() + ms; \ 4.205 + while((prev_msec = SDL_GetTicks()) < end); \ 4.206 + } while(0) 4.207 + 4.208 +#define FRAME_INTERVAL (1000/70) 4.209 + 4.210 +void wait_vsync(void) 4.211 +{ 4.212 + static int prev_msec; 4.213 + int msec, dt, tleft; 4.214 + 4.215 + if(!copy_frame_called) { 4.216 + copy_frame(0); 4.217 + copy_frame_called = 0; 4.218 + } 4.219 + 4.220 + msec = SDL_GetTicks(); 4.221 + 4.222 + dt = msec - prev_msec; 4.223 + 4.224 + tleft = FRAME_INTERVAL - dt; 4.225 + if(tleft > 0) { 4.226 + int coarse = tleft & 0xfffffff8; 4.227 + tleft = tleft & 7; 4.228 + 4.229 + if(coarse) { 4.230 + SDL_Delay(coarse); 4.231 + } 4.232 + if(tleft) { 4.233 + spin_delay(tleft); 4.234 + } else { 4.235 + prev_msec = SDL_GetTicks(); 4.236 + } 4.237 + } else { 4.238 + prev_msec = msec; 4.239 + } 4.240 +} 4.241 + 4.242 +static int cap_count = 0; 4.243 +void begin_capture(int frames) 4.244 +{ 4.245 + frames_to_capture = frames; 4.246 +} 4.247 + 4.248 +void end_capture(void) 4.249 +{ 4.250 + cap_count = 0; 4.251 + frames_to_capture = 0; 4.252 +} 4.253 + 4.254 +#define NUMPIX (fbsurf->w * fbsurf->h) 4.255 +static void capture_frame(unsigned char *frame) 4.256 +{ 4.257 +#ifdef DOSEMU_CAPTURE 4.258 + static unsigned char rgbpix[NUMPIX * 4]; 4.259 + char fname[32]; 4.260 + int i; 4.261 + unsigned char *src, *dest; 4.262 + 4.263 + sprintf(fname, "frame%04d.png", cap_count++); 4.264 + 4.265 + src = frame; 4.266 + dest = rgbpix; 4.267 + 4.268 + for(i=0; i<NUMPIX; i++) { 4.269 + unsigned char c = *src++; 4.270 + *dest++ = palette[c].r; 4.271 + *dest++ = palette[c].g; 4.272 + *dest++ = palette[c].b; 4.273 + *dest++ = 255; 4.274 + } 4.275 + 4.276 + img_save_pixels(fname, rgbpix, fbsurf->w, fbsurf->h, IMG_FMT_RGBA32); 4.277 +#endif 4.278 +} 4.279 + 4.280 + 4.281 +/* ----- event handling (conio.h) ----- */ 4.282 +static SDL_Event *keybev; 4.283 +static int mousex, mousey, bnmask; 4.284 + 4.285 +static int keystate[256]; 4.286 +static int num_pressed; 4.287 + 4.288 +int kbhit(void) 4.289 +{ 4.290 + if(!keybev) { 4.291 + proc_events(); 4.292 + } 4.293 + return keybev != 0; 4.294 +} 4.295 + 4.296 +int getch(void) 4.297 +{ 4.298 + int res; 4.299 + 4.300 + while(!keybev) { 4.301 + SDL_Event ev; 4.302 + SDL_WaitEvent(&ev); 4.303 + SDL_PushEvent(&ev); 4.304 + proc_events(); 4.305 + } 4.306 + res = keybev->key.keysym.sym; 4.307 + keybev = 0; 4.308 + return res; 4.309 +} 4.310 + 4.311 +/* ----- improved event handling (keyb.h) ---- */ 4.312 + 4.313 +int kb_init(int bufsz) 4.314 +{ 4.315 + init_sdl(); 4.316 + 4.317 + return 0; 4.318 +} 4.319 + 4.320 +void kb_shutdown(void) 4.321 +{ 4.322 +} 4.323 + 4.324 +int kb_getkey(void) 4.325 +{ 4.326 + int res = -1; 4.327 + 4.328 + proc_events(); 4.329 + if(keybev) { 4.330 + res = keybev->key.keysym.sym; 4.331 + keybev = 0; 4.332 + } 4.333 + return res; 4.334 +} 4.335 + 4.336 +int kb_isdown(int key) 4.337 +{ 4.338 + if(key == KB_ANY) { 4.339 + return num_pressed; 4.340 + } 4.341 + return keystate[key]; 4.342 +} 4.343 + 4.344 +/* mouse handling (mouse.c implementation) */ 4.345 +static unsigned long last_mouse_hide_time; 4.346 + 4.347 +int have_mouse(void) 4.348 +{ 4.349 + return 1; 4.350 +} 4.351 + 4.352 +void set_mouse(int x, int y) 4.353 +{ 4.354 + SDL_ShowCursor(0); 4.355 + last_mouse_hide_time = get_msec(); 4.356 + 4.357 + SDL_WarpMouse(x * scale, y * scale); 4.358 + mousex = x; 4.359 + mousey = y; 4.360 +} 4.361 + 4.362 +int read_mouse(int *xp, int *yp) 4.363 +{ 4.364 + if(xp) *xp = mousex; 4.365 + if(yp) *yp = mousey; 4.366 + return bnmask; 4.367 +} 4.368 + 4.369 +static void proc_events(void) 4.370 +{ 4.371 + static SDL_Event ev; 4.372 + 4.373 + if(last_mouse_hide_time > 0 && get_msec() - last_mouse_hide_time > 3000) { 4.374 + last_mouse_hide_time = 0; 4.375 + SDL_ShowCursor(1); 4.376 + } 4.377 + 4.378 + while(SDL_PollEvent(&ev)) { 4.379 + switch(ev.type) { 4.380 + case SDL_KEYDOWN: 4.381 + { 4.382 + int key = ev.key.keysym.sym; 4.383 + 4.384 + if(!keybev) { 4.385 + keybev = &ev; 4.386 + } 4.387 + 4.388 + if(!keystate[key]) { 4.389 + keystate[key] = 1; 4.390 + num_pressed++; 4.391 + } 4.392 + } 4.393 + break; 4.394 + 4.395 + case SDL_KEYUP: 4.396 + { 4.397 + int key = ev.key.keysym.sym; 4.398 + 4.399 + if(keystate[key]) { 4.400 + keystate[key] = 0; 4.401 + if(--num_pressed < 0) { 4.402 + num_pressed = 0; 4.403 + } 4.404 + } 4.405 + } 4.406 + break; 4.407 + 4.408 + case SDL_MOUSEMOTION: 4.409 + mousex = ev.motion.x / scale; 4.410 + mousey = ev.motion.y / scale; 4.411 + break; 4.412 + 4.413 + case SDL_MOUSEBUTTONDOWN: 4.414 + case SDL_MOUSEBUTTONUP: 4.415 + { 4.416 + int mask = 0; 4.417 + switch(ev.button.button) { 4.418 + case SDL_BUTTON_LEFT: 4.419 + mask = MOUSE_LEFT; 4.420 + break; 4.421 + case SDL_BUTTON_MIDDLE: 4.422 + mask = MOUSE_MIDDLE; 4.423 + break; 4.424 + case SDL_BUTTON_RIGHT: 4.425 + mask = MOUSE_RIGHT; 4.426 + default: 4.427 + break; 4.428 + } 4.429 + if(!mask) { 4.430 + break; 4.431 + } 4.432 + 4.433 + if(ev.button.state == SDL_PRESSED) { 4.434 + bnmask |= mask; 4.435 + } else { 4.436 + bnmask &= ~mask; 4.437 + } 4.438 + } 4.439 + break; 4.440 + 4.441 + default: 4.442 + break; 4.443 + } 4.444 + } 4.445 +} 4.446 + 4.447 +/* ---- timer.c implementation ---- */ 4.448 +static Uint32 start_time; 4.449 + 4.450 +void init_timer(int res_hz) 4.451 +{ 4.452 + init_sdl(); 4.453 + reset_timer(); 4.454 +} 4.455 + 4.456 +void reset_timer(void) 4.457 +{ 4.458 + start_time = SDL_GetTicks(); 4.459 + printf("resetting timer: %u, %lu\n", start_time, get_msec()); 4.460 +} 4.461 + 4.462 +unsigned long get_msec(void) 4.463 +{ 4.464 + Uint32 ticks = SDL_GetTicks(); 4.465 + return (unsigned long)(ticks - start_time); 4.466 +}
5.1 --- a/src/gfx.c Sun Apr 06 01:12:50 2014 +0300 5.2 +++ b/src/gfx.c Sun Apr 06 02:43:24 2014 +0300 5.3 @@ -138,6 +138,11 @@ 5.4 vbe_set_palette(idx, col, 1, pal_bits); 5.5 } 5.6 5.7 +void wait_vsync(void) 5.8 +{ 5.9 + /* TODO */ 5.10 +} 5.11 + 5.12 static unsigned int make_mask(int sz, int pos) 5.13 { 5.14 unsigned int i, mask = 0;
6.1 --- a/src/gfx.h Sun Apr 06 01:12:50 2014 +0300 6.2 +++ b/src/gfx.h Sun Apr 06 02:43:24 2014 +0300 6.3 @@ -15,6 +15,8 @@ 6.4 6.5 void set_palette(int idx, int r, int g, int b); 6.6 6.7 +void wait_vsync(void); 6.8 + 6.9 #ifdef __cplusplus 6.10 } 6.11 #endif
7.1 --- a/src/m3dimpl.h Sun Apr 06 01:12:50 2014 +0300 7.2 +++ b/src/m3dimpl.h Sun Apr 06 02:43:24 2014 +0300 7.3 @@ -25,6 +25,16 @@ 7.4 7.5 int mmode; /* matrix mode */ 7.6 struct min3d_mstack mstack[2]; 7.7 + 7.8 + const float *vert_array; 7.9 + const float *norm_array; 7.10 + const float *col_array; 7.11 + const float *tc_array; 7.12 + 7.13 + /* immediate mode state */ 7.14 + float cur_color[4]; 7.15 + float cur_normal[3]; 7.16 + float cur_texcoord[2]; 7.17 }; 7.18 7.19 extern struct min3d_context *m3dctx;
8.1 --- a/src/m3drast.c Sun Apr 06 01:12:50 2014 +0300 8.2 +++ b/src/m3drast.c Sun Apr 06 02:43:24 2014 +0300 8.3 @@ -3,6 +3,17 @@ 8.4 8.5 void draw_point(struct min3d_vertex *v) 8.6 { 8.7 + int x = v->pos[0] + 0.5; 8.8 + int y = v->pos[1] + 0.5; 8.9 + int xsz = m3dctx->cbuf->xsz; 8.10 + unsigned char *ptr = m3dctx->cbuf->pixels + (y * xsz + x) * 3; 8.11 + 8.12 + int r = (int)(v->color[0] * 255.0); 8.13 + int g = (int)(v->color[1] * 255.0); 8.14 + int b = (int)(v->color[2] * 255.0); 8.15 + ptr[0] = r > 255 ? 255 : r; 8.16 + ptr[1] = g > 255 ? 255 : g; 8.17 + ptr[2] = b > 255 ? 255 : b; 8.18 } 8.19 8.20 void draw_line(struct min3d_vertex *v)
9.1 --- a/src/main.cc Sun Apr 06 01:12:50 2014 +0300 9.2 +++ b/src/main.cc Sun Apr 06 02:43:24 2014 +0300 9.3 @@ -85,6 +85,7 @@ 9.4 } 9.5 9.6 swap_buffers(); 9.7 + wait_vsync(); 9.8 } 9.9 9.10 #define PACK_RGB(r, g, b) \ 9.11 @@ -133,14 +134,14 @@ 9.12 9.13 static void handle_keyboard() 9.14 { 9.15 - if(!kb_isdown(KB_ANY)) 9.16 - return; 9.17 + int key; 9.18 9.19 - int c = kb_getkey(); 9.20 - switch(c) { 9.21 - case 27: 9.22 - quit = true; 9.23 - return; 9.24 + while((key = kb_getkey()) != -1) { 9.25 + switch(key) { 9.26 + case 27: 9.27 + quit = true; 9.28 + return; 9.29 + } 9.30 } 9.31 } 9.32
10.1 --- a/src/min3d.c Sun Apr 06 01:12:50 2014 +0300 10.2 +++ b/src/min3d.c Sun Apr 06 02:43:24 2014 +0300 10.3 @@ -1,4 +1,6 @@ 10.4 #include <stdlib.h> 10.5 +#include <string.h> 10.6 +#include <math.h> 10.7 #include "min3d.h" 10.8 #include "m3dimpl.h" 10.9 10.10 @@ -233,11 +235,36 @@ 10.11 } 10.12 10.13 /* drawing */ 10.14 -void m3d_draw(int prim, const float *varr, int vcount) 10.15 +void m3d_vertex_array(const float *varr) 10.16 +{ 10.17 + m3dctx->vert_array = varr; 10.18 +} 10.19 + 10.20 +void m3d_normal_array(const float *narr) 10.21 +{ 10.22 + m3dctx->norm_array = narr; 10.23 +} 10.24 + 10.25 +void m3d_color_array(const float *carr) 10.26 +{ 10.27 + m3dctx->col_array = carr; 10.28 +} 10.29 + 10.30 +void m3d_texcoord_array(const float *tcarr) 10.31 +{ 10.32 + m3dctx->tc_array = tcarr; 10.33 +} 10.34 + 10.35 + 10.36 +void m3d_draw(int prim, int vcount) 10.37 { 10.38 int i; 10.39 struct min3d_vertex v[4]; 10.40 struct min3d_vertex resv[16]; 10.41 + const float *varr = m3dctx->vert_array; 10.42 + const float *carr = m3dctx->col_array; 10.43 + 10.44 + if(!varr) return; 10.45 10.46 for(i=0; i<vcount; i++) { 10.47 int idx = i % prim; 10.48 @@ -245,6 +272,9 @@ 10.49 v[idx].pos[0] = *varr++; 10.50 v[idx].pos[1] = *varr++; 10.51 v[idx].pos[2] = *varr++; 10.52 + v[idx].color[0] = carr ? *carr++ : m3dctx->cur_color[0]; 10.53 + v[idx].color[1] = carr ? *carr++ : m3dctx->cur_color[1]; 10.54 + v[idx].color[2] = carr ? *carr++ : m3dctx->cur_color[2]; 10.55 10.56 if(idx == prim - 1) { 10.57 int resnum = proc_prim(prim, resv, v); 10.58 @@ -264,7 +294,7 @@ 10.59 } 10.60 } 10.61 10.62 -void m3d_draw_indexed(int prim, const float *varr, const int *idxarr, int icount) 10.63 +void m3d_draw_indexed(int prim, const int *idxarr, int icount) 10.64 { 10.65 /* TODO */ 10.66 }
11.1 --- a/src/min3d.h Sun Apr 06 01:12:50 2014 +0300 11.2 +++ b/src/min3d.h Sun Apr 06 02:43:24 2014 +0300 11.3 @@ -61,8 +61,13 @@ 11.4 void m3d_perspective(float vfov, float aspect, float znear, float zfar); 11.5 11.6 /* drawing */ 11.7 -void m3d_draw(int prim, const float *varr, int vcount); 11.8 -void m3d_draw_indexed(int prim, const float *varr, const int *idxarr, int icount); 11.9 +void m3d_vertex_array(const float *varr); 11.10 +void m3d_normal_array(const float *narr); 11.11 +void m3d_color_array(const float *carr); 11.12 +void m3d_texcoord_array(const float *tcarr); 11.13 + 11.14 +void m3d_draw(int prim, int vcount); 11.15 +void m3d_draw_indexed(int prim, const int *idxarr, int icount); 11.16 11.17 /* TODO immediate mode */ 11.18
12.1 --- a/src/object.cc Sun Apr 06 01:12:50 2014 +0300 12.2 +++ b/src/object.cc Sun Apr 06 02:43:24 2014 +0300 12.3 @@ -49,5 +49,7 @@ 12.4 } 12.5 } 12.6 12.7 - m3d_draw(M3D_POINTS, &varr->x, num_verts); 12.8 + m3d_vertex_array(&varr->x); 12.9 + m3d_draw(M3D_POINTS, num_verts); 12.10 + m3d_vertex_array(0); 12.11 }