FantasyVII

Member
  • Content count

    221
  • Joined

  • Last visited

Community Reputation

1074 Excellent

About FantasyVII

  • Rank
    Member

Personal Information

  • Interests
    Education
    Programming
  1. 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 !
  2. different meshes, different shaders.

    Yeah, I was thinking the same exact thing. Alright. Thanks for confirming.
  3. 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.
  4. 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.
  5. That didn't help This is super frustrating Maybe I should just switch to another library. uhh...
  6. 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.
  7. 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"
  8. 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)
  9. 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.
  10. 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.
  11. Bin packing

      So my tree looks right? only thing I have to do is go to node 1 instead of node 0 if node 0 fails?
  12. Bin packing

    Hi everyone,   I'm having trouble understand this algorithm  http://blackpawn.com/texts/lightmaps/default.html   Here what I understood from the algorithm.   First lets assume my large texture is 128 x 128. Lets also assume the first texture I want to add is 32 x 32 pixels. So according to the algorithm I have to split my big texture into two regions. After that I add the 32 x 32 blue texture. At this point my tree and texture looks something like this     After that lets assume the next texture I want to pack is 32 x 96 green texture. So my tree would look something like this,     finally lets try and add another 32x32 pink texture. Here is my problem.       When I look at node 0 and 1 I can see that the 32 x 32 pink texture can fit in both nodes. but since node 0 is first, I will pick that node. But if you go down the tree you can see that the last node size is 0, 0 which means there is no space left. My question is now what do I do? if I just go back to the root node and do the same thing I will get to the same consultation. Unless I have to somehow update node 0 every time I add a new texture. But if that is the case he never explained how that would work.   I don't understand this algorithm. Any help would be appreciated.    Cheers.
  13. Well my engine supports both DirectX 11 and OpenGL 4+. So if you have advice for either APIs that would be great.   I will check out Array Textures and see if I can make it work. What is the equivalent of that in D3D11?   I did read somewhere that Array Textures in OpenGL is evil. I forgot why though. That was a long time ago.
  14. man..... I can't believe I wasted all day just to solve this problem.   adding this code in my pixel shader fixed the issue. if(texID == 0) color = texture(textures[0], shared_data.UV); if(texID == 1) color = texture(textures[1], shared_data.UV); if(texID == 2) color = texture(textures[2], shared_data.UV); I don't understand why the above code works but this creates artifacts.... color = texture(textures[texID], shared_data.UV); they are basically the same thing. aren't they?
  15. Hi,   I'm trying to render multiple textures on a single mesh. What i'm doing is binding three different textures using texture units and i'm adding those textureIDs to my vertex buffer. So my vertex buffer looks something like this [vec3 , vec4 , vec2 , vec3 , float ] Vertex Buffer = [vertex position, vertex color, texcoord, normal, textureID] and in my pixel shader I have an array of texture samplers and I render the correct texture using textureID as an index to the array.   This works great, my only problem is that i'm getting some texture artifacting. From the looks of it some textures are partly being drawn on top of other textures.     https://www.youtube.com/watch?v=yQiRgVCbewE     I don't know if this a good way of drawing multiple textures on a mesh. If you guys know a more efficient way of doing this I would love to know about it.     here is how I draw everything void init() { glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBufferData(GL_ARRAY_BUFFER, size, data, GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); } //-------- void Draw() { //I think the problem is this block of code //----- glActiveTexture(GL_TEXTURE0 + 0); glBindTexture(GL_TEXTURE_2D, texture1); glUniform1i(glGetUniformLocation(glshader->GetProgramID(), "textures[0]"), 0); glActiveTexture(GL_TEXTURE0 + 1); glBindTexture(GL_TEXTURE_2D, texture2); glUniform1i(glGetUniformLocation(glshader->GetProgramID(), "textures[1]"), 1); glActiveTexture(GL_TEXTURE0 + 2); glBindTexture(GL_TEXTURE_2D, texture3); glUniform1i(glGetUniformLocation(glshader->GetProgramID(), "textures[2]"), 2); //----- vertexBuffer->Bind(); indexBuffer->Bind(); glDrawElements(GL_TRIANGLES, indexBuffer->GetIndicesCount(), GL_UNSIGNED_INT, nullptr); indexBuffer->Unbind(); vertexBuffer->Unbind(); } here is my vertex shader #version 450 core layout(location = 0) in vec3 inPosition; layout(location = 1) in vec4 inColor; layout(location = 2) in vec2 inUV; layout(location = 3) in vec3 inNormals; layout(location = 4) in float inTextureID; struct data { vec2 UV; float textureID; }; out data shared_data; void main() { shared_data.UV = inUV; shared_data.textureID = inTextureID; } here is my pixel shader #version 450 core struct data { vec2 UV; float textureID; }; in data shared_data; out vec4 color; uniform sampler2D textures[3]; void main() { int texID = int(shared_data.textureID); color = texture(textures[texID], shared_data.UV); }