• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

trick

Members
  • Content count

    95
  • Joined

  • Last visited

Community Reputation

152 Neutral

About trick

  • Rank
    Member
  1. Thanks for the response. While my code isn't doing anything with the error checking, I tested value of e through debug. The problem is now identified, it was in my fragment shader.  The incoming UV was saved to a vec2 called "uv" but my sampler line called out "UV".  Came down to a case of case-sensitivity.
  2. I am working to implement textures in my program. I have trimmed it down to display a single quad on-screen, with space around it showing background color black. In my texture class, I have used glGetError to make sure there was no problem with generating the texture, and I use glGetProgramiv to test my shaders. When using colors in my fragment shader, everything seems to look just fine. I also know the data is packed correctly, because each triangle shows up as expected. The problem occurs as soon as I switch from getting my fragment color from the incoming vertex data to using a texture lookup. As soon as this change takes place, the entire screen goes white. I am using GLFW to handle window and input, and I know the program does not freeze because I can still use my exit key to close the program. Here is my vertex and fragment shaders: shader.vert   #version 430 core layout(location = 0) in vec3 vPosition; layout(location = 1) in vec2 vUV; layout(location = 2) in vec3 vColor; uniform mat4 MVP; out vec4 color; out vec2 uv; void main() { gl_Position = MVP * vec4(vPosition, 1.0f); color = vec4(vColor, 1.0f); uv = vUV; } shader.frag   #version 430 core in vec2 uv; in vec4 color; out vec4 fColor; uniform sampler2D Sampler; void main() { //fColor = color; fColor = texture(Sampler, UV); } zTexture.cpp   #include "zTexture.h" zTexture::zTexture() { } bool zTexture::loadTexture(const char* fileName) { gli::texture Texture = gli::load(fileName); if (Texture.empty()) return false; gli::gl GL(gli::gl::PROFILE_GL33); gli::gl::format const Format = GL.translate(Texture.format(), Texture.swizzles()); GLenum Target = GL.translate(Texture.target()); GLuint TextureName = 0; glGenTextures(1, &TextureName); GLenum e = glGetError(); glBindTexture(Target, TextureName); e = glGetError(); glTexParameteri(Target, GL_TEXTURE_BASE_LEVEL, 0); e = glGetError(); glTexParameteri(Target, GL_TEXTURE_MAX_LEVEL, static_cast<GLint>(Texture.levels() - 1)); e = glGetError(); glTexParameteri(Target, GL_TEXTURE_SWIZZLE_R, Format.Swizzles[0]); e = glGetError(); glTexParameteri(Target, GL_TEXTURE_SWIZZLE_G, Format.Swizzles[1]); e = glGetError(); glTexParameteri(Target, GL_TEXTURE_SWIZZLE_B, Format.Swizzles[2]); e = glGetError(); glTexParameteri(Target, GL_TEXTURE_SWIZZLE_A, Format.Swizzles[3]); e = glGetError(); glTexParameterf(Target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); e = glGetError(); glTexParameterf(Target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); e = glGetError(); glm::tvec3<GLsizei> const Extent(Texture.extent()); GLsizei const FaceTotal = static_cast<GLsizei>(Texture.layers() * Texture.faces()); switch (Texture.target()) { case gli::TARGET_1D: glTexStorage1D(Target, static_cast<GLint>(Texture.levels()), Format.Internal, Extent.x); e = glGetError(); break; case gli::TARGET_1D_ARRAY: case gli::TARGET_2D: case gli::TARGET_CUBE: glTexStorage2D(Target, static_cast<GLint>(Texture.levels()), Format.Internal, Extent.x, Texture.target() == gli::TARGET_2D ? Extent.y : FaceTotal); e = glGetError(); break; case gli::TARGET_2D_ARRAY: case gli::TARGET_3D: case gli::TARGET_CUBE_ARRAY: glTexStorage3D(Target, static_cast<GLint>(Texture.levels()), Format.Internal, Extent.x, Extent.y, Texture.target() == gli::TARGET_3D ? Extent.z : FaceTotal); e = glGetError(); break; default: assert(0); break; } for (std::size_t Layer = 0; Layer < Texture.layers(); ++Layer){ for (std::size_t Face = 0; Face < Texture.faces(); ++Face) { for (std::size_t Level = 0; Level < Texture.levels(); ++Level) { GLsizei const LayerGL = static_cast<GLsizei>(Layer); glm::tvec3<GLsizei> Extent(Texture.extent(Level)); Target = gli::is_target_cube(Texture.target()) ? static_cast<GLenum>(GL_TEXTURE_CUBE_MAP_POSITIVE_X + Face) : Target; switch (Texture.target()) { case gli::TARGET_1D: if (gli::is_compressed(Texture.format())) { glCompressedTexSubImage1D(Target, static_cast<GLint>(Level), 0, Extent.x, Format.Internal, static_cast<GLsizei>(Texture.size(Level)), Texture.data(Layer, Face, Level)); e = glGetError(); } else { glTexSubImage1D(Target, static_cast<GLint>(Level), 0, Extent.x, Format.External, Format.Type, Texture.data(Layer, Face, Level)); e = glGetError(); } break; case gli::TARGET_1D_ARRAY: case gli::TARGET_2D: case gli::TARGET_CUBE: if (gli::is_compressed(Texture.format())) { glCompressedTexSubImage2D(Target, static_cast<GLint>(Level), 0, 0, Extent.x, Texture.target() == gli::TARGET_1D_ARRAY ? LayerGL : Extent.y, Format.Internal, static_cast<GLsizei>(Texture.size(Level)), Texture.data(Layer, Face, Level)); e = glGetError(); } else { glTexSubImage2D(Target, static_cast<GLint>(Level), 0, 0, Extent.x, Texture.target() == gli::TARGET_1D_ARRAY ? LayerGL : Extent.y, Format.External, Format.Type, Texture.data(Layer, Face, Level)); e = glGetError(); } break; case gli::TARGET_2D_ARRAY: case gli::TARGET_3D: case gli::TARGET_CUBE_ARRAY: if (gli::is_compressed(Texture.format())) { glCompressedTexSubImage3D(Target, static_cast<GLint>(Level), 0, 0, 0, Extent.x, Extent.y, Texture.target() == gli::TARGET_3D ? Extent.z : LayerGL, Format.Internal, static_cast<GLsizei>(Texture.size(Level)), Texture.data(Layer, Face, Level)); e = glGetError(); } else { glTexSubImage3D(Target, static_cast<GLint>(Level), 0, 0, 0, Extent.x, Extent.y, Texture.target() == gli::TARGET_3D ? Extent.z : LayerGL, Format.External, Format.Type, Texture.data(Layer, Face, Level)); e = glGetError(); } break; default: assert(0); break; } } } } e = glGetError(); glBindTexture(Target, 0); e = glGetError(); texture = TextureName; return true; } void zTexture::render(GLenum target){//, GLuint ID) { glActiveTexture(target); glBindTexture(GL_TEXTURE_2D, texture); } GLuint zTexture::getID() { return texture; } and lastly, my vertex data   VertexData vertices[NumVertices] = { {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}}, {{1.0f, -1.0f, 0.0f}, {1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}}, {{-1.0f, 1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, 1.0f, 0.0f}}, {{1.0f, 1.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 1.0f, 1.0f}} }; GLuint indices[NumIndices] = { 0, 1, 2, 2, 1, 3 }; glEnableVertexAttribArray(vPosition); glEnableVertexAttribArray(vUV); glEnableVertexAttribArray(vColor); glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Buffers[IndexBuffer]); glVertexAttribPointer(vPosition, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)0); glVertexAttribPointer(vUV, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)12); glVertexAttribPointer(vColor, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)20); myTex.render(GL_TEXTURE0); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); glDisableVertexAttribArray(vPosition); glDisableVertexAttribArray(vUV); glDisableVertexAttribArray(vColor); Honestly I don't know what other code is pertinent, as everything works fine until I switch my fragment shader from using the incoming color to using texture sampling. I appreciate any help!!
  3. Thanks SapphireG, I had not realized that the clipping was done at 0.0 and 1.0 for the Z (your suggestion seems to have taken care of the problem!) Seems being on the edge of the clipping depth was causing inconsistent results.
  4.  I am slightly experienced with C++, and very new to OpenGL.  I have been using tutorials/books to learn and built a project up to the point of displaying a triangle on screen, and using matrices for transformations.  Before I went any further I wanted to develop what I had into a state machine, and get better organized with the code.  After making changes, my new code would display a flickering triangle.  As I have tried to fix the issue, it now no longer displays at all.  I have looked over the code repeatedly to identify the issue, and even printed out all programs following along with how they would proceed highlighting calls to match them up, and I don't see any major differences between the two (minus that I have removed some things like matrices to simplify).  Could anyone please see if they can spot where the error might be, or offer any suggestions? Source Code Below: Original Working Project: Start.cpp //#define GLFW_INCLUDE_GLCOREARB #include <gl/glew.h> #include "gl/wglew.h" #pragma comment(lib, "glew32.lib") #include <GLFW/glfw3.h> #include <stdlib.h> #include <stdio.h> #include <glm/glm.hpp> #include <glm/gtc/matrix_transform.hpp> #include "LoadShaders.h" #include "TestGraphicObject.h" TestGraphicObject testGO; GLuint ProgramID; //shader program GLuint MatrixID; float ratio; glm::mat4 Projection; glm::mat4 View; //GLFW Callbacks static void error_callback(int error, const char* description) { fputs(description, stderr); } static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GL_TRUE); } void window_close_callback(GLFWwindow* window) { glfwSetWindowShouldClose(window, GL_TRUE); } void setCallbacks(GLFWwindow* window) { glfwSetKeyCallback(window, key_callback); glfwSetWindowCloseCallback(window, window_close_callback); } //End GLFW Callbacks GLFWwindow* makeWindow() { GLFWwindow* window; glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want OpenGL 3.3 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL); if (window == NULL) { fprintf(stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n"); glfwTerminate(); return 0; } ratio = 640 / 480; glfwMakeContextCurrent(window); glfwSwapInterval(1); setCallbacks(window); return window; } int init() { glewExperimental = true; // Needed in core profile if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); return -1; } //Setup for displaying tri testGO.init(); // Create and compile our GLSL program from the shaders ProgramID = LoadShaders("shader.vert", "shader.frag"); MatrixID = glGetUniformLocation(ProgramID, "MVP"); //Enable depth testing glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); return 0; } void display(void) { glClear(GL_DEPTH_BUFFER_BIT); glUseProgram(ProgramID); testGO.render(MatrixID, View, Projection); } int main(void) { glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); GLFWwindow* window = makeWindow(); if (!window || window == 0) { glfwTerminate(); exit(EXIT_FAILURE); } //Initialize GLEW if (init() < 0) { exit(EXIT_FAILURE); } //Initialize matrices Projection = glm::perspective(glm::radians(45.0f), ratio, 0.1f, 100.0f); View = glm::lookAt(glm::vec3(4, 3, 3), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)); //Initialize Graphic Object testGO.init(); //Begin Game Loop while (!glfwWindowShouldClose(window)) { display(); glfwSwapBuffers(window); glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); exit(EXIT_SUCCESS); } TestGraphicsObject.cpp #include "TestGraphicObject.h" TestGraphicObject::TestGraphicObject() { } void TestGraphicObject::init() { //Setup for displaying tri glGenVertexArrays(NumVAOs, VAOs); glBindVertexArray(VAOs[Triangles]); //Vertices GLfloat vertices[NumVertices][3] = { { -0.9f, -0.9f, 1.0f },{ 0.9f, -0.9f, 1.0f },{ 0.0f, 0.9f, 1.0f } }; glGenBuffers(NumBuffers, Buffers); glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); Model = glm::mat4(1.0f); } void TestGraphicObject::render(GLuint matID, glm::mat4 view, glm::mat4 projection) { glm::mat4 mvp = projection * view * Model; glUniformMatrix4fv(matID, 1, GL_FALSE, &mvp[0][0]); glEnableVertexAttribArray(vPosition); glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]); glVertexAttribPointer(vPosition, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); glDrawArrays(GL_TRIANGLES, 0, 3); glDisableVertexAttribArray(vPosition); } shader.vert #version 430 core layout(location = 0) in vec4 vPosition; uniform mat4 MVP; out vec4 color; void main() { gl_Position = MVP * vPosition; color = vec4((vPosition.x + 1) / 2, 0.0f, (vPosition.y + 1) / 2, 1.0f); color.y = 1.0f - color.x; if (color.z > color.x){ color.y = 1.0f - color.z; } } shader.frag #version 430 core in vec4 color; out vec4 fColor; void main() { fColor = color; //vec4(0.0, 0.0, 1.0, 1.0); } New non-working project: Main.cpp //Main.cpp #include <gl/glew.h> #pragma comment(lib, "glew32.lib") //#include <GLFW/glfw3.h> #include <stdlib.h> #include <stdio.h> #include <ctime> #include "zWindow.h" #include "zStateManager.h" #include "StateTest.h" //GLFW error callback static void error_callback(int error, const char* description) { fputs(description, stderr); } int initGlew() { glewExperimental = true; if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); return -1; } return 0; } int main(void) { glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); zWindow wind; GLFWwindow* window = wind.getWindow(); if (!window || window == 0) { glfwTerminate(); exit(EXIT_FAILURE); } //Initialize GLEW if (initGlew() < 0) { exit(EXIT_FAILURE); } zStateManager stateMan; //Create State Manager stateMan.setCallbacks(window); //Set Input Callbacks StateTest testState; stateMan.addState(&testState); //Add Test State //Begin Main Loop while (!glfwWindowShouldClose(window)) { if (stateMan.render(window) != zState::STATERESULT_SUCCESS) { glfwTerminate(); exit(EXIT_FAILURE); } //if (stateMan.update(deltaTime) != zStateManager::STATERESULT_SUCCESS) { // glfwTerminate(); // exit(EXIT_FAILURE); //} } glfwDestroyWindow(window); glfwTerminate(); exit(EXIT_SUCCESS); } zWindow.cpp //zWindow.cpp #include "zWindow.h" zWindow::zWindow() { int result = makeWindow(640, 480, "zWindow example", WINDOW_WINDOWED); } GLFWwindow* zWindow::getWindow() { return window; } int zWindow::makeWindow(int width, int height, char* title, int mode) { if (mode != WINDOW_WINDOWED && mode != WINDOW_FULLSCREEN && mode != WINDOW_WINDOWEDFULLSCREEN) { return WINDOW_ERROR_INVALID_SCREENTYPE; } aspectRatio = (float)width / (float)height; GLFWwindow* win; glfwWindowHint(GLFW_SAMPLES, 4); //glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); if (mode == WINDOW_WINDOWED) { //glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); win = glfwCreateWindow(width, height, title, NULL, NULL); } else if (mode == WINDOW_WINDOWEDFULLSCREEN) { const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); aspectRatio = (float)mode->width / (float)mode->height; GLFWmonitor* monitor = glfwGetPrimaryMonitor(); glfwWindowHint(GLFW_RED_BITS, mode->redBits); glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); win = glfwCreateWindow(mode->width, mode->height, title, monitor, NULL); } else { const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); GLFWmonitor* monitor = glfwGetPrimaryMonitor(); glfwWindowHint(GLFW_RED_BITS, mode->redBits); glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); win = glfwCreateWindow(width, height, title, monitor, NULL); } if (win == NULL) { glfwTerminate(); return WINDOW_ERROR_CREATE_WINDOW; } if (window != NULL && window != 0) { glfwDestroyWindow(window); } window = win; glfwMakeContextCurrent(window); glfwSwapInterval(1); return WINDOW_SUCCESS; } // Callbacks void zWindow::window_close_callback(GLFWwindow* win) { //Window closed glfwSetWindowShouldClose(win, GL_FALSE); } void zWindow::window_size_callback(GLFWwindow* win, int width, int height) { //Window size changed aspectRatio = (float)width / (float)height; } void zWindow::framebuffer_size_callback(GLFWwindow* win, int width, int height) { //Framebuffer size changed } void zWindow::window_pos_callback(GLFWwindow* win, int& x, int& y) { //Window has moved } void zWindow::window_iconify_callback(GLFWwindow* win, int iconified) { if (iconified) { //Window minimized } else { //Window restored } } void zWindow::window_focus_callback(GLFWwindow* win, int focused) { if (focused) { //Window received focus } else { //Window lost focus } } zStateManager.cpp //zStateManager.cpp #include "zStateManager.h" zStateManager::zStateManager() { ProgramID = LoadShaders("shader.vert", "shader.frag"); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); } void zStateManager::addState(zState* t) { states.push_back(t); } int zStateManager::removeState() { if (states.size() > 0) { states.pop_back(); return zState::STATERESULT_SUCCESS; } return zState::STATERESULT_FAILURE; } int zStateManager::update(double t) { if (states.size() > 0) { states.back()->update(t); return zState::STATERESULT_SUCCESS; } return zState::STATERESULT_FAILURE; } int zStateManager::render(GLFWwindow* window) { if (states.size() > 0) { glClear(GL_DEPTH_BUFFER_BIT); glUseProgram(ProgramID); states.back()->render(window); glFlush(); glfwSwapBuffers(window); glfwPollEvents(); return zState::STATERESULT_SUCCESS; } glfwSwapBuffers(window); glfwPollEvents(); return zState::STATERESULT_FAILURE; } void zStateManager::setCallbacks(GLFWwindow* window) { glfwSetKeyCallback(window, key_callback); } void zStateManager::key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GL_TRUE); } zState.h - No CPP file //zState.h #pragma once #ifndef __ZSTATE_DEFINED #define __ZSTATE_DEFINED #include <GLFW/glfw3.h> //#include "zStateManager.h" class zState { protected: public: typedef enum { STATERESULT_SUCCESS = 0, STATERESULT_FAILURE } errorCodes; public: virtual int update(double t) = 0; virtual int render(GLFWwindow* window) = 0; virtual void init(void) = 0; }; #endif StateTest.cpp //StateTest.cpp #include "StateTest.h" StateTest::StateTest() { init(); } int StateTest::update(double t) { return zState::STATERESULT_SUCCESS; } int StateTest::render(GLFWwindow* window) { glEnableVertexAttribArray(vPosition); glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]); glVertexAttribPointer(vPosition, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); glDrawArrays(GL_TRIANGLES, 0, NumVertices); glDisableVertexAttribArray(vPosition); //glFlush(); return zState::STATERESULT_SUCCESS; } void StateTest::init() { glGenVertexArrays(NumVAOs, VAOs); glBindVertexArray(VAOs[Triangles]); GLfloat vertices[NumVertices][3] = { { -0.9f, -0.9f, 1.0f },{ 0.9f, -0.9f, 1.0f },{ 0.0f, 0.9f, 1.0f } }; glGenBuffers(NumBuffers, Buffers); glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); } shader.vert #version 430 core layout(location = 0) in vec3 vPosition; //uniform mat4 MVP; out vec4 color; void main() { gl_Position.xyz = vPosition; gl_Position.w = 1.0f; color = vec4(0.0f, 0.0f, 1.0f, 1.0f); } shader.frag #version 430 core in vec4 color; out vec4 fColor; void main() { fColor = color; //vec4(0.0, 0.0, 1.0, 1.0); }
  5. When setting constant buffers to a shader, does DirectX assignn it to the specific shader that is currently loaded, and remember it is for that shader? Or does it keep the same buffer applied through shader changes, and the buffer must be changed as well? As an example, say I have two different vertex shaders, and each has it's own constant buffer, like the simplified snippet below. [CODE] ID3D11Device* Device; ID3D11DeviceContext* DevCon; ID3D11VertexShader* Shader1; ID3D11VertexShader* Shader2; ID3D11Buffer* CBuff1; ID3D11Buffer* CBuff2; //initialization code //Render Routine DevCon->VSSetShader(Shader1, NULL, 0); DevCon->VSSetConstantBuffers(0, 1, CBuff1); //Draw stuff with shader1 DevCon->VSSetShader(Shader2, NULL, 0); DevCon->VSSetConstantBuffers(0, 1, CBuff2); //Draw stuff with shader2 [/CODE] Now, if I then swap back to Shader1... [CODE] DevCon->VSSetShader(Shader1, NULL, 0); [/CODE] Does DirectX remember to use CBuff1, or do I need to reset it as well?
  6. Awesome, managed to get it fixed! The problem was happening around this code: [CODE] if(numVSBuffers > 0){ DevCon->VSSetConstantBuffers(0, numVSBuffers, reinterpret_cast<ID3D11Buffer* const*>(g_pVSConstantBuffers)); } [/CODE] where numVSBuffers is an int. I added "numVSBuffers = 0;" to the constructor for the class, and the problem went away. Thanks!
  7. I am using Visual C++ 2010 Express, and I just finished the basics of my engine code, and wanted to test under release to ensure it worked properly. I started by changing the settings in the directx control panel to force debug layer off, swapped to release mode, and added the include and lib directories (same as the debug directories). The program compiles and links fine, with no errors, but when I try to run the executable it crashes. I am using DirectInput for all input and XAudio2 for sound. The sounds I have playing actually start before the program crashes, so I'm sure it's in the graphics. The odd thing in, I can navigate in windows to the debug executable, and it runs perfectly fine. Is there some other step that must be taken when switching to release mode for it to run properly, when running D3D11? I've been looking for a while now, and the only things I can find are questions about getting an app to run on a different computer, not just swapping from debug to release. Thanks!
  8. I've been writing an application using Visual C++ 2010 Express, and using DirectX 11. It runs fine when I run it from within VC++ Express, but when I try to locate the generated exe file, and run it that way, it crashes every time. Is there something special that must be done before the program can be run in this way?
  9. Thanks for the help! I downloaded the Application Verifier, and although the results from it didn't help me to find the problem, I ended up finding it by manually following each step in the program. It was indeed due to writing to memory outside the array size, and now it's working great!
  10. Thanks for quick response! Is there any easier way to track that down than to follow every step of the program, manually tracking those items?
  11. I am working on developing code to write text to the screen using C++ and DirectX11, and in the code where the text can be changed, I'm getting an error. The error says [quote] Windows has triggered a breakpoint in ZLib.exe. This may be due to a corruption of the heap, which indicates a bug in ZLib.exe or any of the DLLs it has loaded. This may also be due to the user pressing F12 while ZLib.exe has focus. The output window may have more diagnostic information. [/quote] I don't see anything extra in the output window, other than "[font=Consolas][size=1][font=Consolas][size=1][size=2]Critical error detected c0000374[/size]"[/size][/font][/size][/font] Using breakpoints, I've narrowed down the line that causes the error to this. [CODE] int* temp = new int[new_len]; [/CODE] I've also checked the value of new_len in debug mode, to make sure that wasn't the problem, and it is an int variable equal to 11 when it hits this spot. I didn't post all the code, as I can't see why this would fail regardless, but I can if needed. Can anyone help me figure out what's going on?
  12. DX11

    Thanks for quick response! Managed to see what was going on, after checking that.
  13. I'm having trouble with my 3rd vertex shader for my application. I am getting E_FAIL result when calling [size=4][font=Consolas][font=Consolas]D3DX11CompileFromFile. Can anyone take a look at the HLSL below, and let me know if you see anything? I've been over it numerous times, and can't see what I'm doing wrong.[/font][/font][/size] [code]//Sprites.vs //-------------------------------------------------------------------------------------- // Buffers //-------------------------------------------------------------------------------------- cbuffer OnScreen : register( b0 ) { float2 screenSize; } //-------------------------------------------------------------------------------------- // Typedefs //-------------------------------------------------------------------------------------- struct VertexInput { float4 Pos : POSITION; float2 Tex : TEXCOORD0; float2 sPos : TEXCOORD1; float2 sSize : TEXCOORD2; float2 tPos : TEXCOORD3; float2 tSize : TEXCOORD4; }; struct PixelInput { float4 Pos : SV_POSITION; float2 Tex : TEXCOORD0; }; //-------------------------------------------------------------------------------------- // Vertex Shader //-------------------------------------------------------------------------------------- PixelInput VS( VertexInput input ) { PixelInput output; output.Pos = input.Pos; output.Pos[0] = (((output.Pos[0] * output.sSize[0]) + output.sPos[0]) / screenSize[0]) - 1; output.Pos[1] = (((output.Pos[1] * output.sSize[1]) + output.sPos[1]) / screenSize[1]) - 1; output.Tex = input.Tex; output.Tex[0] = ((output.Tex[0] * input.tSize[0]) + input.tPos[0]); output.Tex[1] = ((output.Tex[1] * input.tSize[1]) + input.tPos[1]); return output; } [/code]
  14. One last question on the subject. If the object here is to use instancing, to reduce the number of draw calls being made, I see two things I want to know if I'm correct on. 1) The textures need to be in one sprite-sheet for all sprites, so that the texture buffer can be updated once prior to calling draw function. 2) Couldn't the same idea be applied without the ortho matrix, like the vertex shader below? [CODE] //Sprites.vs //-------------------------------------------------------------------------------------- // Buffers //-------------------------------------------------------------------------------------- cbuffer OnScreenUpdate : register( b0 ) { float sWidth; float sHeight; } //-------------------------------------------------------------------------------------- // Typedefs //-------------------------------------------------------------------------------------- struct VertexInput{ float4 Pos : POSITION; float2 Tex : TEXCOORD0; float2 sPos : TEXCOORD1; }; //sPos = screen position struct PixelInput{ float4 Pos : SV_POSITION; float2 Tex : TEXCOORD0; }; //-------------------------------------------------------------------------------------- // Vertex Shader //-------------------------------------------------------------------------------------- PixelInput VS( VertexInput input ) { PixelInput output; output.Pos = input.Pos; output.Pos[0] = (((output.Pos[0] + sPos[0]) * 2) / sWidth) - 1; output.Pos[1] = (((output.Pos[1] + sPos[1]) * 2) / sHeight) - 1; output.Tex = input.Tex; return output; } [/CODE]
  15. Thanks for the input guys! Looks like I need to do some more research on instancing, using ortho matrix, etc.! [img]http://public.gamedev.net//public/style_emoticons/default/blink.png[/img]