c++ - SDL Small Screen -
c++ - SDL Small Screen -
when run code trying start programming tetris clone prints screen little rectangle (<30*30) , other part of screen black (it should green)
i know shouldn't give code don't know where's error
#include <string> #include <vector> #include "sdl/sdl.h" using namespace std; const unsigned short screen_width = 640; const unsigned short screen_height = 480; const unsigned short screen_bpp = 32; const unsigned char block_length = 20; enum color { bluish = 0, cyan, white, red, yellow, magenta, greenish }; struct point { int x, y; }; struct block { public: point l; color c; }; vector<block> blocks; sdl_surface *screen = null; void apply_surface(sdl_surface *source, sdl_surface *target, int x, int y, sdl_rect *clip = null); bool init(); bool clean_up(); void show_blocks (); int main(int argc, char** argv) { init(); sdl_fillrect(screen, null, 0x00ff00); (int = 0; < 4; i++) { block b; b.c = red; b.l.x = i; b.l.y = i; blocks.push_back(b); } show_blocks(); if (sdl_flip(screen) == -1) homecoming 1; sdl_delay(5000); clean_up(); homecoming 0; } void apply_surface(sdl_surface *source, sdl_surface *target, int x, int y, sdl_rect *clip) { sdl_rect o; o.x = x; o.y = y; sdl_blitsurface(source, clip, target, &o); } bool init() { if (sdl_init(sdl_init_everything) == -1) homecoming false; if (!(screen = sdl_setvideomode(screen_width, screen_height, screen_bpp, sdl_swsurface))) homecoming false; sdl_wm_setcaption("hey tetris!", null); homecoming true; } bool clean_up() { sdl_quit(); } void show_blocks () { sdl_surface *s = sdl_creatergbsurface(sdl_swsurface, block_length, block_length, 32, 0x0, 0x0, 0x0, 0x0); (int = 0; < blocks.size(); i++) { uint64 bcolor; switch (blocks[i].c) { case bluish : bcolor = 0x0000ff; break; case cyan : bcolor = 0x00ffff; break; case white : bcolor = 0xffffff; break; case yellowish : bcolor = 0xffff00; break; case reddish : bcolor = 0xff0000; break; case magenta : bcolor = 0xff00ff; break; case greenish : bcolor = 0x00ff00; break; } sdl_fillrect(s, null, bcolor); apply_surface(s, screen, blocks[i].l.x * block_length, blocks[i].l.y * block_length); } sdl_freesurface(s); }
at first glance, came question: sdl_rect in apply_surface() set correctly? setting x , y without width , height gives rect undefined size due stack trash because rect not zeroed default constructor afaik. i'd set these members equal source, so:
o.x = x; o.y = y; o.w = source->w; o.h = source->h;
c++ sdl
Comments
Post a Comment