dds_loader

所属分类:GPU/显卡
开发工具:C++
文件大小:1826KB
下载次数:0
上传日期:2021-07-27 16:29:03
上 传 者sh-1993
说明:  用于OpenGL和Vulkan应用程序的直接绘制曲面加载器
(direct draw surface loader for your OpenGL and Vulkan applications)

文件列表:
CMakeLists.txt (1651, 2021-07-28)
LICENSE (1073, 2021-07-28)
assets (0, 2021-07-28)
assets\MASTER_Room_Interior_BaseColor.dds (2796344, 2021-07-28)
assets\Shopsign_Bakery_BaseColor.dds (2796344, 2021-07-28)
assets\zero_size.dds (0, 2021-07-28)
cmake (0, 2021-07-28)
cmake\CMakeLists.txt.in (432, 2021-07-28)
exports (0, 2021-07-28)
exports\CMakeLists.txt (383, 2021-07-28)
exports\LibraryConfig.cmake.in (126, 2021-07-28)
include (0, 2021-07-28)
include\dds_loader.h (1602, 2021-07-28)
src (0, 2021-07-28)
src\dds_loader.cpp (10601, 2021-07-28)
src\main.cpp (54, 2021-07-28)
test (0, 2021-07-28)
test\CMakeLists.txt (584, 2021-07-28)
test\dds.cpp (3965, 2021-07-28)
test\main.cpp (129, 2021-07-28)

# MINIMAL OPENGL USAGE EXAMPLE ```c ... DDS_TEXTURE* sample_texture = new DDS_TEXTURE(); bool do_flip = true; load_dds_from_file("file/path/of/dds_file/sample.dds", &sample_texture, do_flip); ... ``` in opengl the dds file can be used in the following way (if it's an compressed texture): ```c ... glCompressedTexImage2D(GL_TEXTURE_2D, 0, sample_texture->format, sample_texture->width sample_texture->height, 0, sample_texture->sz, sample_texture->pixels); ... ``` using an uncompressed texture should be used in the following way: ```c ... glTexImage2D(GL_TEXTURE_2D, 0, sample_texture->channels, sample_texture->width, sample_texture->width, 0, sample_texture->format, GL_UNSIGNED_BYTE, sample_texture->pixels); ... ``` be sure to delete the loaded dds file after loading it: ```c delete (sample_texture); ``` used the following shaders for visualizing the result: vertex shader: ```c #version 330 core layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aColor; layout (location = 2) in vec2 aTexCoord; out vec3 ourColor; out vec2 TexCoord; void main() { gl_Position = vec4(aPos, 1.0); ourColor = aColor; TexCoord = vec2(aTexCoord.x, aTexCoord.y); } ``` fragment shader: ```c #version 330 core out vec4 FragColor; in vec3 ourColor; in vec2 TexCoord; // texture sampler uniform sampler2D texture1; void main() { FragColor = texture(texture1, TexCoord); } ``` FULL OPENGL USAGE EXAMPLE (used GLFW and GLAD) ```c #include #include #include "Shader.h" #include "dds_loader.h" void framebuffer_size_callback( GLFWwindow* window, int width, int height ); void processInput( GLFWwindow *window ); // settings const unsigned int SCR_WIDTH = 800; const unsigned int SCR_HEIGHT = 600; float lastX = SCR_WIDTH / 2.0f; float lastY = SCR_HEIGHT / 2.0f; bool firstMouse = true; // timing float deltaTime = 0.0f; float lastFrame = 0.0f; int main( ) { // glfw: initialize and configure // ------------------------------ glfwInit( ); glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 3 ); glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 3 ); glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE ); #ifdef __APPLE__ glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE ); // uncomment this statement to fix compilation on OS X #endif // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow( SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL ); if ( window == NULL ) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate( ); return -1; } glfwMakeContextCurrent( window ); glfwSetFramebufferSizeCallback( window, framebuffer_size_callback ); // tell GLFW to capture our mouse glfwSetInputMode( window, GLFW_CURSOR, GLFW_CURSOR_DISABLED ); // glad: load all OpenGL function pointers // --------------------------------------- if ( !gladLoadGLLoader( ( GLADloadproc ) glfwGetProcAddress ) ) { std::cout << "Failed to initialize GLAD" << std::endl; return -1; } // build and compile shaders // ------------------------- // NOTE: you have to write your own shader loading lib Shader shader( "shaders/Shader.vert", "shaders/Shader.frag" ); // set up vertex data (and buffer(s)) and configure vertex attributes // ------------------------------------------------------------------ float vertices[] = { // positions // colors // texture coords 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom left -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f // top left }; unsigned int indices[] = { 0, 1, 3, // first triangle 1, 2, 3 // second triangle }; unsigned int VBO, VAO, EBO; glGenVertexArrays(1, &VAO); glGenBuffers(1, &VBO); glGenBuffers(1, &EBO); glBindVertexArray(VAO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); // position attribute glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0); glEnableVertexAttribArray(0); // color attribute glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float))); glEnableVertexAttribArray(1); // texture coord attribute glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float))); glEnableVertexAttribArray(2); // load and create a texture // ------------------------- unsigned int texture; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); // all upcoming GL_TEXTURE_2D operations now have effect on this texture object // set the texture wrapping parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // set texture wrapping to GL_REPEAT (default wrapping method) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // set texture filtering parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); DDS_TEXTURE* sample_texture = new DDS_TEXTURE(); load_dds_from_file("assets/Shopsign_Bakery_BaseColor.dds", &sample_texture, true); glCompressedTexImage2D(GL_TEXTURE_2D, 0, sample_texture->format, sample_texture->width, sample_texture->height, 0, sample_texture->sz, sample_texture->pixels); delete (sample_texture); // render loop // ----------- while (!glfwWindowShouldClose(window)) { // input // ----- processInput(window); // render // ------ glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); // bind Texture glBindTexture(GL_TEXTURE_2D, texture); // render shader.use(); glBindVertexArray(VAO); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) // ------------------------------------------------------------------------------- glfwSwapBuffers(window); glfwPollEvents(); } // optional: de-allocate all resources once they've outlived their purpose: // ------------------------------------------------------------------------ glDeleteVertexArrays(1, &VAO); glDeleteBuffers(1, &VBO); glDeleteBuffers(1, &EBO); // glfw: terminate, clearing all previously allocated GLFW resources. // ------------------------------------------------------------------ glfwTerminate(); return 0; } // process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly // --------------------------------------------------------------------------------------------------------- void processInput(GLFWwindow* window){ if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); } // glfw: whenever the window size changed (by OS or user resize) this callback function executes // --------------------------------------------------------------------------------------------- void framebuffer_size_callback(GLFWwindow* window, int width, int height){ // make sure the viewport matches the new window dimensions; note that width and // height will be significantly larger than specified on retina displays. glViewport(0, 0, width, height); } ```

近期下载者

相关文件


收藏者