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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
/* CCTools SDL plugin GLES example Derived from SDL testgles sources: Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely. */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <SDL2/SDL.h> #include <SDL2/SDL_opengles.h> static SDL_Window *window; static SDL_GLContext context; static void AspectAdjust(int w, int h) { float aspectAdjust; aspectAdjust = (4.0f / 3.0f) / ((float)w / h); glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrthof(-2.0, 2.0, -2.0 * aspectAdjust, 2.0 * aspectAdjust, -20.0, 20.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glShadeModel(GL_SMOOTH); } static void Render() { static GLubyte color[8][4] = { {255, 0, 0, 0}, {255, 0, 0, 255}, {0, 255, 0, 255}, {0, 255, 0, 255}, {0, 255, 0, 255}, {255, 255, 255, 255}, {255, 0, 255, 255}, {0, 0, 255, 255} }; static GLfloat cube[8][3] = { {0.5, 0.5, -0.5}, {0.5f, -0.5f, -0.5f}, {-0.5f, -0.5f, -0.5f}, {-0.5f, 0.5f, -0.5f}, {-0.5f, 0.5f, 0.5f}, {0.5f, 0.5f, 0.5f}, {0.5f, -0.5f, 0.5f}, {-0.5f, -0.5f, 0.5f} }; static GLubyte indices[36] = { 0, 3, 4, 4, 5, 0, 0, 5, 6, 6, 1, 0, 6, 7, 2, 2, 1, 6, 7, 4, 3, 3, 2, 7, 5, 4, 7, 7, 6, 5, 2, 3, 1, 3, 0, 1 }; /* Do our drawing, too. */ glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Draw the cube */ glColorPointer(4, GL_UNSIGNED_BYTE, 0, color); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(3, GL_FLOAT, 0, cube); glEnableClientState(GL_VERTEX_ARRAY); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices); glMatrixMode(GL_MODELVIEW); glRotatef(5.0, 1.0, 1.0, 1.0); } int main(int argc, char *argv[]) { int done; SDL_DisplayMode mode; SDL_Event event; Uint32 then, now, frames; if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { /* Initialize SDL's Video subsystem */ SDL_Log("Unable to initialize SDL"); return 1; } SDL_GetDesktopDisplayMode(0, &mode); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); // Create our window centered window = SDL_CreateWindow("GLES example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, mode.w, mode.h, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN); if (!window) { // Die if creation failed SDL_Log("Unable to create window"); return 1; } // Create our opengl context and attach it to our window context = SDL_GL_CreateContext(window); if (!context) { SDL_Log("Unable to create GL context"); return 1; } SDL_GL_MakeCurrent(window, context); SDL_GL_SetSwapInterval(1); SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format)); SDL_Log("\n"); SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR)); SDL_Log("Renderer : %s\n", glGetString(GL_RENDERER)); SDL_Log("Version : %s\n", glGetString(GL_VERSION)); SDL_Log("Extensions : %s\n", glGetString(GL_EXTENSIONS)); SDL_Log("\n"); AspectAdjust(mode.w, mode.h); /* Main render loop */ frames = 0; then = SDL_GetTicks(); done = 0; while (!done) { /* Check for events */ ++frames; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: if (event.key.keysym.scancode == SDL_SCANCODE_AC_BACK) { done = 1; } break; case SDL_WINDOWEVENT: switch (event.window.event) { case SDL_WINDOWEVENT_RESIZED: /* Change view port to the new window dimensions */ AspectAdjust(event.window.data1, event.window.data2); /* Update window content */ Render(); SDL_GL_SwapWindow(window); break; } } } Render(); SDL_GL_SwapWindow(window); } /* Print out some timing information */ now = SDL_GetTicks(); if (now > then) { SDL_Log("%2.2f frames per second\n", ((double) frames * 1000) / (now - then)); } SDL_GL_DeleteContext(context); SDL_DestroyWindow(window); SDL_Quit(); return 0; } |
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <SDL2/SDL.h> #include <SDL2/SDL_opengles.h> static SDL_Window *window; static SDL_GLContext context; int move_me; static void AspectAdjust(int w, int h) { float aspectAdjust; aspectAdjust = (4.0f / 3.0f) / ((float)w / h); glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrthof(-2.0, 2.0, -2.0 * aspectAdjust, 2.0 * aspectAdjust, -20.0, 20.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glShadeModel(GL_SMOOTH); } static void Render() { static GLubyte color[8][4] = { {0, 0, 255, 0}, {2, 0, 0, 255}, {0, 255, 0, 255}, {0, 255, 0, 255}, {0, 255, 0, 255}, {255, 255, 255, 255}, {255, 0, 255, 255}, {0, 0, 255, 255}, }; static GLfloat trangleVectiles[8][4] = { {0.5f, 0.5f, -0.5f}, {0.5f, -0.5f, -0.5f}, {0.0f, -0.5f, -0.5f}, {-0.5f, 0.5f, 0.0f}, {-0.5f, 0.5f, 0.5f}, }; static GLubyte indices[36] = { 0, 1, 2, 2, 3, 0 }; /* Do our drawing, too. */ glClearColor(0.0, 0.0, 0.0, 0.5); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Draw the cube */ glColorPointer(4, GL_UNSIGNED_BYTE, 0, color); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(3, GL_FLOAT, 0, trangleVectiles); glEnableClientState(GL_VERTEX_ARRAY); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices); glMatrixMode(GL_MODELVIEW); glRotatef(1.0, 0.0, 1.0, 0.0); } int main(int argc, char *argv[]) { int done; SDL_DisplayMode mode; SDL_Event event; if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { /* Initialize SDL's Video subsystem */ SDL_Log("Unable to initialize SDL"); return 1; } SDL_GetDesktopDisplayMode(0, &mode); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); // Create our window centered window = SDL_CreateWindow("GLES example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, mode.w, mode.h, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN); // Create our opengl context and attach it to our window context = SDL_GL_CreateContext(window); SDL_GL_MakeCurrent(window, context); SDL_GL_SetSwapInterval(1); AspectAdjust(mode.w, mode.h); done = 0; while (!done) { /* Check for events */ while (SDL_PollEvent(&event)) { if ( event.type == SDL_MOUSEBUTTONDOWN ) { if (event.button.button == SDL_BUTTON_LEFT ) { if (event.type == SDL_MOUSEMOTION) { move_me = event.motion.x; }} // cursorPosition.y = event.motion.y; } switch (event.type) { case SDL_KEYDOWN: if (event.key.keysym.scancode == SDL_SCANCODE_AC_BACK) { done = 1; } break; case SDL_WINDOWEVENT: switch (event.window.event) { case SDL_WINDOWEVENT_RESIZED: /* Change view port to the new window dimensions */ AspectAdjust(event.window.data1, event.window.data2); /* Update window content */ Render(); SDL_GL_SwapWindow(window); break; } } } Render(); SDL_GL_SwapWindow(window); } SDL_GL_DeleteContext(context); SDL_DestroyWindow(window); SDL_Quit(); return 0; } |
Indem du entweder die Indices Liste erweiterst (siehe auch die andere Frage), oder einen weiteren "Index Buffer" anlegst.Zitat
-> kann mir wer helfen und zeigen wie man ein 2ten würfel neben den würfel dastellt - es gibt ja kein glBegin und glEnd mehr ?
Das sind mehrdimensionale Arrays. Du kannst dir genanntes Array vorstellen, wie ein Raster mit 8x3 Zellen. In diesem Fall wird es dafür benutzt, um jeweils 3 Farbkanäle (Rot, Grün, Blau) pro Vertex zu beschreiben.Zitat
-> was haben die arrays [8][3] aufsich ?
*funktionierenZitat
-> wie functionieren indices ?
C-/C++-Quelltext |
|
1 2 3 4 5 6 |
SVertex vertices[3] = { SVertex( 0.0f, 1.0f, 2.0f); SVertex( 0.5f, 0.0f, 2.0f); SVertex(-0.5f, 0.0f, 2.0f); }; |
C-/C++-Quelltext |
|
1 |
unsigned int indices[3] = { 1, 0, 2 }; |
Zum Beispiel, indem du mit SDL_CreateRGBSurface eine neue Surface erstellst und in die renderst.Zitat
-> wie kann ich ein Surface zusätzlich darstellen
Zitat
-> gibt es wo Tutorials dazu , die mir helfen (ohne JAVA !)
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 53 54 55 56 57 58 59 60 61 62 63 64 65 |
static void Render() { static GLubyte color[8][4] = { {0, 0, 255, 0}, {2, 0, 0, 255}, {0, 255, 0, 255}, {0, 255, 0, 255}, {0, 255, 0, 255}, {255, 255, 255, 255}, {255, 0, 255, 255}, {0, 0, 255, 255}, }; static GLfloat trangleVecties[8][4] = { {0.5f, 0.5f, -0.5f}, {0.5f, -0.5f, -0.5f}, {0.0f, -0.5f, -0.5f}, {-0.5f, 0.5f, 0.0f}, {-0.5f, 0.5f, 0.5f}, }; static GLfloat trangleVecties2[8][4] = { {0.5f, 0.5f, -0.5f}, {0.5f, -0.5f, -0.5f}, {0.0f, -0.5f, -0.5f}, {-0.5f, 0.5f, 0.0f}, {-0.5f, 0.5f, 0.5f}, }; static GLubyte indices[36] = { 0, 1, 2, 2, 3, 0 }; static GLubyte indices2[36] = { 5, 4, 7, 7, 6, 5, }; /* Do our drawing, too. */ glClearColor(0.0, 0.0, 0.0, 0.5); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Draw the cube */ glColorPointer(4, GL_UNSIGNED_BYTE, 0, color); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(3, GL_FLOAT, 0, trangleVectiles); glEnableClientState(GL_VERTEX_ARRAY); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices); glVertexPointer(3, GL_FLOAT, 0, trangleVectiles2); glEnableClientState(GL_VERTEX_ARRAY); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices2); glMatrixMode(GL_MODELVIEW); glRotatef(1.0, 0.0, 1.0, 0.0); } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »iSmokiieZz« (04.08.2014, 02:23)
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Jein. Davids Buch richtet sich an Einsteiger in der Spiele-Entwicklung. Allerdings nicht an Programmier-Einsteiger. Wollte das nur nochmal klar stellen.David hat ein gutes Buch geschrieben, in dem ein Großteil an Grundlagen übermittelt wird, wenn auch der Rest mit directx Zutun hat.
Werbeanzeige