Remove SlideShow, and stb_image
This commit is contained in:
parent
8378805d35
commit
aac9ae6e11
File diff suppressed because it is too large
Load Diff
@ -1,54 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2009-2010 Mikko Mononen memon@inside.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, subject to the following restrictions:
|
|
||||||
// 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
// claim that you wrote the original software. If you use this software
|
|
||||||
// in a product, an acknowledgment in the product documentation would be
|
|
||||||
// appreciated but is not required.
|
|
||||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
// misrepresented as being the original software.
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef SLIDESHOW_H
|
|
||||||
#define SLIDESHOW_H
|
|
||||||
|
|
||||||
#include "Filelist.h"
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class SlideShow
|
|
||||||
{
|
|
||||||
std::vector<std::string> m_files;
|
|
||||||
char m_path[256];
|
|
||||||
|
|
||||||
int m_width;
|
|
||||||
int m_height;
|
|
||||||
unsigned int m_texId;
|
|
||||||
|
|
||||||
void purgeImage();
|
|
||||||
bool loadImage(const char* path);
|
|
||||||
|
|
||||||
bool m_showCurSlide;
|
|
||||||
float m_slideAlpha;
|
|
||||||
int m_curSlide;
|
|
||||||
int m_nextSlide;
|
|
||||||
|
|
||||||
public:
|
|
||||||
SlideShow();
|
|
||||||
~SlideShow();
|
|
||||||
|
|
||||||
bool init(const char* path);
|
|
||||||
void nextSlide();
|
|
||||||
void prevSlide();
|
|
||||||
void setSlide(int n);
|
|
||||||
void updateAndDraw(float dt, const float w, const float h);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // SLIDESHOW_H
|
|
@ -1,160 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2009-2010 Mikko Mononen memon@inside.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, subject to the following restrictions:
|
|
||||||
// 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
// claim that you wrote the original software. If you use this software
|
|
||||||
// in a product, an acknowledgment in the product documentation would be
|
|
||||||
// appreciated but is not required.
|
|
||||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
// misrepresented as being the original software.
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "SlideShow.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "SDL_opengl.h"
|
|
||||||
//#define STBI_HEADER_FILE_ONLY
|
|
||||||
#include "stb_image.h"
|
|
||||||
|
|
||||||
SlideShow::SlideShow() :
|
|
||||||
m_width(0),
|
|
||||||
m_height(0),
|
|
||||||
m_texId(0),
|
|
||||||
m_showCurSlide(true),
|
|
||||||
m_slideAlpha(1.0f),
|
|
||||||
m_curSlide(-1),
|
|
||||||
m_nextSlide(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
SlideShow::~SlideShow()
|
|
||||||
{
|
|
||||||
purgeImage();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SlideShow::purgeImage()
|
|
||||||
{
|
|
||||||
if (m_texId)
|
|
||||||
{
|
|
||||||
glDeleteTextures(1, (GLuint*)&m_texId);
|
|
||||||
m_texId = 0;
|
|
||||||
m_width = 0;
|
|
||||||
m_height = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SlideShow::loadImage(const char* path)
|
|
||||||
{
|
|
||||||
purgeImage();
|
|
||||||
|
|
||||||
int bpp;
|
|
||||||
unsigned char* data = stbi_load(path, &m_width, &m_height, &bpp, 4);
|
|
||||||
if (!data)
|
|
||||||
{
|
|
||||||
printf("Could not load file '%s': %s\n", path, stbi_failure_reason());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
glGenTextures(1, (GLuint*)&m_texId);
|
|
||||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_texId);
|
|
||||||
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, m_width, m_height, 0,
|
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, data);
|
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
|
|
||||||
stbi_image_free(data);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SlideShow::init(const char* path)
|
|
||||||
{
|
|
||||||
strcpy(m_path, path);
|
|
||||||
scanDirectory(m_path, ".png", m_files);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SlideShow::nextSlide()
|
|
||||||
{
|
|
||||||
setSlide(m_nextSlide+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SlideShow::prevSlide()
|
|
||||||
{
|
|
||||||
setSlide(m_nextSlide-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SlideShow::setSlide(int n)
|
|
||||||
{
|
|
||||||
const int maxIdx = m_files.size() ? m_files.size() - 1 : 0;
|
|
||||||
m_nextSlide = n;
|
|
||||||
if (m_nextSlide < 0) m_nextSlide = 0;
|
|
||||||
if (m_nextSlide > maxIdx) m_nextSlide = maxIdx;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SlideShow::updateAndDraw(float dt, const float w, const float h)
|
|
||||||
{
|
|
||||||
float slideAlphaTarget = (m_showCurSlide && m_texId) ? 1.0f : 0.0f;
|
|
||||||
if (m_curSlide != m_nextSlide)
|
|
||||||
slideAlphaTarget = 0;
|
|
||||||
|
|
||||||
if (slideAlphaTarget > m_slideAlpha)
|
|
||||||
m_slideAlpha += dt*4;
|
|
||||||
else if (slideAlphaTarget < m_slideAlpha)
|
|
||||||
m_slideAlpha -= dt*4;
|
|
||||||
if (m_slideAlpha < 0) m_slideAlpha = 0;
|
|
||||||
if (m_slideAlpha > 1) m_slideAlpha = 1;
|
|
||||||
|
|
||||||
if (m_curSlide != m_nextSlide && m_slideAlpha < 0.01f)
|
|
||||||
{
|
|
||||||
m_curSlide = m_nextSlide;
|
|
||||||
if (m_curSlide >= 0 && static_cast<std::size_t>(m_curSlide) < m_files.size())
|
|
||||||
{
|
|
||||||
char path[256];
|
|
||||||
strcpy(path, m_path);
|
|
||||||
strcat(path, m_files[m_curSlide].c_str());
|
|
||||||
loadImage(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_slideAlpha > 0.01f && m_texId)
|
|
||||||
{
|
|
||||||
unsigned char alpha = (unsigned char)(m_slideAlpha*255.0f);
|
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_RECTANGLE_ARB);
|
|
||||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_texId);
|
|
||||||
|
|
||||||
const float tw = (float)m_width;
|
|
||||||
const float th = (float)m_height;
|
|
||||||
const float hw = w*0.5f;
|
|
||||||
const float hh = h*0.5f;
|
|
||||||
|
|
||||||
glColor4ub(255,255,255,alpha);
|
|
||||||
glBegin(GL_QUADS);
|
|
||||||
glTexCoord2f(0,th);
|
|
||||||
glVertex2f(hw-tw/2,hh-th/2);
|
|
||||||
glTexCoord2f(tw,th);
|
|
||||||
glVertex2f(hw+tw/2,hh-th/2);
|
|
||||||
glTexCoord2f(tw,0);
|
|
||||||
glVertex2f(hw+tw/2,hh+th/2);
|
|
||||||
glTexCoord2f(0,0);
|
|
||||||
glVertex2f(hw-tw/2,hh+th/2);
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
glDisable(GL_TEXTURE_RECTANGLE_ARB);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -39,7 +39,6 @@
|
|||||||
#include "InputGeom.h"
|
#include "InputGeom.h"
|
||||||
#include "TestCase.h"
|
#include "TestCase.h"
|
||||||
#include "Filelist.h"
|
#include "Filelist.h"
|
||||||
#include "SlideShow.h"
|
|
||||||
#include "Sample_SoloMesh.h"
|
#include "Sample_SoloMesh.h"
|
||||||
#include "Sample_TileMesh.h"
|
#include "Sample_TileMesh.h"
|
||||||
#include "Sample_TempObstacles.h"
|
#include "Sample_TempObstacles.h"
|
||||||
@ -176,9 +175,6 @@ int main(int /*argc*/, char** /*argv*/)
|
|||||||
float markerPosition[3] = {0, 0, 0};
|
float markerPosition[3] = {0, 0, 0};
|
||||||
bool markerPositionSet = false;
|
bool markerPositionSet = false;
|
||||||
|
|
||||||
SlideShow slideShow;
|
|
||||||
slideShow.init("slides/");
|
|
||||||
|
|
||||||
InputGeom* geom = 0;
|
InputGeom* geom = 0;
|
||||||
Sample* sample = 0;
|
Sample* sample = 0;
|
||||||
|
|
||||||
@ -254,14 +250,6 @@ int main(int /*argc*/, char** /*argv*/)
|
|||||||
geom->saveGeomSet(&settings);
|
geom->saveGeomSet(&settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (event.key.keysym.sym == SDLK_RIGHT)
|
|
||||||
{
|
|
||||||
slideShow.nextSlide();
|
|
||||||
}
|
|
||||||
else if (event.key.keysym.sym == SDLK_LEFT)
|
|
||||||
{
|
|
||||||
slideShow.prevSlide();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
@ -888,8 +876,6 @@ int main(int /*argc*/, char** /*argv*/)
|
|||||||
imguiEndScrollArea();
|
imguiEndScrollArea();
|
||||||
}
|
}
|
||||||
|
|
||||||
slideShow.updateAndDraw(dt, (float)width, (float)height);
|
|
||||||
|
|
||||||
// Marker
|
// Marker
|
||||||
if (markerPositionSet && gluProject((GLdouble)markerPosition[0], (GLdouble)markerPosition[1], (GLdouble)markerPosition[2],
|
if (markerPositionSet && gluProject((GLdouble)markerPosition[0], (GLdouble)markerPosition[1], (GLdouble)markerPosition[2],
|
||||||
modelviewMatrix, projectionMatrix, viewport, &x, &y, &z))
|
modelviewMatrix, projectionMatrix, viewport, &x, &y, &z))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user