Jump to content
  • Advertisement

lightbug

Member
  • Content Count

    23
  • Joined

  • Last visited

Everything posted by lightbug

  1. 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 
  2. 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
  3. 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!
  4. 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
  5. 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!
  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. Hi, I'm new in the singleton world, I used to think that i was using singletons, but really i was using static variables instead       example: I have Core.h: #pragma once #define WIN32_LEAN_AND_MEAN const bool FULL_SCREEN = false; const bool VSYNC_ENABLED = true; const float SCREEN_DEPTH = 1000.0f; const float SCREEN_NEAR = 0.1f; #include "Renderer.h" #include "inputclass.h" #include "Camera.h" #include "ObjectsManager.h" // #include "MeshRenderer.h" #include "ColorMaterial.h" #include "ColorShader.h" // #include "Game.h" class Core { private: //Singleton static Core* m_Core; Core(); Core(const Core&); ~Core(); bool Frame(bool first_frame); bool InitializeWindows(int&, int&); void ShutdownWindows(); LPCWSTR m_applicationName; HINSTANCE m_hinstance; HWND m_hwnd; //Singletons Renderer* m_renderer; ObjectsManager* m_Objmanager; InputClass* m_Input; Camera* m_Camera; Game* m_game; //test //D3DClass* d3d; //ID3D11Device* d3d_Device; //ID3D11DeviceContext* d3d_DeviceContext; ColorShader* color_shader; public: //Singleton static Core* GetInstance() { m_Core = new Core; return m_Core; } //Core(); bool Initialize(); void Shutdown(); void Run(); //get window handler LRESULT CALLBACK MessageHandler(HWND, UINT, WPARAM, LPARAM); //singletons inline HWND* GetHwnd() { return &m_hwnd; } inline Renderer* GetRenderer() { return m_renderer; } inline ObjectsManager* GetObjManager() { return m_Objmanager; } inline InputClass* GetInput() { return m_Input; } inline Camera* GetCamera() { return m_Camera; } inline Game* GetGame() { return m_game; } inline ColorShader* GetColorShader() { return color_shader; } }; static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); in Core.cpp I  have this line: Core* Core::m_Core = 0; I have the previous line in Renderer.cpp , Inputclass.cpp , .. and so on, in all my singletons classes.   So, in the cpp (where almost everything happens) I have initialize every singleton, Here is and example with renderer singleton inside Core::Initialize(): m_renderer = Renderer::GetInstance(); if (!m_renderer)return false; result = m_renderer->Initialize(screenWidth, screenHeight, m_hwnd, SCREEN_DEPTH, SCREEN_NEAR); if (!result) { return false; } in main.cpp: #include "Core.h" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline, int iCmdshow) { bool result; //Core Singleton Core* m_Core = Core::GetInstance(); // Initialize and run the system object. result = Core::GetInstance()->Initialize(); if (!result) return -1; //..... } Questions: 1 - Should I call m_renderer every time i want my renderer singleton (same with others) or should I call Renderer::GetInstance() ??   2 - How can I initialize a singleton that depends of another singleton? (for example first I have to initialize d3d, then initialize renderer)   3 - in main.cpp should I define a "m_Core" or use directly GetInstance()? what is the difference?   4 - Do I need to pass a singleton to a function? for example (inside core.cpp): bool Core::Frame() { bool result; //... //some code //... result = m_renderer->Frame(m_Camera->GetViewMatrix() , m_Camera->GetProjectionMatrix() , m_Objmanager); //... //some code //... return true; } As you can see, i'm passing camera and objmanager singletons, can I call this singleton inside m_renderer->Frame? (previously i was using this and had too many problems, so i started to pass everything i need)     sorry about my english   Thanks!    
  10. Hi, this is my first post, first of all english is not my primary language, so I will try my best (and my friend google too) .   To the problem... I'm trying to create a small game engine (a component based approach), mostly rendering engine at first, but I have a strange error, strange because : 1) when is debugging (VS 2013) it crash, the typical .exe stop working, but when I run the same program directly with the .exe file it works fine. 2) when I'm trying to interact with my classes ( specifically with meshrenderer, material and shader) the program also crash (inside and outside VS)   3) When i'm using only d3d for begin and end scene (not for drawing any gameobject (not with shaders)) everything works fine, but when I include the shader part the program crash. The initialization of the shader result is ok, but the problem is when I add the shader to a material, and that material to a meshrenderer component, and that component to a gameobject (that's why I mean classes interaction)   4) I have created other project with some classes (not a win32 project,but a console application (without any of directx)) and test the member functions that supposedly fail, and works fine (example : create a gameobject , add a component , get that component , etc).   I have a class that is the core of the engine (named Core) , the game setup occurs in a function named Initialize(). In the console application (only for test purpose) all the code is in main function.   I'm using Directx11, DirectMath (xmfloat , xmmatrix , ...) , C++ , VS 2013 ultimate.   I know that without code it's imposible to find the error, but in test project all works fine.   Please i need help, i'm stuck   Thanks!!
  11.   great example! at least you didn't came out with the "muaahaha" and "the pure evil" sh&$t     I'll slowly killing all singletons
  12.   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?
  13. 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
  14. 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?
  15. 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!
  16.   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.
  17. Now i Have this: //Singleton static Core* GetInstance() { if (!m_Core) <----I forgot this m_Core = new Core; return m_Core; }     but... now, with singletons my life is easier, and only I have like four of them.   Anyway a singleton is static, so , what's the difference between define a static variable at the end of the class and create a singleton?
  18.   I did that, no errors. This is getting weird/annoying
  19. Wow thanks answer so fast     How do I do that? (Debug after CreateWindowEx)
  20. Previously I had a variable instead of a pointer. Now I have "m_hwnd" variable. But what is the difference?, I used " *m_hwd ".   Also now i use "reinterpret_cast<LPVOID>(this)" , because ... you said The debugger is still crashing at CreateWindowEx() , with my and with your initialization code . But outside of VS the program seems to be fine, so I wondering if the problem is in the IDE, or the project configuration.   Nothing strange with my variables:   m_hwnd:   -        m_hwnd    0x00000000 <NULL>    HWND__ *         unused    <Unable to read memory>       that's before the CreateWindowEx function.   little question-> can I do all these stuff with a simple main function  ( int main() ) ? like in another project with opengl that I made   EDIT: I just download a tutorial from rastertek, the tutorial 4 (draw a green triangle) , and I have used the debugger, it crash at the same function.   ( X files music ... )
  21. debugging with breakpoints (i put one in the first line of main, then use F11 or F10 to step in or step over) bool Core::Initialize() { m_hwnd = new HWND; int screenWidth = 0, screenHeight = 0; bool result; // Initialize the windows api. result = InitializeWindows(screenWidth, screenHeight); <<-------------------- if (!result) { MessageBox(*m_hwnd, L"Initialize window FAIL", L"Bienvenido", MB_OK); return false; } //...... the rest of initialization inside InitializeWindows... bool Core::InitializeWindows(int& screenWidth, int& screenHeight) { WNDCLASSEX wc; DEVMODE dmScreenSettings; int posX, posY; // Get an external pointer to this object. //ApplicationHandle = this; //MODIFIQUE OJOOOO //m_Core = this; // Get the instance of this application. m_hinstance = GetModuleHandle(NULL); // Give the application a name. m_applicationName = L"Engine"; // Setup the windows class with default settings. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = m_hinstance; wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hIconSm = wc.hIcon; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = m_applicationName; wc.cbSize = sizeof(WNDCLASSEX); // Register the window class. RegisterClassEx(&wc); // Determine the resolution of the clients desktop screen. screenWidth = GetSystemMetrics(SM_CXSCREEN); screenHeight = GetSystemMetrics(SM_CYSCREEN); // Setup the screen settings depending on whether it is running in full screen or in windowed mode. if(FULL_SCREEN) { // If full screen set the screen to maximum size of the users desktop and 32bit. memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); dmScreenSettings.dmSize = sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth = (unsigned long)screenWidth; dmScreenSettings.dmPelsHeight = (unsigned long)screenHeight; dmScreenSettings.dmBitsPerPel = 32; dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; // Change the display settings to full screen. ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN); // Set the position of the window to the top left corner. posX = posY = 0; } else { // If windowed then set it to 800x600 resolution. screenWidth = 800; screenHeight = 600; // Place the window in the middle of the screen. posX = (GetSystemMetrics(SM_CXSCREEN) - screenWidth) / 2; posY = (GetSystemMetrics(SM_CYSCREEN) - screenHeight) / 2; } // Create the window with the screen settings and get the handle to it. *m_hwnd = CreateWindowEx(WS_EX_APPWINDOW, m_applicationName, m_applicationName, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP, posX, posY, screenWidth, screenHeight, NULL, NULL, m_hinstance, NULL); // Bring the window up on the screen and set it as main focus. ShowWindow(*m_hwnd, SW_SHOW); SetForegroundWindow(*m_hwnd); SetFocus(*m_hwnd); // Hide the mouse cursor. ShowCursor(false); return true; } The crash occurs on "CreateWindowEx", at the moment of step over this function the program stops. -> Outside VS, with the .exe don't crash     Here is my Core.h #pragma once #define WIN32_LEAN_AND_MEAN const bool FULL_SCREEN = false; const bool VSYNC_ENABLED = true; const float SCREEN_DEPTH = 1000.0f; const float SCREEN_NEAR = 0.1f; #include "Renderer.h" #include "inputclass.h" #include "Camera.h" #include "ObjectsManager.h" // #include "MeshRenderer.h" #include "ColorMaterial.h" #include "ColorShader.h" // #include "Game.h" class Core { public: Core(); Core(const Core&); ~Core(); //bool Initialize(HINSTANCE, HWND, int, int) bool Initialize(); //bool InitializeSingletons void Shutdown(); void Run(); //get window handler LRESULT CALLBACK MessageHandler(HWND, UINT, WPARAM, LPARAM); //singletons inline HWND* GetHwnd() { return m_hwnd; } inline Renderer* GetRenderer() { return m_renderer; } inline ObjectsManager* GetObjManager() { return m_Objmanager; } inline InputClass* GetInput() { return m_Input; } inline Camera* GetCamera() { return m_Camera; } inline Game* GetGame() { return m_game; } inline GameObject* GetGameObject() { return obj1; } private: bool Frame(); bool InitializeWindows(int&, int&); void ShutdownWindows(); LPCWSTR m_applicationName; HINSTANCE m_hinstance; HWND* m_hwnd; //Singletons Renderer* m_renderer; ObjectsManager* m_Objmanager; InputClass* m_Input; Game* m_game; Camera* m_Camera; //test GameObject* obj1; ColorShader* cube_shader; ColorMaterial* cube_material; MeshRenderer* cube_meshRenderer; }; static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static Core* m_Core = new Core;
  22. thanks Irlan! , this are my classes headers in conflict:   MeshRenderer.h class ColorMaterial; class MeshRenderer : public Component { private: ColorMaterial* m_material; //... ColorMaterial.h class MeshRenderer; class ColorShader; class ColorMaterial { private: ColorShader* m_ColorShader; MeshRenderer* m_MeshRenderer; //... ColorShader.h class ColorMaterial; class ColorShader { private: ColorMaterial* m_material; The rest of the code (.h and .cpp) i believe is fine. I have been following the tutorials from rastertek.(http://www.rastertek.com/tutdx11.html) I have used forward declarations in these classes to communicate between classes, is this the right way?
  • 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!