- restored to space texture

- invert option added to gl texture load
This commit is contained in:
Frank DeMarco 2019-10-03 14:21:23 -04:00
parent b2f5f56063
commit eb519bdf93
1 changed files with 22 additions and 20 deletions

View File

@ -67,16 +67,16 @@ int link_shader(GLuint program)
return 0; return 0;
} }
GLuint get_gl_texture_from_surface(SDL_Surface *surface, GLint mipmap_filter) GLuint get_gl_texture_from_surface(SDL_Surface *surface, GLint mipmap_filter, bool invert = false)
{ {
GLuint id; GLuint id;
glCreateTextures(GL_TEXTURE_2D, 1, &id); glCreateTextures(GL_TEXTURE_2D, 1, &id);
glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id);
GLenum format; GLenum format;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN #if SDL_BYTEORDER == SDL_BIG_ENDIAN
format = GL_BGRA; format = invert ? GL_RGBA : GL_BGRA;
#else #else
format = GL_RGBA; format = invert ? GL_BGRA : GL_RGBA;
#endif #endif
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, format, glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, format,
GL_UNSIGNED_BYTE, surface->pixels); GL_UNSIGNED_BYTE, surface->pixels);
@ -143,8 +143,8 @@ void Mushroom::update()
Demo::Demo() Demo::Demo()
{ {
// Mix_Music *music = Mix_LoadMUS("resource/Field.mp3"); Mix_Music *music = Mix_LoadMUS("resource/Field.mp3");
Mix_Music *music = Mix_LoadMUS("/home/frank/WATERMELON-clean.mp3"); // Mix_Music *music = Mix_LoadMUS("/home/frank/WATERMELON-clean.mp3");
Mix_PlayMusic(music, -1); Mix_PlayMusic(music, -1);
load_gl_context(); load_gl_context();
delegate.subscribe(&Demo::respond, this); delegate.subscribe(&Demo::respond, this);
@ -222,18 +222,18 @@ void Demo::load_gl_context()
view = glm::lookAt( view = glm::lookAt(
glm::vec3(4, 3, 3), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)); glm::vec3(4, 3, 3), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
SDL_Surface* surface = zoomSurface( SDL_Surface* surface = zoomSurface(
rotateSurface90Degrees(IMG_Load("resource/tile.png"), 2), 1, -1, SMOOTHING_OFF); rotateSurface90Degrees(IMG_Load("resource/tile.png"), 2), -1, 1, SMOOTHING_OFF);
SDL_Log("tile.png bytes per pixel %i", surface->format->BytesPerPixel); SDL_Log("tile.png bytes per pixel %i", surface->format->BytesPerPixel);
space_texture_id = get_gl_texture_from_surface(surface, GL_LINEAR); space_texture_id = get_gl_texture_from_surface(surface, GL_LINEAR, true);
SDL_FreeSurface(surface); SDL_FreeSurface(surface);
std::vector<fs::path> paths = sfw::glob("/home/frank/projects/public/games/rov/face03/[0-9]+\\-.+\\.png"); // std::vector<fs::path> paths = sfw::glob("/home/frank/projects/public/games/buddi/local/face03/[0-9]+\\-.+\\.png");
for (fs::path path : paths) // for (fs::path path : paths)
{ // {
surface = zoomSurface(rotateSurface90Degrees(IMG_Load(path.c_str()), 2), -1, 1, SMOOTHING_OFF); // surface = zoomSurface(rotateSurface90Degrees(IMG_Load(path.c_str()), 2), -1, 1, SMOOTHING_OFF);
SDL_Log("loading %s", path.c_str()); // SDL_Log("loading %s", path.c_str());
face_ids.push_back(get_gl_texture_from_surface(surface, GL_LINEAR)); // face_ids.push_back(get_gl_texture_from_surface(surface, GL_LINEAR));
SDL_FreeSurface(surface); // SDL_FreeSurface(surface);
} // }
std::array<glm::vec2, 6> framerate_indicator_uv = { std::array<glm::vec2, 6> framerate_indicator_uv = {
{ {
{0, 1}, {1, 1}, {0, 0}, {0, 1}, {1, 1}, {0, 0},
@ -439,11 +439,13 @@ void Demo::update()
glEnableVertexAttribArray(1); glEnableVertexAttribArray(1);
glDisableVertexAttribArray(2); glDisableVertexAttribArray(2);
glVertexAttrib3f(2, 1, 1, 1); glVertexAttrib3f(2, 1, 1, 1);
for (int ii = 0; ii < 6; ii++) // for (int ii = 0; ii < 6; ii++)
{ // {
glBindTexture(GL_TEXTURE_2D, face_ids[ii]); // glBindTexture(GL_TEXTURE_2D, face_ids[ii]);
glDrawArrays(GL_TRIANGLES, ii * 6, 6); // glDrawArrays(GL_TRIANGLES, ii * 6, 6);
} // }
glBindTexture(GL_TEXTURE_2D, space_texture_id);
glDrawArrays(GL_TRIANGLES, 0, 36);
//glFlush(); //glFlush();
SDL_GL_SwapWindow(window); SDL_GL_SwapWindow(window);
// if (amount_rotated < 3.14f * 2) // if (amount_rotated < 3.14f * 2)