Jump to content
  • Advertisement

lightbug

Member
  • Content Count

    23
  • Joined

  • Last visited

Community Reputation

123 Neutral

About lightbug

  • Rank
    Member
  1. lightbug

    Adding some GUI to OpenGL

    that's a good looking gui   I will be the only user of my future tool app    I just want to add some properties panel and a menu, that's all for now, and of course a Opengl scene view (in qt this is called GL widget)   I was checking qt and something like this is what a want :       the qt creator is great , not only for qt, also as an c++ IDE, right now I'm using MSVS 2013 community , and some qt libs, for now it works pretty well, and its so easy to code, although still I don't understand what is happening in the background. With my cpp + Glew I can specify where the main loop is going to be, now in qt i don't have any idea.   In the video above use repaingGL for this (i think)   How did you make you own imgui? is there any tutorial out there? i don't what nothing complicated, only the basics   regards
  2. lightbug

    Adding some GUI to OpenGL

    wow this post is growing stronger! thanks for all the answers.    I want to add an OS based GUI.   This is a new concept for me, every application runs a native User interface, that's why i said:   So, i'll go with wxwidget, which is crossplatform, but is RMGUI. I like the approach of IMGUI now   correct me if I'm wrong!   -> A win32 application used the win32 API to open a window -> opengl by itself can't create a window -> Only the OS can create a windows   So Can I made an entire editor with wxwidget (for example) and read inputs from sdl at the same time? Would there be a problem? (because wxwidget and SDL reads messages from the OS)     Again thanks!   Regards!
  3. lightbug

    Adding some GUI to OpenGL

    I was searching about this new concept (for me) of "immediate GUI". Some people says it's not good, some people says that this is "the" solution against the classic method (called "Retained GUI")     See this link : http://gamedev.stackexchange.com/questions/24103/immediate-gui-yae-or-nay   I really don't understand anything about GUI, so I will keep investigating
  4. lightbug

    Adding some GUI to OpenGL

      OMG is that simple: // Setup ImGui binding ImGui_ImplGlfw_Init(window, true); then i can start drawing GUI things      where did you find this library? I was going to start with wxwidget, but now i got to see more of ImGUI   Thanks!
  5. Hi, I have a c++ 3d application based in opengl, sdl and bullets (physics), now i want to add a simple GUI (for example a buttom), the problem is that I don't know how to aproach this situation:   1 - Should I download a free gui library (c++) or made one with SDL?   2 - Should I add the GUI to my openGL window, or Add the openGL window to my GUI project?     Another thing, i have been seeing profesional software (for example : unreal engine 4 , unity , cubase , 3ds max , etc ... ) and all of those uses the same buttoms, the same menus, like the one windows have. My question--> what GUI use these software?    In any case, I would appreciate a good book about this specific topic     Thanks and sorry for the english 
  6. Hi, I wanna make a level editor (or any other tool) that involve a window with all of the features of the engine (graphics and audio). The thing is that I started the engine with a "game" approach , i mean, if the application runs it runs the game. I 've been reading about it and found wxwidget, qt and other tools for making level editor, but, what happen with all the features and stuff that I've been putting in the engine? How can I program a tool for the engine? ( Once I have almost the engine ready (suppose) ) Thanks in advance!
  7. lightbug

    Bind textures from framebuffer

      Hi, thanks for the answer, but, why would I want detach the normal texture?, In every tutorial and example i've seen that the "glFramebufferTexture2D" is called once, in the initialization.     I fix the problem, it was (as always) a reaaaaallly stupid problem, when i called InitQuad() I forgot to call this: glGenVertexArrays(1, &m_VAO); glBindVertexArray(m_VAO); glGenBuffers(3, m_VAB); So, sometimes it gives me "Segmentation Fault".
  8. Hello, like says in the title, I'm playing aroud with framebuffers, I have made a basic postprocessing effect (chromatic aberration), to do this I created a fbo, bind it like GL_FRAMEBUFFER, render every geometry and then Unbind it  (= 0) , the thing is that i want to use two framebuffers.   I have two classes "Deferred" and "PostProcessing"   The first stage consist in render the geometry, so I Bind the FBO from Deferred   The second stage consist in render the deferred lighting (see the shader below, actually it does nothing) Unding the FBO from deferred and Bind the one from PostProcessing.   the third stage consist in render with the postProcessing shader, so I Unbind the fbo from postProcessing   1) is this the correct way of doing this?     The problem : before create the deferred class, the postProcessing works fine (I have passing only one texture) , but now with both (deferred and PP) the display is clear always (a blue background). Maybe because I'm passing the textures in the wrong way, i don't know     Here is the Code from Renderer.cpp (the master render class) void Renderer::Frame() { BeginDraw(ColorBrackground.x, ColorBrackground.y, ColorBrackground.z, ColorBrackground.w); RenderScene(); RenderDeferred(); RenderPostProcessing(); EndDraw(); } void Renderer::BeginDraw(float r, float g , float b, float a) { glClearColor(r, g, b, a); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); } void Renderer::EndDraw() { m_window->SwapBuffers(); if(PostProcessingFX) m_postProcessing->UnbindFBO(); if(DeferredRendering) m_deferredRender->UnbindFBO(); } void Renderer::RenderScene() { if(DeferredRendering) m_deferredRender->BindFBO(); if(PostProcessingFX && !DeferredRendering) m_postProcessing->BindFBO(); ObjectsManager::GetInstance()->RenderAll(); } void Renderer::RenderDeferred() { if(!DeferredRendering) return; m_deferredRender->UnbindFBO(); if(PostProcessingFX) m_postProcessing->BindFBO(); m_deferredRender->RenderLightingPass(); } void Renderer::RenderPostProcessing() { if(!PostProcessingFX) return; m_postProcessing->UnbindFBO(); m_postProcessing->Render(); } with :   Deferred.cpp void Deferred::InitTextures() { //Get data from window     SDL_Window* window = Renderer::GetInstance()->GetWindow()->GetSDLWindow();     SDL_GetWindowSize(window , &width , &height); // Create the textures     glGenTextures(ARRAY_SIZE(m_textures), m_textures); //Albedo     glActiveTexture(GL_TEXTURE0);     glBindTexture(GL_TEXTURE_2D, m_textures[Albedo]);     //Properties     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_LINEAR);     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, NULL);     //Bind to the FBO     glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_textures[Albedo], 0);     glActiveTexture(GL_TEXTURE0);     glBindTexture(GL_TEXTURE_2D, 0); //Normal     glActiveTexture(GL_TEXTURE1);     glBindTexture(GL_TEXTURE_2D, m_textures[Normal]);     //Properties     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_LINEAR);     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, NULL);     //Bind to the FBO     glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, m_textures[Normal], 0);     glActiveTexture(GL_TEXTURE1);     glBindTexture(GL_TEXTURE_2D, 0);   } bool Deferred::Initialize() { // Create the FBO glGenFramebuffers(1, &m_FBO); glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); std::cout << m_FBO <<std::endl; InitTextures(); //Set the draw buffers GLenum DrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}; glDrawBuffers(ARRAY_SIZE(DrawBuffers), DrawBuffers); GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (Status != GL_FRAMEBUFFER_COMPLETE) { printf("FB error, status: 0x%x\n", Status); return false; } glBindFramebuffer(GL_FRAMEBUFFER, 0); m_shader = new DeferredShader; m_shader->Initialize(); return true; } void Deferred::RenderLightingPass() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); m_shader->Render( m_textures[Albedo] ,m_textures[Normal]); } And PostProcessing: void PostProcessing::InitTextures() { //Get data from window SDL_Window* window = Renderer::GetInstance()->GetWindow()->GetSDLWindow(); SDL_GetWindowSize(window , &width , &height); // Create the textures glGenTextures(ARRAY_SIZE(m_textures), m_textures); 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_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_textures[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, NULL); //Unbind texture glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, 0); } bool PostProcessing::Initialize() { // Create the FBO glGenFramebuffers(1, &m_FBO); glBindFramebuffer(GL_FRAMEBUFFER , m_FBO); std::cout << m_FBO <<std::endl; InitTextures(); //Bind to the FBO glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_textures[0], 0); //Set the draw buffers GLenum DrawBuffers[] = { GL_COLOR_ATTACHMENT0 }; glDrawBuffers(1, DrawBuffers); GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (Status != GL_FRAMEBUFFER_COMPLETE) { printf("FB error, status: 0x%x\n", Status); return false; } glBindFramebuffer(GL_FRAMEBUFFER, 0); m_shader = new ScreenShader; m_shader->Initialize(); return true; } void PostProcessing::Render() { glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); m_shader->Render(m_textures[0]); } Here is my fragments shaders , In the geometry pass I use only one shader (textureshader)   TextureShader #version 330 in vec2 texCoord0; in vec3 normal0; uniform vec4 color; uniform sampler2D sampler; layout (location = 0) out vec4 alb; layout (location = 1) out vec4 norm; void main() { alb = texture2D(sampler, texCoord0) * color; norm = vec4(normal0 , 0); } DeferredShader #version 330 in vec2 texCoord0; uniform sampler2D Albedo; uniform sampler2D Normal; layout (location = 0) out vec4 result; void main() { result = texture2D( Albedo , texCoord0 ); } PostProcessingShader #version 330 in vec2 texCoord0; uniform sampler2D sampler; uniform float offset; out vec4 result; void main() { vec4 scene; vec4 left; vec4 right; scene = texture2D(sampler, texCoord0); if(texCoord0.x - offset >= 0 && texCoord0.x + offset <= 1) { left = texture2D(sampler, vec2(texCoord0.x - offset , texCoord0.y) ); right = texture2D(sampler, vec2(texCoord0.x + offset , texCoord0.y) ); } else { left = scene; right = scene; } result = vec4(left.x , scene.y , right.z , scene.z); } 2) if I said --> layout (location =  X ) out vec4 result; , the result color would be the ColorAttachmentX right? (in the binded FBO of course)   ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------     This is a snippet of my deferredshader.cpp: void DeferredShader::InitQuad() { vec2 vertices[] = { vec2( -1 , 1 ) , vec2(-1 , -1) , vec2(1 , -1) , vec2( 1, 1) }; GLuint indices[] = {0 , 1 , 2 , 0 , 2 , 3}; vec2 uvs[] = { vec2( 0 , 1 ) , vec2(0 , 0) , vec2(1 , 0) , vec2( 1, 1) }; //positions glBindBuffer(GL_ARRAY_BUFFER, m_VAB[bufferPosition] ); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * 4 , //4 .... es QUAD vertices , GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); //uvs glBindBuffer(GL_ARRAY_BUFFER, m_VAB[bufferUVs]); glBufferData(GL_ARRAY_BUFFER, sizeof(uvs[0]) * 4 , uvs , GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0); //indices glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_VAB[bufferIndices]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices[0]) * 6, &indices[0], GL_STATIC_DRAW); //Unbind the VAO glBindVertexArray(0); } void DeferredShader::Initialize() { const std::string fileName = "./Resource/Glsl/deferred"; m_program = glCreateProgram(); m_vertexShader = CreateShader(LoadShader(fileName + ".vs"), GL_VERTEX_SHADER); m_fragmentShader = CreateShader(LoadShader(fileName + ".fs"), GL_FRAGMENT_SHADER); glAttachShader(m_program, m_vertexShader); glAttachShader(m_program, m_fragmentShader); //set the semantic for the input glBindAttribLocation(m_program, 0, "position"); glBindAttribLocation(m_program, 1, "texCoord"); glLinkProgram(m_program); CheckShaderError(m_program, GL_LINK_STATUS, true, "Error linking shader program"); glValidateProgram(m_program); CheckShaderError(m_program, GL_LINK_STATUS, true, "Invalid shader program"); uniform_Alb = glGetUniformLocation(m_program, "Albedo"); uniform_Norm = glGetUniformLocation(m_program, "Normal"); InitQuad(); } void DeferredShader::Render(GLuint albedo , GLuint normal) { glUseProgram(m_program); //Bind textures glActiveTexture(GL_TEXTURE0); glUniform1i(uniform_Alb , 0); glBindTexture(GL_TEXTURE_2D, albedo); glActiveTexture(GL_TEXTURE1); glUniform1i(uniform_Norm , 1); glBindTexture(GL_TEXTURE_2D, normal); glBindVertexArray(m_VAO); //Draw glDrawElements(GL_TRIANGLES ,6 , GL_UNSIGNED_INT , 0 ); //Release resources glBindVertexArray(0); //Unbind textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, 0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, 0); } 3) is necessary the "glUniform1i(...  )"?   4) is correct to Unbind the texture via " glActiveTexture(GL_TEXTURE X );     glBindTexture(GL_TEXTURE_2D, 0); " ??           sorry about : - Put so much code - The english   Thanks in advance!
  9.   great example! at least you didn't came out with the "muaahaha" and "the pure evil" sh&$t     I'll slowly killing all singletons
  10.   I'm totally agree with you, I don't want to have statics everywhere (only I have 5), this is what happend:   Initially i had a core object(which was static = m_Core pointer) and their class private members (renderer, objectmanager, Scene,...). the situation: I needed to call some manager inside SceneInit function from scene.cpp (basically the same example as my previous post).   Inside InitScene() I created the triangle. Once the gameobject is created is added to the objmanager list (a vector) (every gameobject had a reference to this objmanager).   Scene.cpp void SceneManager::SceneInit() { GameObject* obj1; //set the gameobject m_Core->getObjmanager()->AddGameObject(obj1); //added to objectmanager vector //a lot of code, set shader, and stuff } The application simply didn't work (application-->Show a green triangle), it showed a colored background (without triangle).       I assumed that the object did not created, maybe it did, so I decided to pass a manager (objectmanager pointer) to the sceneInit function and check if the manager contain the object:   Scene Init changed void SceneManager::SceneInit(objmanager* m_objmanager) { GameObject* obj1; //set the gameobject m_objmanager->AddGameObject(obj1); //added to objectmanager vector //a lot of code, set shader, and stuff } It worked, So i decided to pass every manager as arguments to the function that needed them (and to be clear, this is what I want)----->here the problems appeared. I had troubles to render, because i was passing "renderer" to a component of a gameobject that was on a vector of a manager, and that renderer to the meshrenderer, to the material, to the shader ...   Two ways 1) review every line of code (which i did) and try to figure out what was the problem (which i didn't) .....and 2) try another method...   then I discover the singletons  --->  the result: everything works!, even now, So, are they pureee evill? ...   What is the difference in the above code? i mean, why it worked when passing the pointer?
  11. One thing, i'm using directx, not opengl, i was using opengl before in a console application I'm gonna try again with the breakpoint, this time below the line
  12. I have this: core--->manager1        --->manager2 --->class 1 --->class 2 ---> class 3 ...(etc)   managerX is a member of core class   So, if i have to call "manager1" from class 3.cpp (class3 referenced to class 2, 2 referenced to 1, and 1 to Manager2), what's the correct way of doing this? should I define all managers like static objects and included their h file in "core", or define them inside my "core" class?
  13. Yes, i had this approach previously, but i had problems passing pointers in my components classes (from meshrenderer ->material->shader) , then i chose singletons, and for now it's working fine.   the problem: inside a cpp file I was able to call any of the managers (pointers) and use their methods, but if I need a method from a manager of a manager (example m_renderer ->getd3d() ->getdevice()), there was a problem.     This is actually wrong, singletons(at least by the design of the pattern) will always be constructed with the first call to whatever Get function you are using.   Static is a bit of a confusing keyword in C++ since it means different things in different places. The construction order issue is relegated to any kind of global object since global instances are not contained in a function there is no logical way to construct them from scoped code. In terms of global object the word static simply affects the linkage of the object.   A lot of people have issues with singletons for two seperate but related reasons. The first is that singletons are essentially masquerading globals, their construction is hidden in a function call but due to the Get call having to be static they are essentially globals, there will only be one created during the program lifetime and it is accessible from anywhere. The second issue and more prevalent one is that good engineering practice tends to say that globals are signals of bad code, they ironically create tight coupling by being accessible from anywhere because a complex weave of object interrelations begins to form between game and engine objects and the often large global "subsystems" that people make, i.e. a renderer, a state manager.   I can briefly go over the difference between a global and the different static constructs.   Global variables are technically any variable declared at global(program) scope. By itself a global isn't very useful, if you declare an int value in a header file and include it more than once it will cause linking errors(possibly compilation) since you will get multiply defined symbols. By declaring a global as extern and defining it ONCE(in a cpp file) all code can reference that one variable.   Which brings us to our uses of static: Static on a global variable gives it internal linkage, this means the variable can be included by multiple files but each that includes it will get its own copy of the variable, they won't be shared and modifying one will not affect the others. Linkage basically refers to whether the variable will be visible and possibly accessible to other compilation units. Static on a member variable is a bit different, it essentially means that the variable belongs to the class itself and only one will exist between all instances of the class. Static on a member function has more or less the same effect as above, the function can be accessed through the class name itself and thus the function can't interact with any member variables of the class since it isn't actually part of any particular instance(there may not even be any.) Static on a variable declared inside a function means the variable will be initialized only when the function is first called and will retain that state between function calls.   Using the above, a singleton must be created by at the very least having a static variable representing itself or in reference to itself. You could do that with a static function containing a static object declaration, that would create the object on first function call.   Either way the point is that a singleton is just a trick essentially in order to control the order of instantiation with a global, the same could be attained by only constructing globals with basic functionality and doing actual startup through an Init function. The book the OP referred to actually describes this quite a bit in detail, and he also later describes the singleton pattern as being semi-commonly used in game development but not necessarily ideal.     thanks for taking the time for the answer, it's really helpful anyway, in these days i learned a lot of c++ and how the rendering pipeline works, this it's my hobby so i don't pretend to be good at this in just a couple of days.   regards!
  14.   Thanks!   before use singletons i was defining every manager (renderer, core, objmanager) like a static object. I was getting some errors. From the book "game engine architecture" I read how to implement this managers, and the author used singletons, so this is why I used them.   Give me an example on how implement a class with a static object, and maybe I will be convinced.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!