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 |
int load_texture(const std::string &file_name) { SDL_Surface *bitmap = SDL_LoadBMP(file_name.c_str()); if(0 == bitmap) { std::cout << "Fehler beim Laden der Bitmap" << std::endl; return 0; } int texture; glGenTextures(1, reinterpret_cast<unsigned int *>(&texture)); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmap->w, bitmap->h, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmap->pixels); SDL_FreeSurface(bitmap); return texture; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
void update_screen(int texture) { glColor3ub(255, 255, 255); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture); glBegin(GL_QUADS); glTexCoord2d(0.0, 0.0); glVertex2d(0.0, 0.0); glTexCoord2d(1.0, 0.0); glVertex2d(1.0, 0.0); glTexCoord2d(1.0, 1.0); glVertex2d(1.0, 1.0); glTexCoord2d(0.0, 1.0); glVertex2d(0.0, 1.0); glEnd(); SDL_GL_SwapBuffers(); } |
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 42 43 44 45 46 47 48 49 50 51 52 |
int main() { if(-1 == SDL_Init(SDL_INIT_VIDEO)) std::cout << "Fehler beim Initialisieren von SDL_Video" << std::endl; if(-1 == SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5)) std::cout << "Fehler beim Setzen der Rottiefe" << std::endl; if(-1 == SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5)) std::cout << "Fehler beim Setzen der Grüntiefe" << std::endl; if(-1 == SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5)) std::cout << "Fehler beim Setzen der Blautiefe" << std::endl; if(-1 == SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)) std::cout << "Fehler beim Setzen der des Doublebuffers auf 1" << std::endl; int flags = SDL_OPENGL | SDL_HWSURFACE | SDL_DOUBLEBUF; if(0 == SDL_SetVideoMode(800, 600, 16, flags)) std::cout << "Fehler beim Setzen des Bildschirmmodus" << std::endl; int texture = load_texture("texture.bmp"); if(0 == texture) std::cout << "Fehler beim Laden der Textur" << std::endl; glViewport(0, 0, 800, 600); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 800, 600, 0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); bool quit = false; while(!quit) { SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_KEYDOWN: case SDL_QUIT: quit = true; break; } } update_screen(texture); } } |
Anonymous
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
void update_screen(int texture) { glColor3ub(255, 255, 255); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture); glBegin(GL_QUADS); glTexCoord2d(0.0, 0.0); glVertex2d(0.0, 0.0); glTexCoord2d(1.0, 0.0); glVertex2d(100.0, 0.0); glTexCoord2d(1.0, 1.0); glVertex2d(100.0, 100.0); glTexCoord2d(0.0, 1.0); glVertex2d(0.0, 100.0); glEnd(); SDL_GL_SwapBuffers(); } |
Zitat von »"weigo"«
www.zfx.info
Hier gibt es auch ein extra Forum für OGL, außerdem jede Menge guter Leute, da wird dir sicher jemand helfen können.
Ich habe noch nichts mit der SDL gemacht.
Werbeanzeige