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
|
#include <stdlib.h>
#include <stdio.h>
#include <memory>
#include <glload/gll.hpp>
#include <glimg/glimg.h>
#include <glimg/ImageSet.h>
#include <glimg/ImageFormat.h>
#include <glimg/TextureGeneratorExceptions.h>
#include <GL/glfw.h>
using namespace glimg;
int main()
{
int width, height;
int frame = 0;
bool running = true;
glfwInit();
if( !glfwOpenWindow( 640, 480, 0, 0, 0, 0, 0, 0, GLFW_FULLSCREEN ) )
{
glfwTerminate();
return 0;
}
glfwEnable( GLFW_MOUSE_CURSOR );
glfwSetWindowTitle("GLFW Application");
//////////////////////////////////////////////////////////////////////////////////
if(glload::LoadFunctions() == glload::LS_LOAD_FAILED)
{
printf("glload failure.\n");
running = false;
return 0;
}
GLuint theTexture = 0;
try
{
std::auto_ptr<glimg::ImageSet> pImgSet(glimg::loaders::stb::LoadFromFile("TestImage.png"));
theTexture = glimg::CreateTexture(pImgSet.get(), 0);
}
catch(glimg::loaders::stb::StbLoaderException &e)
{
printf("Image file loading failed.\n");
}
catch(glimg::TextureGenerationException &e)
{
printf("Texture creation failed.\n");
}
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
printf("Texture creation successful.\n");
glimg::Dimensions dims = ImageSet->glimg::ImageSet::GetDimensions();
////////////////////////////////////////////////////////////////////////////////
while(running)
{
frame++;
glfwGetWindowSize( &width, &height );
height = height > 0 ? height : 1;
glViewport( 0, 0, width, height );
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,width,height,0.0,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, 1);
glBegin (GL_QUADS);
glTexCoord2f (-1.0f, 1.0f); glVertex3i (0,0,0);
glTexCoord2f (0.0f, 1.0f); glVertex3i (23,0,0);
glTexCoord2f (0.0f, 0.0f); glVertex3i (23,29,0);
glTexCoord2f (-1.0f, 0.0f); glVertex3i (0,29,0);
glEnd ();
glfwSwapBuffers();
// exit if ESC was pressed or window was closed
running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam( GLFW_OPENED);
}
glfwTerminate();
return 0;
}
|