SDL: Problem mit pixelColor()
-
ich habe ein kleiner problem mit SDL. pixelColor(), welches in Zeile 45 aufgerufen wird, zeichnet NICHTS auf den Bildschirm.
Wenn ich meine eigene Pixelmethode schreibe, dann gehts auch net.
#include <stdlib.h> #include <iostream> #include <SDL/SDL.h> #include <SDL/SDL_image.h> #include <SDL/SDL_gfxPrimitives.h> void errmsg(const std::string msg); int main (int argc, char* argv[]) { const int width = 256, height = 256, depth = 16; SDL_Event event; if (SDL_Init(SDL_INIT_VIDEO) == -1) errmsg("Couldn't initialize video"); atexit(SDL_Quit); SDL_Surface* screen = SDL_SetVideoMode(width, height, depth, SDL_SWSURFACE | SDL_DOUBLEBUF); if (screen == 0) errmsg("error: Couldn't set video mode"); SDL_Surface* surf = IMG_Load("./aaa.png"); if (!surf) errmsg("Couldn't load image"); /*SDL_Rect src_rect = {0, 0, surf->w, surf->h}; SDL_Rect dst_rect = {20, 20, surf->w, surf->h};*/ SDL_ShowCursor(0); SDL_WM_SetCaption("Just a test", "Just a test"); while (event.type != SDL_QUIT) { SDL_PumpEvents(); SDL_PollEvent(&event); SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); //SDL_BlitSurface(surf, &src_rect, screen, &dst_rect); if (SDL_MUSTLOCK(screen)) SDL_LockSurface(screen); pixelColor(screen, 10, 10, SDL_MapRGB(screen->format, 255, 0, 0)); if (SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); SDL_Flip(screen); SDL_Delay(10); } } void errmsg(const std::string msg) { std::cerr<<"error: "<<msg<<std::endl; exit(-1); }Jemand ne lösung?
-
Dieser Thread wurde von Moderator/in rüdiger aus dem Forum Rund um die Programmierung in das Forum Spiele-/Grafikprogrammierung verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
und du bist sicher, dass der modus 256x256x16 existiert?
-
hellihjb schrieb:
und du bist sicher, dass der modus 256x256x16 existiert?
Lol? steht da irgendwo SDL_FULLSCREEN?
Es entsteht ein fenster von der Grösse 256x256 bei 16 bits Farbtiefe.(ps: Hab mich geregt)
-
Lol? steht da irgendwo SDL_FULLSCREEN?
da hast du wohl recht - und so hoeflich formuliert

loesung:
pixelColor() nutzt intern SDL_BlitSurface, aber:The blit function should not be called on a locked surface.
also lass mal lock/unlock weg.
kommt mir allerdings nicht sonderlich geistreich vor, ein 1x1 surface zu fuellen und zu blitten, anstatt den pixel direkt ins gelockte surface zu schreiben...