• Advertisement

Hector San Roman Lanza

Member
  • Content count

    40
  • Joined

  • Last visited

Community Reputation

158 Neutral

About Hector San Roman Lanza

  • Rank
    Member
  1. But, It should be the opposite. If damperForce is >0 then the vehicle is more stable...   The code: // UNITY 5.4.0 //Constant values float suspensionLength = 1.0f; float stiffness = 0.4f; float dampingForce = 1.0f; void FixedUpdate()     {         RaycastHit hit;                 for (int i = 0; i < wheelPoints.Length; i++)         {             var wheelPoint = wheelPoints[i];             if (Physics.Raycast(wheelPoint.transform.position,                                 -transform.up,                                 out hit,                                 suspensionLength,                                 layerMask))             {                 float contactDepth = suspensionLength - hit.distance;                 float contactSpeed = contactDepth - lastContactDepth;                 float suspensionForce = stiffness * contactDepth + dampingForce * contactSpeed;                 suspensionForce *= 500;                 rigidBody.AddForceAtPosition(transform.up * suspensionForce, wheelPoints[i].transform.position, ForceMode.Force);                 lastContactDepth = contactDepth;             }         }     }
  2. Hi! I render the depth texture to generate the shadow mapping.  I am following this tutorial: http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/ In this tutorial, the author obtain a greyscale depthmap, but I obtain a red depth map without gradient. My code:         // After initialize the meshes and load the textures, generate the textures in OpenGL void Engine::GenerateTextures() {     // Generate the textures     textureCount = texturelist.size()+1; texturesID.reserve(textureCount);   // +1 to reserve space for depth texture glGenTextures(textureCount, &texturesID[0]);     int c = 0;     foreach(std::list<Texture*>, texturelist)     {         glActiveTexture(GL_TEXTURE0+c);         glBindTexture(GL_TEXTURE_2D, texturesID[c]);         ExitOnGLError("Error: Could not bind the texture");         glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, (*it)->width, (*it)->height, 0, GL_BGRA,GL_UNSIGNED_BYTE,(*it)->pixels );         ExitOnGLError("Error: Could not create the texture with glTexImage2D");         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);         //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);         //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);         glGenerateMipmap(GL_TEXTURE_2D);         c++;     }     // Initialize and binds the framebuffer.     ShadowFramebuffer = 0;     glGenFramebuffers(1, &ShadowFramebuffer);     glBindFramebuffer(GL_FRAMEBUFFER, ShadowFramebuffer);     // Generate the depth texture     glActiveTexture(GL_TEXTURE0+c);     glBindTexture(GL_TEXTURE_2D, texturesID[c]);     ExitOnGLError("Error: Could not bind the shadow texture");     glTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT16, 1024, 1024, 0,GL_DEPTH_COMPONENT, GL_FLOAT, 0);     ExitOnGLError("Error: Could not create the shadow texture with glTexImage2D");     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);     // Attach the texture to the framebuffer     glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,  texturesID[c], 0);     ExitOnGLError("Error: Could not attach the texture to the frame buffer");     glDrawBuffer(GL_NONE); // No color buffer is drawn to.     ExitOnGLError("Error: Could not draw the buffer");     if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)         ExitOnGLError("Error: FrameBuffer isn´t OK");     glBindFramebuffer(GL_FRAMEBUFFER, 0); }     void Engine::Draw(void) {     drawDepthMap = true;     if(drawDepthMap)     {        // draw the objects using the depthRTT shader         foreach(std::list<GameScreen*>, gamescreens)         {             (*it)->Draw();         }     } }        depthRTT.glsl #ifdef COMPILING_VS layout(location=0) in vec4 in_Position; uniform mat4 ModelMatrix; uniform mat4 ViewMatrix; uniform mat4 ProjectionMatrix; void main(void) { gl_Position = (ProjectionMatrix * ViewMatrix * ModelMatrix) * in_Position; } #endif #ifdef COMPILING_FS out float fragmentdepth; void main(void) { fragmentdepth = gl_FragCoord.z; } #endif    http://imageshack.us/photo/my-images/259/sinttulovbu.png/
  3. Hi! I try to render a mesh with GL_LINE_LOOP, but the result is deform:   This image show the vertex of the mesh and the indices:     The code to load and render:   void PhysicObject::Load(void) { glGenVertexArrays(1, &BufferIds[0]); ExitOnGLError("ERROR: No se puede generar el VAO"); glBindVertexArray(BufferIds[0]); ExitOnGLError("ERROR: No se puede bindear el VAO"); // Activamos dos vertex attribute locations glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); ExitOnGLError("ERROR: No se puede activar los vertex attributes"); // Creamos los VBO glGenBuffers(2, &BufferIds[1]); ExitOnGLError("ERROR: No se pueden generar los buffer objects"); // Bindeamos el VBO al VAO glBindBuffer(GL_ARRAY_BUFFER, BufferIds[1]); glBufferData(GL_ARRAY_BUFFER, vertices.size()*sizeof(VertexTextureNormal), &vertices[0], GL_STATIC_DRAW); ExitOnGLError("ERROR: No se puede bindear el VBO al VAO"); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(vertices[0]) ,0); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(vertices[0]) , (GLvoid*) sizeof(vertices[0].position)); ExitOnGLError("ERROR: Could not set VAO attributes"); // Creamos el IBO glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferIds[2]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), &indices.front(), GL_STATIC_DRAW); ExitOnGLError("ERROR: No se puede bindear el IBO al VAO"); glBindVertexArray(0); } void PhysicObject::Draw() { std::cout<<c<<std::endl; // Create the ModelMatrix glm::mat4 ModelMatrix = glm::translate( glm::mat4(1.0f), getPosition() ); colormat->Prepare3dDraw(ModelMatrix); glBindVertexArray(BufferIds[0]); ExitOnGLError("ERROR: No se puede bindear el VAO para dibujar"); glDrawElements(GL_LINE_LOOP, indices.size(), GL_UNSIGNED_INT, (GLvoid*)0); ExitOnGLError("ERROR: No se puede dibujar el meshpart"); glBindVertexArray(0); }    
  4. glutKeyboardFunc takes 5 frames to update state

    Ok, thanks for your answers
  5. glutKeyboardFunc takes 5 frames to update state

    I am thinking to change to GLFW. Is reading inputs faster?
  6. glutKeyboardFunc takes 5 frames to update state

    I am using Freeglut.
  7. Hi! I have the keyboard class that initialize the glutKeyboards functions. When I release a key, the program takes five frames to detect. I have another class that when I push the key 's', it add a vec3(1.0,1.0,1.0) to the variable position. The problem is that in each frame from that I press key 's' until it detects that I released it adds to the variable position the vector vec3(1.0,1.0,1.0). The update() function is called before the Draw () function in the render method KeyboardDevice.cpp     void KeyboardDevice::keySpecialUp(int key, int x, int y) { keySpecialStates[key] = false; timeReleased = clock(); keySpecialReleaseStates[key] = true; // Set the state of the current special key recently pressed }   bool KeyboardDevice::IsKeyPress(unsigned char key) { return keyStates[key]; } bool KeyboardDevice::IsKeyUp(unsigned char key) { double now = clock()/(double)CLOCKS_PER_SEC; double last = timeReleased /(double)CLOCKS_PER_SEC; if(now-last < 1 && keyReleaseStates[key] == true) { keyReleaseStates[key] = false; return true; } return false; } Actor.cpp: void Cube::Update(void) { if(kb->IsKeyPress('s')) position += glm::vec3(1.0 * getParent()->getEngine()->deltaTime); } Any idea to resolve this?
  8. GLSL initialize uniform variable with default value

    If I not initialize the color variable in GLSL but I give a value through "glUniform3f(ColorUniformLocation, color.x, color.y, color.z);" in the code, it does´n work.  Am I doing something wrong?
  9. Hi! I want to initialize my uniform variable in GLSL with a default value, but the program give me an error when I run it: Fragment code GLSL uniform vec3 Color = vec3(1.0,0.0,0.0); out vec3 out_Color; void main(void){ out_Color = Color; } If I the variable "Color" isn´t a uniform variable, the program works. I need that Color is uniform to change his value from a class. When I load the material I call this method:     void Color_mat::Load(void) { shader = getParent()->getEngine()->content.Load("Shaders/ColorShader.glsl"); Material::Load(); ColorUniformLocation = glGetUniformLocation(shader->ID, "Color"); ExitOnGLError("ERROR: Could not get the Color uniform location"); }       And When I draw, i call this method to start drawing the objects:   void Color_mat::Prepare3dDraw(glm::mat4 ModelMatrix) { Material::Prepare3dDraw(ModelMatrix); glUniform3f(ColorUniformLocation, color.x, color.y, color.z); ExitOnGLError("ERROR: Could not set the color"); }    
  10. I have a class with the Load texture that is responsible for loading an image and add the pixels of this to a variable char * pixels. Then, in the main class, Engine class, I have another method that adds this texture loaded to a std::list , so that once you have loaded all the textures generate. The problem is that all objects that use a texture, appear with the last texture I uploaded.   In the method Engine::CreateWorld() I add the objets for my 3D World:   void Engine::CreateWorld(void) {     GameScreen *gs1 = new GameScreen("hola");     PushGameScreen(gs1);       Camera *cam = new Camera();     gs1->AddComponent(cam);     cam->setPosition(glm::vec3(0.0, 2.0, 4.0));       Plane* pln = new Plane();     gs1->AddComponent(pln);     pln->setPosition(glm::vec3(0.0f,-1.0f,0.0f));       Cube* cb = new Cube();     gs1->AddComponent(cb);     cb->setPosition(glm::vec3(1.2f));     cb->setScale(glm::vec3(.2f)); }   Every time I add a Component to GameScreen, it call the Load method:   Plane.cpp   void Plane::Load(void) {     mesh = getParent()->getEngine()->content.Load<Mesh>("Models/plane.obj");     ApplyMaterials(); }   void Plane::ApplyMaterials() {     Texture_mat *texturemat = new Texture_mat;    // Instanciamos el material     getParent()->AddComponent(texturemat);    // Añadimos el material a los component para que se cargue     texturemat->setDiffuseTexture("Textures/plane.png");     materials.insert(std::pair<std::string, Material*>("Material.005",texturemat));   //Añadimos el material e indicamos odnde se tiene que aplicar }   Cube.cpp   void Cube::Load(void) {     mesh = getParent()->getEngine()->content.Load<Mesh>("Models/untitled.obj");     ApplyMaterials(); }   void Cube::ApplyMaterials() {     Color_mat *colormat = new Color_mat;    // Instanciamos el material     getParent()->AddComponent(colormat);    // Añadimos el material a los component para que se cargue     Texture_mat *texturemap = new Texture_mat;     getParent()->AddComponent(texturemap);    //Añadimos el material a los component     materials.insert(std::pair<std::string, Material*>("Material.002",colormat));   //Añadimos el material e indicamos odnde se tiene que aplicar     materials.insert(std::pair<std::string, Material*>("Material.003",texturemap)); }   Plane and Cube use Texture material:   void Texture_mat::Load(void) {     shader = getParent()->getEngine()->content.Load<Shader>("Shaders/SimpleShader.glsl");    //texture shader     Material::Load();     diffvalue = getParent()->getEngine()->LoadTexture(                                                                                                            //return texture value for to use in glUniform1i                                                                                getParent()->getEngine()->content.Load<Texture>("Textures/cube.bmp") //return texture loaded                                                                               );      DiffuseUniformLocation = shader->GetUniformLocation("texture0");   // get the texture uniform location form shader     ExitOnGLError("Error: Could not load texture"); }       void Texture_mat::Prepare3dDraw(glm::mat4 ModelMatrix) {     Material::Prepare3dDraw(ModelMatrix);  //     glUniform1i(DiffuseUniformLocation, diffvalue); }   Texture.cpp   #include "gl/glew.h" #include "../../include/Texture.hpp" #include "../../include/Util.hpp" #include "../../include/IL/il.h" Texture::Texture(){};     Texture::~Texture() {     };     void Texture::Load(std::string filename) {     name = filename;         ILuint imageID;     ilGenImages(1, &imageID);     ilBindImage(imageID);     ILboolean success = ilLoadImage(filename.c_str());     if(!success)     {         ExitOnError("ERROR: Imagen no cargada adecuadamente");     }     width = ilGetInteger(IL_IMAGE_WIDTH);     height = ilGetInteger(IL_IMAGE_HEIGHT);     ILint image_format = ilGetInteger(IL_IMAGE_FORMAT);     ILint image_type = ilGetInteger(IL_IMAGE_TYPE);     pixels = new BYTE[width*height*3];     ilCopyPixels(0,0,0,width,height, 1, IL_RGB, IL_UNSIGNED_BYTE, pixels);         ilBindImage(0);     ilDeleteImage(imageID); }     bool operator == (const Texture &tex1, const Texture &tex2) {     return (             tex1.name == tex2.name             ); };   Engine.cpp   GLint Engine::LoadTexture(Texture* n_tex) {     int c = 0;     for (std::list<Texture*>::iterator it = texturelist.begin(); it != texturelist.end(); it++)     {         if( (*it)->name == n_tex->name )         {             return (GLint) c;         }         c++;     }       texturelist.push_back(n_tex);       return (GLint) texturelist.size()-1; }   After the method CreateWorld(), call to GenerateTextures()   void Engine::GenerateTextures() {     // Gneramos las texturas para OpenGL     GLuint texturesID[texturelist.size()];     glGenTextures(texturelist.size(), texturesID);     int c = 0;     foreach(std::list<Texture*>, texturelist)     {         glBindTexture(GL_TEXTURE_2D, texturesID[c]);         glTexImage2D(GL_TEXTURE_2D,0,GL_RGB, (*it)->width, (*it)->height, 0, GL_RGB,GL_UNSIGNED_BYTE,(*it)->pixels );         ExitOnGLError("Error: Could not create the texture with glTexImage2D");         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);         //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);         //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);         glGenerateMipmap(GL_TEXTURE_2D);             glActiveTexture(GL_TEXTURE0+c);         glBindTexture(GL_TEXTURE_2D, texturesID[c]);         ExitOnGLError("Error: Could not bind the texture");         c++;     } }
  11. Problem load multiple meshes

    I discover my problem, the mesh variable from actor class...is static!!
  12. Problem load multiple meshes

    The problem isn´t the VAO or VBO. Before I load the cube, the plane have his data. After I load the cube, plane have the cube data. While the data cube load , the plane have the correctly data. I don´t know what its the problem. At least VBO and VAO are discarted.   Thanks for your attention.
  13. Problem load multiple meshes

    I add glBindBuffer(GL_ARRAY_BUFFER, BufferIds[1]) before calling DrawElements and it doesn´t work.
  14. Problem load multiple meshes

    the render function of meshparts:       void MeshPart::Draw() {     glBindVertexArray(BufferIds[0]);     ExitOnGLError("ERROR: No se puede bindear el VAO para dibujar");     glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, (GLvoid*)0);     ExitOnGLError("ERROR: No se puede dibujar el meshpart");     glBindVertexArray(0); }  
  15. Problem load multiple meshes

    Hi!   I have a method that load a mesh from .obj, and Initialice. It works when I load one mesh only...But If I load two o more different meshes, the first that I load take the values ( vertices, indices... ) from the second. I think that the problem is in VAO or VBO, but i can´t found the error.   There is the initialice method from Mesh Class:   void MeshPart::Initialize() { // Creamos el VAO glGenVertexArrays(1, &BufferIds[0]); ExitOnGLError("ERROR: No se puede generar el VAO"); glBindVertexArray(BufferIds[0]); ExitOnGLError("ERROR: No se puede bindear el VAO"); // Activamos dos vertex attribute locations glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); ExitOnGLError("ERROR: No se puede activar los vertex attributes"); // Creamos los VBO glGenBuffers(2, &BufferIds[1]); ExitOnGLError("ERROR: No se pueden generar los buffer objects"); // Bindeamos el VBO al VAO glBindBuffer(GL_ARRAY_BUFFER, BufferIds[1]); glBufferData(GL_ARRAY_BUFFER, vtn.size()*sizeof(VertexTextureNormal), &vtn[0], GL_STATIC_DRAW); ExitOnGLError("ERROR: No se puede bindear el VBO al VAO"); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(vtn[0]) ,0); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(vtn[0]) , (GLvoid*) sizeof(vtn[0].position)); ExitOnGLError("ERROR: Could not set VAO attributes"); // Creamos el IBO glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferIds[2]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), &indices.front(), GL_STATIC_DRAW); ExitOnGLError("ERROR: No se puede bindear el IBO al VAO"); glBindVertexArray(0); }     Does anyone know what happens to me?    
  • Advertisement