Jump to content
  • Advertisement

Phil15

Member
  • Content Count

    25
  • Joined

  • Last visited

Community Reputation

184 Neutral

About Phil15

  • Rank
    Member
  1. Hi guys, I have been looking around for any graphics engine which would be able to load blender objects and display them on a website preferably ASP.net. The objects will have to be realistic. Sketchfab is one website which does this but their engine only allows movement left right zoom in/ out. I actually want to be able to navigate with keys within the object. Does anyone know if something is available. Can it be done with unreal engine or unity?
  2. Thanks everyone Looks I will stick with JNI for the time being. 
  3. Hello, There is a small dilemma, After developing a basic 3d engine in c++ it now needs to be ported to Android.  I was going to go with the usual NDK approach using JNI and calling the c++ library from Java. But now there is this Android native activity in Visual  Studio 2015( which uses c++)  and I don`t know if there are any disadvantages to using it. Most people say it`s slower but they usually refer to c# when saying that, I dont see how it can be slower with c++, does anyone  have any idea on this subject ?
  4. Phil15

    Best Way to Achieve Transformations?

    I have been where you are not so long ago. You have to get some grasp on matrices. But I would not recommend trying to know everything there is about them. I picked up a book called Math primer for Graphics and Game development and Chapter 7 introduction to matrices it gives you the fundamentals. When you read this chapter you will understand that a matrix is just a bunch of vectors. Best bet is to start from 2x2 matrices and multiply them yourself on a piece of paper to see what is going on. Check this website out: http://www.songho.ca/opengl/gl_matrix.html  play around with the example. Check this guy out he also gives an awesome explanation on MVP   A lot of matrix operations are in glm library, take a look at it.  This is also another video but a bit harder to grasp but it also explains a lot on Camera transform as long as you get the concept I think it will benefit you. Just like most things matrices are not too hard when you pick them apart and get the concept. Hope that helps.
  5. Do you know how much faster, and is it worth it? If it`s 5% faster than yeh I probably would not bother but if it`s a good 20%-30% performance increase than something should be done.
  6. I agree yet that means restructuring all the classes and the design of the engine which will take a considerate amount of time.
  7. Hi guys I wanted to get your opinion on this. I currently thought of making multiple classes each one will have a prepare and draw method. To prepare and render staff to screen.  The draw method has multiple glDraw() calls as it binds a texture and draws a part of the object binds next texture draw another part etc.. (I am aware this is quiet expensive but I maximum have 3 textures)  the draw method will be used by some base class which will call the corresponding draw method on every object. (The code should make more sense than this sentence :) )  Now the problem is that when I start creating multiple objects should If I just concatenate them into one big buffer  which should increase performance I will end up with restricted number of vertices because of  "glDrawElements(GL_TRIANGLES, Index, GL_UNSIGNED_SHORT, 0);"  GL_UNSIGNED_SHORT -> only 65,535 vertices  for all objects.... If however I keep the multiple draw calls I can have max 65,535  per object or am I being optimistic and the phone will just crash ??  RenderShip.cpp(some object with methods Draw and PrepareGraphics) void RenderShip::PrepareGraphics(std::string textureFilename, std::string modelFilename) { GLuint textureHandle; std::vector<GLfloat> rawData; objMtlLoader meshLoader; data = meshLoader.LoadFromFile(modelFilename); GLfloat * RawGraphicsData = data->GetRawArrayofValues(true, false); IndexPerTexture = data->IndxsPrTxtHndl(programId); std::vector<unsigned short> Indexes; // cannot be more than 15 textures any way std::vector<glm::vec3> * Vertices = data->GetVertices(); CenterMatrix = ModelPositioning::CenterModel(*Vertices); indexes = data->getIndexes(); indexSize = data->GetIndexSize(); GLint FragmentShaderTextureId; GLint VertexId; VertexId = glGetAttribLocation(programId, "position"); FragmentShaderTextureId = glGetAttribLocation(programId, "vertexUV"); glEnable(GL_DEPTH_TEST); GLuint myBuffId = 0; glGenBuffers(1, &myBuffId); glEnableVertexAttribArray(VertexId); glBindBuffer(GL_ARRAY_BUFFER, myBuffId); glBufferData(GL_ARRAY_BUFFER, indexSize * 5 * sizeof(float), RawGraphicsData, GL_STATIC_DRAW); glVertexAttribPointer(VertexId, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 5, 0); GLuint IndexBuffId = 0; glGenBuffers(1, &IndexBuffId); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBuffId); glEnableVertexAttribArray(FragmentShaderTextureId); glVertexAttribPointer(FragmentShaderTextureId, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 5, (char *)(sizeof(float) * 3)); // stride of 5 floats describing my colors starting at position 2 } void RenderShip::DrawShip() { glm::mat4 ModelViewProject(1.0f); glm::mat4 View(1.0f); glm::mat4 Model(1.0f); glm::mat4 Projection = glm::perspective(45.0f, 1024.0f / 768.0f, 0.1f, 15.0f); Model = CenterMatrix; ModelViewProject = Projection * camera->getWorldToViewMatrix() * Model; GLint transform = glGetUniformLocation(programId, "ModelViewProject"); glUniformMatrix4fv(transform, 1, false, glm::value_ptr(ModelViewProject));; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); GLuint IndexBuffId = 0; glGenBuffers(1, &IndexBuffId); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBuffId); GLuint textureHandle; for (std::map<GLuint, size_t>::iterator it = IndexPerTexture.begin(); it != IndexPerTexture.end(); it++) { glBufferData(GL_ELEMENT_ARRAY_BUFFER, it->second * sizeof(GLfloat), indexes, GL_DYNAMIC_DRAW); glBindTexture(GL_TEXTURE_2D, it->first); // Bind that texture temporarily glActiveTexture(it->first); glDrawElements(GL_TRIANGLES, it->second, GL_UNSIGNED_SHORT, 0); } } Renderer.cpp (Base class which will call draw on all objects) #include "Renderer.h" #include "RenderShip.h" #pragma once GLuint programId; int program; RenderShip * ship; void Renderer::Prepare() { programId = InstallShaders(); SendDataToOpenGL(); } void Renderer::Render() { ship->DrawShip(); } void Renderer::SetCamera(Camera& cam) { camera = &cam; } void Renderer::SendDataToOpenGL() { ship = new RenderShip(programId, (*camera)); ship->PrepareGraphics("textureWood.bmp", "untitled.obj"); } int Renderer::InstallShaders() { return ShaderHandler::InstallShaders(); }
  8. So what would you advise for serious work? I have written a class which reorders all the vertices and the texels in .obj file to be compatible with the GLDrawElements() call. And now I faced this problem with multiple texturing, what are other guys using?  
  9. Hi,   There are a lot of tutorials and questions online about multiple textures however most concentrate on mapping two or more textures to one place. If you have a mesh in blender which is textured with multiple textures, how can do you let opengl know which textures goes with which coordinates. When exported as an .obj file nothing indicates which image maps to specific set of coordinates. What strategies would you use to get over this problem??
  10. Phil15

    bmp Loader class

    Compression is optional in TGA files. I've never used it.   Ok I did some more research and now I am convinced. I will definitely look into rewriting my class to Tga at a later stage then.
  11. Phil15

    bmp Loader class

    Great. But you still have to load TGA files for transparency. Even if BMP files can technically support it, exporters almost never add it, and you didn’t add support for it anyway. L. Spiro   Yeh transparency, never thought of that, I didn`t even get so far to need transparency yet but cant you adjust that in a shader?
  12. Phil15

    bmp Loader class

    Finally it worked     int LoadBMPTextureFromFile(const std::string& Filename, GLuint& texture) { #ifdef _MSC_VER FILE* File = NULL; fopen_s(&File, Filename.c_str(), "rb"); #else FILE* File = fopen(Filename.c_str(), "rb"); #endif if (File == NULL) { //ILogger::Get() << "ERROR : LoadBMPTextureFromFile couldn't find, or failed to load " + Filename + ".\n"; return NULL; } UINT16 MagicNumber = 0; fread(&MagicNumber, sizeof(UINT16), 1, File); if (MagicNumber != BMP_MAGIC) { //ILogger::Get() << "ERROR : The file " + Filename + " doesn't appear to be a valid .bmp file.\n"; fclose(File); return NULL; } BMP_HEADER BMPHeader; fread(&BMPHeader, sizeof(BMP_HEADER), 1, File); BMP_INFO_HEADER BMPInfoHeader; fread(&BMPInfoHeader, sizeof(BMP_INFO_HEADER), 1, File); if ((BMPInfoHeader.Size != sizeof(BMP_INFO_HEADER)) || (BMPInfoHeader.Planes != 1)) { //ILogger::Get() << "ERROR : The file " + Filename + " doesn't appear to be a valid .bmp file.\n"; fclose(File); return 0; } if (BMPInfoHeader.Compression != 0) { //ILogger::Get() << "ERROR : The file " + Filename + " is a compressed .bmp file.\n"; fclose(File); return 0; } if (BMPInfoHeader.BitCount == 1) { //ILogger::Get() << "ERROR : The file " + Filename + " is a monochrome .bmp file.\n"; fclose(File); return 0; } else if (BMPInfoHeader.BitCount == 4) { //ILogger::Get() << "ERROR : The file " + Filename + " is a 4-bit .bmp file.\n"; fclose(File); return 0; } else if (BMPInfoHeader.BitCount == 16) { // ILogger::Get() << "ERROR : The file " + Filename + " is a 16-bit .bmp file.\n"; fclose(File); return 0; } fseek(File, BMPHeader.OffBits, SEEK_SET); BMP_IMAGE_DATA* BMPImageData = new BMP_IMAGE_DATA; memset(BMPImageData, 0, sizeof(BMP_IMAGE_DATA)); if (BMPInfoHeader.BitCount == 8) BMPImageData->Components = 1; else if (BMPInfoHeader.BitCount == 24) BMPImageData->Components = 3; else if (BMPInfoHeader.BitCount == 32) BMPImageData->Components = 4; UINT32 BufferSize = BMPInfoHeader.Width * BMPInfoHeader.Height * BMPImageData->Components; //BMPInfoHeader.SizeImage BMPImageData->Pixels = new UINT8[BufferSize]; fread(BMPImageData->Pixels, 1, BufferSize, File); UINT8 tmpRGB = 0; for (ULONG i = 0; i < BMPInfoHeader.SizeImage; i += 3) { if (i + 2 > BMPInfoHeader.SizeImage) // prevent going beyond allocated memory { break; } tmpRGB = BMPImageData->Pixels[i]; BMPImageData->Pixels[i] = BMPImageData->Pixels[i + 2]; BMPImageData->Pixels[i + 2] = tmpRGB; } GLuint w = BMPInfoHeader.Width; GLuint h = BMPInfoHeader.Height; glGenTextures(1, &texture); // Generate a texture glBindTexture(GL_TEXTURE_2D, texture); // Bind that texture temporarily GLint mode = GL_RGB; // Set the mode glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //// Create the texture. We get the offsets from the image, then we use it with the image's //// pixel data to create it. //must be multiple of 2 1024 x 1024, 512 x 512 , 256 x 256 glTexImage2D(GL_TEXTURE_2D, 0, mode, w, h, 0, mode, GL_UNSIGNED_BYTE, BMPImageData->Pixels); fclose(File); BMPImageData->Width = BMPInfoHeader.Width; BMPImageData->Height = BMPInfoHeader.Height; delete[] BMPImageData->Pixels; return 1; }
  13. Phil15

    bmp Loader class

    Yes bmp sucks but I feel so close. This code works perfectly with bmp only one flaw when I try to free the pixels I get heap corruption. !!!  The only reason I use this format because I dont want to overload my head with compression and decompression, as I understand and correct me if am wrong everything else including targa uses compression.    int bmpTextureLoader::loadBMP(const char* location, GLuint& texture) { uint8_t *datBuff[2] = { nullptr, nullptr }; uint8_t *pixels = nullptr; BITMAPFILEHEADER * bmpHeader = nullptr; BITMAPINFOHEADER * bmpInfo = nullptr; // The file... We open it with it's constructor std::ifstream file(location, std::ios::binary); if (!file) { return -1; } // Allocate byte memory that will hold the two headers datBuff[0] = new uint8_t[sizeof(BITMAPFILEHEADER)]; datBuff[1] = new uint8_t[sizeof(BITMAPINFOHEADER)]; file.read((char*)datBuff[0], sizeof(BITMAPFILEHEADER)); file.read((char*)datBuff[1], sizeof(BITMAPINFOHEADER)); // Construct the values from the buffers bmpHeader = (BITMAPFILEHEADER*)datBuff[0]; bmpInfo = (BITMAPINFOHEADER*)datBuff[1]; if (bmpHeader->bfType != 0x4D42) { return 2; } // First allocate pixel memory const int imageSize = bmpInfo->biSizeImage; pixels = new uint8_t[imageSize]; int size = sizeof(pixels); size = size; // Go to where image data starts, then read in image data file.seekg(bmpHeader->bfOffBits); file.read((char*)pixels, bmpInfo->biSizeImage); // We're almost done. We have our image loaded, however it's not in the right format. // .bmp files store image data in the BGR format, and we have to convert it to RGB. // Since we have the value in bytes, this shouldn't be to hard to accomplish uint8_t tmpRGB = 0; // Swap buffer int cmpress = bmpInfo->biCompression; cmpress = cmpress; int ImageSize = bmpInfo->biSizeImage; for (unsigned long i = 0; i < ImageSize; i += 3) { if (i + 2 > ImageSize) // prevent going beyond allocated memory { break; } tmpRGB = pixels[i]; pixels[i] = pixels[i + 2]; pixels[i + 2] = tmpRGB; } // Set width and height to the values loaded from the file GLuint w = bmpInfo->biWidth; GLuint h = bmpInfo->biHeight; /*******************GENERATING TEXTURES*******************/ glGenTextures(1, &texture); // Generate a texture glBindTexture(GL_TEXTURE_2D, texture); // Bind that texture temporarily GLint mode = GL_RGB; // Set the mode glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //// Create the texture. We get the offsets from the image, then we use it with the image's //// pixel data to create it. //must be multiple of 2 1024 x 1024, 512 x 512 , 256 x 256 glTexImage2D(GL_TEXTURE_2D, 0, mode, w, h, 0, mode, GL_UNSIGNED_BYTE, pixels); //// Unbind the texture // glBindTexture(GL_TEXTURE_2D, NULL); //// Output a successful message //// Delete the two buffers. delete[] datBuff[0]; delete[] datBuff[1]; //delete[] pixels; <--- this causes error return 0; // Return success code }  
  14. Phil15

    bmp Loader class

    Thanks for your replies. Unfortunately I cannot  use most of the libraries because I am trying to port a msvc c++ version to android and most windows libraries or libraries which work with opengl as opposed to opengles will not do, my bad I shoud have mentioned it .    I have adapted this code to add the texture but for some reason I get a black screen and I have no clue why, here is my code:    #include "BmpLoader.h" int LoadBMPTextureFromFile(const std::string& Filename, GLuint& texture) { #ifdef _MSC_VER FILE* File = NULL; fopen_s(&File, Filename.c_str(), "rb"); #else FILE* File = fopen(Filename.c_str(), "rb"); #endif if (File == NULL) { //ILogger::Get() << "ERROR : LoadBMPTextureFromFile couldn't find, or failed to load " + Filename + ".\n"; return NULL; } UINT16 MagicNumber = 0; fread(&MagicNumber, sizeof(UINT16), 1, File); if (MagicNumber != BMP_MAGIC) { //ILogger::Get() << "ERROR : The file " + Filename + " doesn't appear to be a valid .bmp file.\n"; fclose(File); return NULL; } BMP_HEADER BMPHeader; fread(&BMPHeader, sizeof(BMP_HEADER), 1, File); BMP_INFO_HEADER BMPInfoHeader; fread(&BMPInfoHeader, sizeof(BMP_INFO_HEADER), 1, File); if ((BMPInfoHeader.Size != sizeof(BMP_INFO_HEADER)) || (BMPInfoHeader.Planes != 1)) { //ILogger::Get() << "ERROR : The file " + Filename + " doesn't appear to be a valid .bmp file.\n"; fclose(File); return 0; } if (BMPInfoHeader.Compression != 0) { //ILogger::Get() << "ERROR : The file " + Filename + " is a compressed .bmp file.\n"; fclose(File); return 0; } if (BMPInfoHeader.BitCount == 1) { //ILogger::Get() << "ERROR : The file " + Filename + " is a monochrome .bmp file.\n"; fclose(File); return 0; } else if (BMPInfoHeader.BitCount == 4) { //ILogger::Get() << "ERROR : The file " + Filename + " is a 4-bit .bmp file.\n"; fclose(File); return 0; } else if (BMPInfoHeader.BitCount == 16) { // ILogger::Get() << "ERROR : The file " + Filename + " is a 16-bit .bmp file.\n"; fclose(File); return 0; } fseek(File, BMPHeader.OffBits, SEEK_SET); BMP_IMAGE_DATA* BMPImageData = new BMP_IMAGE_DATA; memset(BMPImageData, 0, sizeof(BMP_IMAGE_DATA)); if (BMPInfoHeader.BitCount == 8) BMPImageData->Components = 1; else if (BMPInfoHeader.BitCount == 24) BMPImageData->Components = 3; else if (BMPInfoHeader.BitCount == 32) BMPImageData->Components = 4; UINT32 BufferSize = BMPInfoHeader.Width * BMPInfoHeader.Height * BMPImageData->Components; BMPImageData->Pixels = new UINT8[BufferSize]; fread(BMPImageData->Pixels, 1, BufferSize, File); UINT8 tmpRGB = 0; for (ULONG i = 0; i < BMPInfoHeader.SizeImage; i += 3) { if (i + 2 > BMPInfoHeader.SizeImage) // prevent going beyond allocated memory { break; } tmpRGB = BMPImageData->Pixels[i]; BMPImageData->Pixels[i] = BMPImageData->Pixels[i + 2]; BMPImageData->Pixels[i + 2] = tmpRGB; } glGenTextures(1, &texture); // Generate a texture glBindTexture(GL_TEXTURE_2D, texture); // Bind that texture temporarily GLint mode = GL_RGB; // Set the mode glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //// Create the texture. We get the offsets from the image, then we use it with the image's //// pixel data to create it. //must be multiple of 2 1024 x 1024, 512 x 512 , 256 x 256 glTexImage2D(GL_TEXTURE_2D, 0, mode, BMPImageData->Width, BMPImageData->Height, 0, mode, GL_UNSIGNED_BYTE, BMPImageData->Pixels); fclose(File); BMPImageData->Width = BMPInfoHeader.Width; BMPImageData->Height = BMPInfoHeader.Height; delete BMPImageData->Pixels; return 1; }
  15. Hello, I was building a class to load a bmp file 24 bit depth. To make it simple at first I have created a 2x2 image in paint with 4 pixels red, green, blue and white. when I open the image in a hex editor I count the 54 bit header offset and try and make sense of the values. The first 3 bytes I get is red but all the next BGR values are not what I expect them to be. also every pixel is 3 bytes but there is C++ no type with 3 bytes could I use uint or can that corrupt the colors when changing from BGR to RGB? Code so far:   int bmpTextureLoader::loadBMP(const char* location, GLuint& texture) { UINT16 *datBuff[2] = { nullptr, nullptr }; UINT16 *pixels = nullptr; BITMAPFILEHEADER * bmpHeader = nullptr; BITMAPINFOHEADER * bmpInfo = nullptr; // The file... We open it with it's constructor std::ifstream file(location, std::ios::binary); if (!file) { return -1; } // Allocate byte memory that will hold the two headers datBuff[0] = new UINT16[sizeof(BITMAPFILEHEADER)]; datBuff[1] = new UINT16[sizeof(BITMAPINFOHEADER)]; file.read((char*)datBuff[0], sizeof(BITMAPFILEHEADER)); file.read((char*)datBuff[1], sizeof(BITMAPINFOHEADER)); // Construct the values from the buffers bmpHeader = (BITMAPFILEHEADER*)datBuff[0]; bmpInfo = (BITMAPINFOHEADER*)datBuff[1]; if (bmpHeader->bfType != 0x4D42) { return 2; } // First allocate pixel memory const int imageSize = bmpInfo->biSizeImage; pixels = new UINT16[imageSize]; int size = sizeof(pixels); size = size; file.seekg(bmpHeader->bfOffBits); file.read((char*)pixels, bmpInfo->biSizeImage); UINT16 tmpRGB = 0; // Swap buffer int cmpress = bmpInfo->biCompression; cmpress = cmpress; for (unsigned long i = 0; i < bmpInfo->biSizeImage; i += 3) { tmpRGB = pixels[i]; pixels[i] = pixels[i + 2]; pixels[i + 2] = tmpRGB; } // Set width and height to the values loaded from the file GLuint w = bmpInfo->biWidth; GLuint h = bmpInfo->biHeight; glGenTextures(1, &texture); // Generate a texture glBindTexture(GL_TEXTURE_2D, texture); // Bind that texture temporarily GLint mode = GL_RGB; // Set the mode glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //// Create the texture. We get the offsets from the image, then we use it with the image's //// pixel data to create it. //must be multiple of 2 1024 x 1024, 512 x 512 , 256 x 256 glTexImage2D(GL_TEXTURE_2D, 0, mode, w, h, 0, mode, GL_UNSIGNED_BYTE, pixels); //// Delete the two buffers. delete[] datBuff[0]; delete[] datBuff[1]; delete[] pixels; return 0; // Return success code }
  • 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!