Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
// Blittet eine Textur auf den Bildschirm void SDLW::Blit(unsigned texture, float x, float y, int w, int h) { GL_TexEnable(1); GL_Bind(texture); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2i(x, y); glTexCoord2f(1, 0); glVertex2i(x+w, y); glTexCoord2f(1, 1); glVertex2i(x+w, y+h); glTexCoord2f(0, 1); glVertex2i(x, y+h); glEnd(); } // Hier noch GL_TexEnable und GL_Bind static __inline__ void GL_TexEnable(int enable) { if (SDLW::gl_state_texenable == enable) return; if (enable) glEnable(GL_TEXTURE_2D); else glDisable(GL_TEXTURE_2D); SDLW::gl_state_texenable = enable; } /* Bindet eine Textur */ static __inline__ void GL_Bind(unsigned texture) { if (SDLW::gl_state_texture == texture) return; glBindTexture(GL_TEXTURE_2D, texture); SDLW::gl_state_texture = texture; } |
Administrator
Administrator
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
void SDLW::Init() { /* SDL initialisieren */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { Log::getInstance()->Write("Fehler beim initialisieren von SDL"); fprintf(stderr, "SDL konnte nicht initialisiert werden: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); Log::getInstance()->Write("SDL initialisiert"); /* OpenGL-Bildschirmmodus */ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); screen = SDL_SetVideoMode(1024, 768, 0, SDL_OPENGL | SDL_FULLSCREEN); if (!screen) { Log::getInstance()->Write("Fehler beim setzen von Bildschirmmodus"); fprintf(stderr, "Konnte Bildschirmmodus nicht setzen: %s\n", SDL_GetError()); exit(1); } Log::getInstance()->Write("Bildschirmmodus gesetzt"); SDL_EnableKeyRepeat(1, 1); /* Initialisierung von OpenGL */ glViewport(0, 0, screen->w, screen->h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, screen->w, screen->h, 0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } |
Quellcode |
|
1 |
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); |
Quellcode |
|
1 |
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); |
Zitat
Wo es schon um Performance geht, ist es eurere Meinung überhaupt sinnvoll SDL im OpenGL modus laufen zulassen, oder sollte ich lieber nur OpenGL verwenden. (Dann würde ich jetzt anfangen NeHe durchzuarbeiten bis ich alles wichtige für 2D Grafik mit OpenGL kann)
Administrator
Werbeanzeige