Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About ote

  • Rank
  1. ote

    curve editor

    It's for giving the user a way to indicate how some results must be filtered. So on a Cartesian coordinate system (excluding the negative values) where the curve is drawn, I need to be able to know the ordinate value for each abscissa. I hope it's clear. And I would like to be able to give the user a way to change the type of curve : Bézier, b-spline, Hermite, ... and to choose the number of control points.
  2. Hello, I'm looking for a C++ or C library for creating a window where users can manipulate a 2D curve. Something like that : http://moon245.3dtotal.com/admin/new...aph-editor.jpg Thanks
  3. I finally manage to render a model with his texture. I was not giving the complete path of the file, so Qt wasn't finding it. Now I'm trying to find a solution for not writing in the code the folder where images are, but consider this problem solved.
  4. Thanks for your reply but how do I do that ? I've try to add that line m_program.setUniformValue("texture", 0); in the initializeGL function, after the program is bind, but it doesn't change anything, the modele is still black. I also try to this : glActiveTexture(GL_TEXTURE0); in initializeGLbut still no improvement.
  5. Hello everyone, I'm having trouble drawing a model with his texture. With colors for each vertex it's ok, models are colored, but when I try to use a texture my model is render in black. I'm pretty sure the texture loading is working cause I've been printing the id and they are increasing as I load a new texture. Although when I use the Qt's function bindTexture(const QString &filename) I always have ids = 0. But with the classic glGenTextures, glBindTexture and glTexImage2D I get an id superior to 0 and it keeps increasing. I already managed to get textured objects but I'm new to Qt and I think something is missing, but I can't figure by myself what, so I anyone could help me I'll really appreciate. (sorry for my english) Here's the relevant code : //texture id is store as a GLuint in a structure infoMesh.texture = m_RenduModele->loadTexture(nomTex); How I load the texture : GLuint RenduModele::loadTexture(std::string &nom) { QString appliDir = QCoreApplication::applicationDirPath(); QString cheminComplet = appliDir + nom.c_str(); glEnable(GL_TEXTURE_2D); QImage texBuf; texBuf.load(cheminComplet); QImage tex = QGLWidget::convertToGLFormat(texBuf); GLuint id = 0; glGenTextures(1, &id); glBindTexture(GL_TEXTURE_2D, id); GLint internFormat; GLenum format; if(tex.hasAlphaChannel()) { internFormat = 4; format = GL_RGBA; } else { internFormat = 3; format = GL_RGB; } glTexImage2D(GL_TEXTURE_2D, 0, internFormat, tex.width(), tex.height(), 0, format, GL_UNSIGNED_BYTE, tex.bits()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glDisable(GL_TEXTURE_2D); return id; //doesn't work //return bindTexture(cheminComplet); } and the rendering : void RenduModele::renderModeleMesh(Modele *modele, unsigned int numMesh) { m_program.bind(); glm::mat4 matrixMP = m_camera->getProjectionMatrix() * m_camera->getModelViewMatrix() * modele->getMatrice(); QMatrix4x4 mvp; mat4toQmat4(matrixMP, mvp); for(unsigned int i = 0; i < modele->getNbMesh(); i++) { g_resources infos = modele->m_info_rendu; m_program.setUniformValue(infos.uniform.MVP, mvp); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, infos.texture); infos.vertex_buffer->bind(); m_program.enableAttributeArray(infos.in.position); m_program.enableAttributeArray(infos.in.texCoord); infos.vertex_buffer->release(); infos.element_buffer->bind(); glDrawElements(GL_TRIANGLES, infos.count, GL_UNSIGNED_INT, NULL); infos.element_buffer->release(); m_program.disableAttributeArray(infos.in.position); m_program.disableAttributeArray(infos.in.texCoord); } m_program.release(); } vertex shader : uniform mat4 MVP; uniform sampler2D texture; in vec4 position; in vec2 texCoord; out vec4 v_couleur; void main() { gl_Position = MVP * position; v_couleur = vec4(texture2D(texture, texCoord.st).rgb, 1.0); } fragment shader : in vec4 v_couleur; out vec4 color; void main() { color = colorFactor * v_couleur; }
  6. It works now without changing a single letter of my code. The problem was that I that I get the library from svn. With the latest stable version it works. I have been playing with my code for the day before looking into that...
  7. ote

    SDL Key press help- NEED BAD HELP

    Maybe it's not that but have you try to enable SDL_EnableKeyRepeat(int delay, int interval) ? http://pwet.fr/man/linux/fonctions_bibliotheques/sdl_enablekeyrepeat
  8. Hello, I'm trying to use assimp to load some models in my project. I have succesfully installed it, I am able to load some models but I have a problem to get access to two types of data : the texCoords and the indices of faces that form a mesh. When I try to retrieve those informations, my program crash due to segmentation fault. But for all the other things (vertex position, normals, colors, ...) I can get the information without any problem. I don't understand why this is happenning. I have read the doc, looked at the samples provided with the library and to others codes I found, I think I'm doing the same but doesn't work for me with these two cases. Here's the lines : bool Modele::loadGlresources(const aiScene *scene) { for(unsigned int i = 0; i < scene->mNumMeshes; i++) { aiMesh* mesh = scene->mMeshes; //temp array to store data info_vertex *attributes = (info_vertex *)malloc(mesh->mNumVertices * sizeof(info_vertex)); for(unsigned int j = 0; j < mesh->mNumVertices; j++) { //get the position, normal, .... without problems //here's how I do for position : attributes[j].position.x = mesh->mVertices[j].x; attributes[j].position.y = mesh->mVertices[j].y; attributes[j].position.z = mesh->mVertices[j].z; attributes[j].position.w = 1.0f; //but here's my problem : if(mesh->HasTextureCoords(0)) { attributes[j].texCoord.x = mesh->mTextureCoords[0][j].x; attributes[j].texCoord.y = mesh->mTextureCoords[0][j].y; } } //and the problem with the faces : //again temp array element *indices = (element *)malloc(mesh->mNumFaces * 3 * sizeof(element)); if(!mesh->HasFaces()) //add that to check where the error is, but still pass the test and crash..... return false; unsigned int count = 0; for(unsigned int j = 0; j < mesh->mNumFaces; j++) { indices[count].element = mesh->mFaces[j].mIndices[0]; indices[count + 1].element = mesh->mFaces[j].mIndices[1]; indices[count + 2].element = mesh->mFaces[j].mIndices[2]; count += 3; } } return true; } I've trying for hours now to make this work, but nothing works. So if someone has an idea of what I'm doing wrong, I'd be very grateful. Sorry for my english.
  9. I've changed the structure Trimesh_vertex to an array of float, instead of an array of glm::vec4, but it didn't change anything to my problem. I keep having a black screen. I really don't understand why it works with the array of vertices directly filled in the program, but not from a obj file. So if anyone has an idea where the mistake is... thanks in advance
  10. I'm back again because I've been trying for more than two hours now to display objects loading from obj files and I have again the same black screen. I've created a obj file with the same square I was giving the vertices in the array vertex_data but I can't make it work... I've check the data that are loaded from the obj file, they are the same as the ones in arrays. The only difference is that I'm using now a array of glm::vec4 instead of an array of float. Here's the code : typedef struct { glm::vec4 position; }Trimesh_vertex; the creation of the VBO std::vector<Trimesh_vertex> *attributes = new std::vector<Trimesh_vertex>(objData->vertexCount); for(int iVertex = 0; iVertex < this->objData->vertexCount; iVertex ++) { attributes->at(iVertex).position.x = objData->vertexList[iVertex]->e[0]; attributes->at(iVertex).position.y = objData->vertexList[iVertex]->e[1]; attributes->at(iVertex).position.z = objData->vertexList[iVertex]->e[2]; attributes->at(iVertex).position.w = 1.0f; } size_t tailleTableau = sizeof(Trimesh_vertex) * objData->vertexCount; this->m_infosRendu.vertex_buffer = myRenderer->makeBuffer(GL_ARRAY_BUFFER, attributes, tailleTableau); std::vector<glm::gtc::type_precision::u16vec3> *triBuf = new std::vector<glm::gtc::type_precision::u16vec3>(objData->faceCount); for(int iFace = 0; iFace < objData->faceCount; iFace++) { triBuf->at(iFace).x = objData->faceList[iFace]->vertex_index[0]; triBuf->at(iFace).y = objData->faceList[iFace]->vertex_index[1]; triBuf->at(iFace).z = objData->faceList[iFace]->vertex_index[2]; } tailleTableau = objData->faceCount * 3 * sizeof(GLushort); this->m_infosRendu.element_buffer = myRenderer->makeBuffer(GL_ELEMENT_ARRAY_BUFFER, triBuf, tailleTableau); display : void Renderer::drawObjet(Geometry *objet) { glUseProgram(m_infos_rendu.program); glm::vec3 couleur = glm::vec3(1.0, 0.0, 0.0); glVertexAttrib3fv(glGetAttribLocation(m_infos_rendu.program, "Color"), &couleur[0]); glBindBuffer(GL_ARRAY_BUFFER, objet->getVertexBuffer()); glEnableVertexAttribArray(m_infos_rendu.in.position); glVertexAttribPointer(m_infos_rendu.in.position, 4, GL_FLOAT, GL_FALSE, sizeof(Trimesh_vertex), (void*)offsetof(Trimesh_vertex, position)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, objet->getElementBuffer()); glDrawElements(GL_TRIANGLES, objet->getTriangleCount() * 3, GL_UNSIGNED_SHORT, (void*)0); glDisableVertexAttribArray(m_infos_rendu.in.position); SDL_GL_SwapBuffers(); }
  11. Thank you so much karwosts for you help, now it works ! Indeed I was only creating VBO of 8 bytes (I have a 64 bit computer, that's why it's 8 and not 4 I guess). I would have taken days to find this mistake, so really thanks a lot !!!!!
  12. Hello everyone, First, excuse me for the mistakes I make but I'm french and don't use english often enough. I've already used OpenGL 1.2 a few times, but now I want to learn the last version of OpenGL. So I've wrote a program which load OBJ file, create a VBO and display it with shaders. At first, I only consider vertices and gave a unique color for every vertex. But the screen keeps being black so I've simplify my program but I still don't have any results. I don't find where is my mistake so if you could help me that would be great. Here's an extract of the code where I think the error is. For now, there is no camera. Thanks in advance for the precious help you can give me. the creation of the VBO GLuint Renderer::makeBuffer(GLenum target, const void *buffer_data) { GLsizei buffer_size = sizeof(buffer_data); GLuint buffer; glGenBuffers(1, &buffer); glBindBuffer(target, buffer); glBufferData(target, buffer_size, buffer_data, GL_STATIC_DRAW); return buffer; } static const GLfloat vertex_data[] = { 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f }; this->m_infosRendu.vertex_buffer = myRenderer->makeBuffer(GL_ARRAY_BUFFER, vertex_data); static const GLushort element_data[] = {0, 1, 2, 2, 3, 0}; this->m_infosRendu.element_buffer = myRenderer->makeBuffer(GL_ELEMENT_ARRAY_BUFFER, element_data); display : void Renderer::drawObjet(Geometry *objet) { glUseProgram(m_infos_rendu.program); glm::vec3 couleur = glm::vec3(1.0, 0.0, 0.0); glVertexAttrib3fv(glGetAttribLocation(m_infos_rendu.program, "Color"), &couleur[0]); glBindBuffer(GL_ARRAY_BUFFER, objet->getVertexBuffer()); glEnableVertexAttribArray(m_infos_rendu.in.position); glVertexAttribPointer(m_infos_rendu.in.position, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, (void*)0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, objet->getElementBuffer()); glDrawElements(GL_TRIANGLES, objet->getVertexCount(), GL_UNSIGNED_SHORT, (void*)0); glDisableVertexAttribArray(m_infos_rendu.in.position); SDL_GL_SwapBuffers(); } the vertex shader attribute vec4 Position; attribute vec3 Color; varying vec3 v_Color; void main() { gl_Position = Position; v_Color = Color.xyz; } fragment shader varying vec3 v_Color; void main() { gl_FragColor = vec4(v_Color,1.0); }
  • 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!