Jump to content
  • Advertisement

FantasyVII

Member
  • Content Count

    226
  • Joined

  • Last visited

Community Reputation

1074 Excellent

About FantasyVII

  • Rank
    Member

Personal Information

  • Role
    Programmer
  • Interests
    Education
    Programming

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I'm not. I didn't know you had to do that !! How do you do that?
  2. Ok, this is actually driving me crazy... If I enable v-sync the issue is fixed. If I disable v-sync and let the program run at 2000+ FPS the issue is fixed. If I disable v-sync and limit my frame rate to 60 or anything under 60 like let's say 40 FPS using C++ timer my issue comes back. If I do point 3 and attach RenderDoc to my engine the issue is fixed. If I only have a single uniform buffer the issue is fixed. If I increase the number of planes rendered on the screen from 25 planes to 1000 planes the issue is fixed. if I increase my buffer size to 256 bytes the issue is fixed. If I only update my materials uniform buffer once the issue is fixed. If I set the output Color manually in the fragment shader like so (color = vec4(1.0, 0, 0, 1.0);) without using any uniform buffer objects the issue is fixed. However, in all of these cases, the issue is not really fixed. This is really driving me crazy..... I tested this one a GTX 970 and GTX 950M and I get the same issue. I would test it on an AMD card if I had one I changed my drivers and that didn't help... Is there any way I can debug this better? I'm literally getting nowhere...
  3. No, only to my C++ struct. I tried both and that didn't help. You can see my ColorBuffer in my original post up top. The SystemBuffer in C++ corresponds to camera_data in the shader. The ColorBuffer in C++ corresponds to MaterialUniform in the shader. I assume you can have multiple uniform buffers, one for the camera and one for the material and you can update both for a single shader. Am I right?
  4. Update: After 2 full days of debugging... the only way I seem to solve this problem is by adding 3 x vector4 as padding to get the size of my struct to 256 bytes. This seems to solve the problem. But I don't understand why. I understand the struct size has to be a multiple of 16 bytes. 208 bytes is multiple of 16. 208 / 16 = 13. So why do I get color flickering when my camera struct is at 208 bytes but not at 256 bytes???? if I query "GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT" it returns 256bytes. but from my understanding, that this is only necessary if you want to have multiple buffers on the same binding point, each buffer has to be 256 bytes. That is not the case for me. The system Buffer is bound at point 0 and the color buffer is bound at point 2. GLint uniformBufferAlignSize = 0; glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &uniformBufferAlignSize); struct SystemBuffer { BF::Math::Matrix4 modelMatrix; // 0 + 4 bytes * 4 floats * 4 vector4 = 64 byte BF::Math::Matrix4 viewMatrix; // 64 + 4 bytes * 4 floats * 4 vector4 = 128 byte BF::Math::Matrix4 projectionMatrix; // 128 + 4 bytes * 4 floats * 4 vector4 = 192 byte BF::Math::Vector4f cameraPosition; // 192 + 4 bytes * 4 floats = 208 byte BF::Math::Vector4f pading[3]; // 208 + 4 bytes * 4 floats * 3 array elements = 256 byte }; Never mind. That still didn't solve anything..... ☹️
  5. Hi everyone, I have an issue where my geometry color would flicker from red to black. I narrowed the issue down to it being caused by my Uniform Buffers, but for the life of me I cannot figure out why its happening. So I have two Uniform Buffers. One for my camera matrices and the other is for my material colors. This is my first buffer, the camera buffer and this is how it looks like struct SystemBuffer { BF::Math::Matrix4 modelMatrix; // 0 + 4 bytes * 4 floats * 4 vector4 = 64 byte BF::Math::Matrix4 viewMatrix; // 64 + 4 bytes * 4 floats * 4 vector4 = 128 byte BF::Math::Matrix4 projectionMatrix; // 128 + 4 bytes * 4 floats * 4 vector4 = 192 byte BF::Math::Vector4f cameraPosition; // 192 + 4 bytes * 4 floats = 208 byte }; This is 208 bytes and is aligned perfectly for OpenGL std140 as far as I know. This is my second buffer, the material buffer and this is how it looks like struct ColorBuffer { Color ambientColor; // 0 + 4 bytes * 4 floats = 16 byte Color diffuseColor; // 16 + 4 bytes * 4 floats = 32 byte Color specularColor; // 32 + 4 bytes * 4 floats = 48 byte float shininess = 0.0f; // 48 + 4 bytes = 52 byte }; This is 52 bytes and is also aligned perfectly for OpenGL std140 as far as I know. My issue is that if I remove the shininess variable from my color buffer, my geometry does not flicker to black at all and the problem is solved the flickering is reduced a lot but still does not get better. However, when I add that variable back it goes back to flickering. I tried to add padding as in add 3 more floats under the shininess variable to make my ColorBuffer a multiple of 16 bytes but that did not help at all. This is how my uniform buffer class looks like namespace BF { namespace Platform { namespace API { namespace OpenGL { GLConstantBuffer::GLConstantBuffer() : buffer(0), bindingIndex(0) { } GLConstantBuffer::~GLConstantBuffer() { GLCall(glDeleteBuffers(1, &buffer)); } void GLConstantBuffer::Create(unsigned int size, unsigned int bindingIndex) { this->bindingIndex = bindingIndex; GLCall(glGenBuffers(1, &buffer)); GLCall(glBindBufferBase(GL_UNIFORM_BUFFER, bindingIndex, buffer)); GLCall(glBufferData(GL_UNIFORM_BUFFER, size, nullptr, GL_STATIC_DRAW)); GLCall(glBindBuffer(GL_UNIFORM_BUFFER, 0)); } void GLConstantBuffer::Update(const void* data, unsigned int size) { GLCall(glBindBufferBase(GL_UNIFORM_BUFFER, bindingIndex, buffer)); GLCall(glBufferSubData(GL_UNIFORM_BUFFER, 0, size, data)); GLCall(glBindBuffer(GL_UNIFORM_BUFFER, 0)); } } } } } This is my usage for the buffers void Camera::Initialize() { constantBuffer.Create(sizeof(SystemBuffer), 0); } void Camera::Update() { constantBuffer.Update(&systemBuffer, sizeof(SystemBuffer)); } //------ void ForwardRenderer::Initialize() { materialConstantBuffer.Create(sizeof(MeshMaterial::ColorBuffer), 2); } void ForwardRenderer::Render() { // clear depth + color buffers for (size_t i = 0; i < meshes.size(); i++) { //transform meshe constantBuffer.Update(&systemBuffer, sizeof(SystemBuffer)); materialConstantBuffer.Update(&meshes[i]->material->colorBuffer, sizeof(MeshMaterial::ColorBuffer)); //draw } } and this is how my shader looks like vertexShader = R"( #version 450 core layout(location = 0) in vec3 inPosition; layout (std140, binding = 0) uniform camera_data { mat4 buffer_modelMatrix; mat4 buffer_viewMatrix; mat4 buffer_projectionMatrix; vec4 cameraPos; }; void main() { vec4 worldSpace = buffer_modelMatrix * vec4(inPosition.xyz, 1.0f); gl_Position = buffer_projectionMatrix * buffer_viewMatrix * worldSpace; } )"; pixelShader = R"( #version 450 core struct Material { vec4 ambientColor; vec4 diffuseColor; vec4 specularColor; float shininess; }; layout (std140, binding = 2) uniform MaterialUniform { Material material; }; out vec4 color; void main() { color = material.ambientColor * material.diffuseColor * material.specularColor; } )"; All these planes will flicker randomly to black then back to red. Any help would be greatly appreciated.
  6. FantasyVII

    different meshes, different shaders.

    oops. I thought I did post it in the graphics section. It was 4 am when I posted this. I guess graphics is close enough to gameplay. I'm using almost every graphics API out there. DX11, GL4+, GLES and Metal. That's perfect. Thanks !
  7. FantasyVII

    different meshes, different shaders.

    Yeah, I was thinking the same exact thing. Alright. Thanks for confirming.
  8. Let's say I have a mesh that only has vertex position and UV's. Lets say I have another mesh that has position data and normals only. Let's say I have another one that has position, UV's and Normal data. Do I make a struct that is tailored for each mesh? One struct that has only position and UV and another that has only position and normals and so on? For shaders, do I do the same? One shader that takes in position and UV's and another that takes position and normals etc.... Then I render all the meshes that have things in common together? Or do I make one big struct that has UV, position, normals, binormal and tangent and send it to one shader? If I do it this way I'm sending extra unnecessary data to the gpu if one of the meshes doesn't have normals or UV's for example.
  9. i did. ok, here it goes. This took me two days of trying random things and looking at the FreeImage source code. I can't believe I actually made this work. I'm actually a bit proud of myself right now. Anyway, I finally fixed this. although I'm still not sure why this fix is needed when including windows.h file. Why this wasn't an issue before including windows.h? anyways, here it is. So if you look at the "Utilities.h" file you will see this //FreeImage.h #define DLL_CALLCONV __stdcall #define DLL_API __declspec(dllexport) //---------------------------------------- //Utilities.h #if defined(__cplusplus) extern "C" { #endif DLL_API FIBITMAP * DLL_CALLCONV FreeImage_AllocateHeaderT(BOOL header_only, FREE_IMAGE_TYPE type, int width, int height, int bpp FI_DEFAULT(8), unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0)); DLL_API FIBITMAP * DLL_CALLCONV FreeImage_AllocateHeader(BOOL header_only, int width, int height, int bpp, unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0)); DLL_API FIBITMAP * DLL_CALLCONV FreeImage_AllocateHeaderForBits(BYTE *ext_bits, unsigned ext_pitch, FREE_IMAGE_TYPE type, int width, int height, int bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask); DLL_API BOOL DLL_CALLCONV FreeImage_HasRGBMasks(FIBITMAP *dib); #if defined(__cplusplus) } #endif BOOL SwapRedBlue32(FIBITMAP* dib); //This is the function that I want to use SwapRedBlue32 is the function that I want to use in my engine. Keep in mind I'm building FreeImage as a static library and linking it to my engine. Anyway, if you are an experienced c++ programmer (not me) you would have figured out by now why I got the linking issue only with the SwapRedBlue32 function. It's because it's not inside the extern "C" block. so after doing the following, everything worked just fine. //FreeImage.h #define DLL_CALLCONV __stdcall #define DLL_API __declspec(dllexport) //---------------------------------------- //Utilities.h #if defined(__cplusplus) extern "C" { #endif DLL_API FIBITMAP * DLL_CALLCONV FreeImage_AllocateHeaderT(BOOL header_only, FREE_IMAGE_TYPE type, int width, int height, int bpp FI_DEFAULT(8), unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0)); DLL_API FIBITMAP * DLL_CALLCONV FreeImage_AllocateHeader(BOOL header_only, int width, int height, int bpp, unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0)); DLL_API FIBITMAP * DLL_CALLCONV FreeImage_AllocateHeaderForBits(BYTE *ext_bits, unsigned ext_pitch, FREE_IMAGE_TYPE type, int width, int height, int bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask); DLL_API BOOL DLL_CALLCONV FreeImage_HasRGBMasks(FIBITMAP *dib); DLL_API BOOL DLL_CALLCONV SwapRedBlue32(FIBITMAP* dib); #if defined(__cplusplus) } #endif I still don't know why this wasn't an issue before including the Windows.h header file. You would think that this linking problem would be a problem without having to include Windows.h. I would love someone to explain this to me. Why does including Windows.h causes this issue and why this fix worked.
  10. That didn't help This is super frustrating Maybe I should just switch to another library. uhh...
  11. You mean if I try to #include <windows.h> inside the source code of FreeImage? If I do that I get a bunch of errors and the FreeImage lib will not compile.
  12. This is why this makes zero sense to me. I have FreeImage compiled as a static lib file and it is linked into my project just fine. If I don't include the Windows.h header file, my engine compiles and links and even runs and works perfectly. But the second I include Windows.h header in the same source file I have FreeImage in, I get the link error which makes zero sense to me. //Link error #include <Windows.h> #include "FreeImage/FreeImage.h" #include "FreeImage/Utilities.h" //----------------------------------------- //'HANDLE': undeclared identifier #include "FreeImage/FreeImage.h" #include "FreeImage/Utilities.h" #include <Windows.h> //----------------------------------------- //Works and runs perfectly fine. #include "FreeImage/FreeImage.h" #include "FreeImage/Utilities.h"
  13. Hi, I'm using the FreeImage library to load images into my game engine. However, I have a small problem. There is a header file called Utilities.h and it contains a function called SwapRedBlue32. My problem is that if I include Windows.h at the very top of my ImageLoader class and then include FreeImage headers after it I get an unresolved external error. The linker will not be able to link to the SwapRedBlue32 function. If I don't include Windows.h everything seems to work just fine. If I include Windows.h at the very bottom (after the FreeImage header files) I get 'HANDLE': undeclared identifier and many other windows related things become undeclared. I have no idea how to fix this. I really need both Windows.h and this function. How do I even begin to try to fix this? I looked at Utilities.h and FreeImage.h and I can't seem to figure out how to fix this. here is the error error LNK2019: unresolved external symbol "int __cdecl SwapRedBlue32(struct FIBITMAP *)" (?SwapRedBlue32@@YAHPEAUFIBITMAP@@@Z) referenced in function "public: static unsigned char * __cdecl BF::IO::ImageLoader::Load(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned int *,unsigned int *)" (?Load@ImageLoader@IO@BF@@SAPEAEAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAI1@Z)
  14. Sorry if I wasn't clear. I'm not talking about letters like j. Letters like j, g, p, q look fine to me. I'm taking about letters like a, c e, m, n, u. If you look at the first picture you will notice that all of these letters are above the base line where they should actually be on same line. I did try to do this, it gave me the same result as the first image. y = face->glyph->bitmap.rows - (face->glyph->metrics.horiBearingY >> 6); As far as I can tell from the values in my code both horiBearingY and bitmap_top are the same. This is a better image [Edit] Alright, this is the most progress that I have done in two days. if I do this unsigned int height = (face->bbox.yMax - face->bbox.yMin) >> 6; pos.y = height - face->glyph->bitmap.rows; all the characters line up nicely, but characters like j, g, p, q are now messed up.
  15. Hi everyone, I have been struggling with this issue for the past two days. I cannot render all my letters on the base line. I have used this function to set my font size unsigned int charPixelSize = 50; FT_Set_Pixel_Sizes(face, 0, charPixelSize); and when it's time to render a character I do this y = face->glyph->bitmap.rows - face->glyph->bitmap_top; But the line of code above will produce the image above. The only way I could get all my characters to render properly is by doing this y = (50 / 1.33333) - face->glyph->bitmap_top; in theory 50 should be my font size in pixels. But it seems that it is in points?? I don't know. If I divide 50 by 1.3333 this woks somewhat. The reason I'm diving by 1.33333 is because each point has 1.33333 pixels. I feel this whole division thing is a hacky way of getting this to work. Because 50 should be the font size in pixels not points. I don't know. I'm just lost. Any help would be appreciated. Cheers. [Edit] Alright, after a lot of reading and digging around, I finally was able to make this work. So what I did was loop through the entire list of characters and find the largest face->glyph->metrics.horiBearingY. After that I simply subtracted face->glyph->bitmap_top from the largest horiBearingY. int maxY = 0; //Loop through every character and get the biggest horiBearingY. for() { if (face->glyph->metrics.horiBearingY > maxY) maxY = face->glyph->metrics.horiBearingY >> 6; } void RenderText(std::string& text, Vector2 position) { Vector2 pos = position; //Loop through my text for() { pos.y = position.y + maxY - face->glyph->bitmap_top; } } Hope this will help someone else. Cheers.
  • 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!