diff --git a/src/nvtt/tools/CMakeLists.txt b/src/nvtt/tools/CMakeLists.txt index 3bb7b1b..5bc83a4 100644 --- a/src/nvtt/tools/CMakeLists.txt +++ b/src/nvtt/tools/CMakeLists.txt @@ -1,5 +1,4 @@ - ADD_EXECUTABLE(nvcompress compress.cpp cmdline.h) TARGET_LINK_LIBRARIES(nvcompress nvcore nvmath nvimage nvtt) @@ -18,10 +17,22 @@ TARGET_LINK_LIBRARIES(nvassemble nvcore nvmath nvimage) ADD_EXECUTABLE(nvzoom resize.cpp cmdline.h) TARGET_LINK_LIBRARIES(nvzoom nvcore nvmath nvimage) +SET(TOOLS nvcompress nvdecompress nvddsinfo nvassemble nvzoom) + +IF(GLEW_FOUND AND GLUT_FOUND) + INCLUDE_DIRECTORIES(${GLEW_INCLUDE_PATH} ${GLUT_INCLUDE_DIR}) + ADD_EXECUTABLE(nvddsview ddsview.cpp cmdline.h) + TARGET_LINK_LIBRARIES(nvddsview nvcore nvmath nvimage ${GLEW_LIBRARY} ${GLUT_LIBRARY}) + SET(TOOLS ${TOOLS} nvddsview) +ENDIF(GLEW_FOUND AND GLUT_FOUND) + + ADD_EXECUTABLE(nv-gnome-thumbnailer thumbnailer.cpp cmdline.h) TARGET_LINK_LIBRARIES(nv-gnome-thumbnailer nvcore nvmath nvimage) - -INSTALL(TARGETS nvcompress nvdecompress nvddsinfo nvimgdiff nvassemble nvzoom nv-gnome-thumbnailer DESTINATION bin) + +SET(TOOLS ${TOOLS} nv-gnome-thumbnailer) + +INSTALL(TARGETS ${TOOLS} DESTINATION bin) # Use gconftool-2 to install gnome thumbnailer FIND_PROGRAM(GCONFTOOL2 gconftool-2) diff --git a/src/nvtt/tools/ddsview.cpp b/src/nvtt/tools/ddsview.cpp new file mode 100644 index 0000000..7d033c7 --- /dev/null +++ b/src/nvtt/tools/ddsview.cpp @@ -0,0 +1,206 @@ +// Copyright NVIDIA Corporation 2007 -- Ignacio Castano +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + +#include +#include + +#include +#include + +#include +#include + +#include "cmdline.h" + +GLuint tex0, tex1; + +float scale = 1.0f; +float tx = 0, ty = 0; + + +void initOpengl() +{ + glewInit(); + + if (!glewIsSupported( + "GL_VERSION_2_0 " + "GL_ARB_vertex_program " + "GL_ARB_fragment_program " + )) + { + printf("Unable to load required extension\n"); + exit(-1); + } + + glEnable(GL_DEPTH_TEST); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + + glutReportErrors(); +} + +GLuint createTexture(GLenum target, GLint internalformat, GLenum format, GLenum type, int w, int h) +{ + GLuint tex; + glGenTextures(1, &tex); + glBindTexture(target, tex); + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexImage2D(target, 0, internalformat, w, h, 0, format, type, 0); + return tex; +} + +void drawQuad() +{ + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); glVertex2f(-1.0, -1.0); + glTexCoord2f(1.0, 0.0); glVertex2f(1.0, -1.0); + glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0); + glTexCoord2f(0.0, 1.0); glVertex2f(-1.0, 1.0); + glEnd(); +} + + +void glutKeyboardCallback(unsigned char key, int x, int y) +{ + switch(key) { + case 27: + case 'q': + exit(0); + break; + + case '=': + case '+': + scale *= 1.5; + break; + + case '-': + case '_': + scale /= 1.5; + break; + + case 'r': + scale = 1.0; + tx = ty = 0.0; + break; + } +} + +void glutKeyboardUpCallback(unsigned char key, int x, int y) +{ +} + +void special(int key, int x, int y) +{ + switch(key) { + case GLUT_KEY_RIGHT: + tx -= 0.1; + break; + case GLUT_KEY_LEFT: + tx += 0.1; + break; + case GLUT_KEY_DOWN: + ty += 0.1; + break; + case GLUT_KEY_UP: + ty -= 0.1; + break; + } + glutPostRedisplay(); +} + + +void glutDisplayCallback(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + drawQuad(); + + glutSwapBuffers(); +} + +void glutIdleCallback(void) +{ + //glutPostRedisplay(); +} + + + + + +int main(int argc, char *argv[]) +{ + MyAssertHandler assertHandler; + MyMessageHandler messageHandler; + + if (argc != 2 && argc != 3) + { + printf("NVIDIA Texture Tools - Copyright NVIDIA Corporation 2007\n\n"); + printf("usage: nvddsview file0 [file1]\n\n"); + return 1; + } + + // Load surface. + nv::DirectDrawSurface dds(argv[1]); + if (!dds.isValid()) + { + printf("The file '%s' is not a valid DDS file.\n", argv[1]); + return 1; + } + + uint w = dds.width(); + uint h = dds.height(); + + // @@ Clamp window size is texture larger than desktop? + + + glutInit(&argc, argv); + + glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH ); + glutInitWindowSize( w, h ); + glutCreateWindow( "DDS View" ); + glutKeyboardFunc( glutKeyboardCallback ); + glutKeyboardUpFunc( glutKeyboardUpCallback ); + glutDisplayFunc( glutDisplayCallback ); + glutIdleFunc( glutIdleCallback ); + + initOpengl(); + + /* + glGenTextures(1, &tex0); + glBindTexture(GL_TEXTURE_2D, tex0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, img_w, img_h, 0, image.getFormat(), image.getType(), image.getLevel(0)); + */ + //tex0 = createTexture(GL_TEXTURE_2D, GL_RGBA, GL_RGBA, type, w, h,); + + // @@ Add IMGUI, fade in and out depending on mouse movement. + + + glutMainLoop(); + + return 0; +} +