Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

127 Neutral

About LeeBrowm

  • Rank
  1. Hello, I'm trying to get my Bullet physics debug working properly. And I am experiencing a problem while drawing wireframe - it gets drawn in a wrong place. It looks like the problem is purely of mathematical origin but I just don't know how to get around it. I've recorded a video showing the problem.   My guess is that it is related to the fact that I draw all the objects using VAO, but the wireframe drawLine function is umplemented using glBegin(GL_LINES)-glEnd.     Here is my draw function: void World::Draw() { glClearColor(0.1f,0.4f,0.9f,1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glm::mat4 VP =m_camera->GetViewProjection(); for(std::list<Object*>::iterator it = m_list.begin(), end =m_list.end(); it !=end; ++it) { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, *(*it)->TextureIDPtr()); m_shader.Update((*it)->TransformMatrixPtr(),&VP); for(int k=0;k<(*it)->ModelPtr()->numMeshes;k++) { glBindVertexArray((*it)->ModelPtr()->Meshes[k].m_VAOID); glDrawElements(GL_TRIANGLES, (*it)->ModelPtr()->Meshes[k].m_drawCount, GL_UNSIGNED_INT, 0); } glBindVertexArray(0); } m_dynamicsWorld->debugDrawWorld(); } m_dynamicsWorld->debugDrawWorld() in it's turn calls the following function void bulletDebugDrawer::drawLine(const btVector3& from,const btVector3& to,const btVector3& color) { glBegin(GL_LINES); glColor3f(color.getX(), color.getY(), color.getZ()); glVertex3d(from.getX(), from.getY(), from.getZ()); glColor3f(color.getX(), color.getY(), color.getZ()); glVertex3d(to.getX(), to.getY(), to.getZ()); glEnd(); } So I would greatly appreciate any help or hint on how to fix this thing  
  2. LeeBrowm

    OpenGL Rotating camera with mouse

    Never mind the text below, I found a solution to it - checking for multiple key presses in each update. Thanks to your help I managed to get it working correctly. Though I  have another question now. While I am rotating my camera with a mouse or move it with keys the picture on the screen really seems jittery, it doesn't feel smooth. I've tried recording it on a video (with glc) but the movement/ rotation on the video is smooth. Any idea what might cause this? Right now my loop looks like this void mainLoop(Display* disp, World * wrld){ m_previousTime = m_currentTime; m_currentTime =SDL_GetTicks(); m_dt=float(m_currentTime-m_previousTime); SDL_Event e; while(SDL_PollEvent(&e)){ if(e.type == SDL_QUIT){ disp->Close(); } if(e.type == SDL_KEYDOWN) { switch(e.key.keysym.sym) { case SDLK_ESCAPE: disp->Close(); case SDLK_w: *(wrld->CameraPtr()->PositionPtr())+=*(wrld->CameraPtr()->ForwardPtr())**(wrld->CameraPtr()->SpeedPtr())*m_dt; break; case SDLK_s: *(wrld->CameraPtr()->PositionPtr())-=*(wrld->CameraPtr()->ForwardPtr())**(wrld->CameraPtr()->SpeedPtr())*m_dt; break; case SDLK_a: *(wrld->CameraPtr()->PositionPtr())-=*(wrld->CameraPtr()->RightPtr())**(wrld->CameraPtr()->SpeedPtr())*m_dt; break; case SDLK_d: *(wrld->CameraPtr()->PositionPtr())+=*(wrld->CameraPtr()->RightPtr())**(wrld->CameraPtr()->SpeedPtr())*m_dt; break; } } if(e.type==SDL_MOUSEMOTION){ wrld->CameraPtr()->Rotate(-e.motion.xrel,-e.motion.yrel); } } wrld->Draw(); disp->Update(); }
  3. LeeBrowm

    OpenGL Rotating camera with mouse

    Thank you, I will try that.
  4. LeeBrowm

    OpenGL Rotating camera with mouse

    It doesn't actually do anything unless I move the mouse since it's called only if(e.type==SDL_MOUSEMOTION)
  5. Hello, I've decided implement camera rotation based on mouse input, but somewhere during the process it went wrong. Basically I tried following this tutorial: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-6-keyboard-and-mouse/ Instead of working properly the programm actually rotates camera but in a very peculiar manner: no matter in what direction I move my mouse the image always moves in the same direction and then flips and so on. After doing the tutorial I ended up with something like this; void Camera::Rotate(Sint32 dx, Sint32 dy){ m_horizontalAngle+= mouseSpeed*float(width/2-dx); m_verticalAngle+=mouseSpeed*float(height/2-dy); m_forward.x = cosf(m_verticalAngle)*sinf(m_horizontalAngle); m_forward.y = sinf(m_verticalAngle); m_forward.z = cosf(m_verticalAngle)*cosf(m_horizontalAngle); m_right = glm::vec3(sinf(m_horizontalAngle-3.14f/2.0f),0,cosf(m_horizontalAngle-3.14f/2.0f)); m_up=glm::cross(m_right,m_forward); } The function itself is called from the main loop void mainLoop(Display* disp, World * wrld){ SDL_Event e; while(SDL_PollEvent(&e)){ if(e.type==SDL_MOUSEMOTION){ std::cout<<"("<<e.motion.xrel<<","<<e.motion.yrel<<")"<<std::endl; wrld->CameraPtr()->Rotate(e.motion.xrel,e.motion.yrel); } } wrld->Draw(); } wrld->Draw() is made this way void World::Draw(){ glClearColor(0.2f,0.3f,0.1f,1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glm::mat4 VP =m_camera->GetViewProjection(); for(unsigned int i =0; i<m_list.size();i++){ m_list[i]->TexturePtr()->Bind(0); m_shader.Update(*(m_list[i]->PositionPtr()),*(m_list[i]->RotationPtr()),*(m_list[i]->ScalePtr()),VP); m_list[i]->MeshPtr()->Draw(); } } m_camera->GetViewProjection() is the member of Camera class inline glm::mat4 GetViewProjection() const{ return m_perspective* glm::lookAt(m_position,m_position+m_forward,m_up); } m_shader.Update(..) is void Shader::Update(glm::vec3& position,glm::vec3& rotation, glm::vec3& scale, glm::mat4 viewProjection) { glm::mat4 posMatrix = glm::translate(position); glm::mat4 rotXMatrix = glm::rotate(rotation.x,glm::vec3(1,0,0)); glm::mat4 rotYMatrix = glm::rotate(rotation.y,glm::vec3(0,1,0)); glm::mat4 rotZMatrix = glm::rotate(rotation.z,glm::vec3(0,0,1)); glm::mat4 scaleMatrix = glm::scale(scale); glm::mat4 wmat = viewProjection* posMatrix * rotZMatrix * rotYMatrix * rotXMatrix * scaleMatrix; glUniformMatrix4fv(m_uniforms[TRANSFORM_U], 1, GL_FALSE,&wmat[0][0]); } Without the rotation part all the object display correctly and I can move in space using WASD keys.   I would greatly appreciate any help:)
  6. Thank you, HappyCoder, it fixed it, that was so stupid of me...
  7. Hello everyone, My question may seem pretty newbish for you but I just can't figure it out and it's really bothering me. So... Having little knowledge about OpenGL I wanted to find myself a tutorial and stumbled upon video series on youtube that was published about half a year ago (so it's fairly recent) and decided to just follow it. I am quite sure that the mentioned tutorial does not have the error I experience (it is shown that it works). I am using Code::Blocks and the system is Arch Linux x64, the computer has two video cards: 1) integrated Intel graphics card 2) nvidia Geforce GT 620M. There is this class Mesh in the tutorial   mesh.cpp #include "mesh.h" #include <vector> Mesh::Mesh(Vertex* vertices, unsigned int numVertices){ m_drawCount = numVertices; glGenVertexArrays(1,& m_vertexArrayObject); glBindVertexArray(m_vertexArrayObject); std::vector<glm::vec3> positions; std::vector<glm::vec2> texCoords; positions.reserve(numVertices); texCoords.reserve(numVertices); for(unsigned int i=0; i<numVertices;i++){ positions.push_back(*vertices[i].GetPos()); texCoords.push_back(*vertices[i].GetTexCoord()); } glGenBuffers(NUM_BUFFERS, m_vertexArrayBuffers); glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[POSITION_VB]); glBufferData(GL_ARRAY_BUFFER,numVertices*sizeof(positions[0]), &positions[0],GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[TEXCOORD_VB]); glBufferData(GL_ARRAY_BUFFER,numVertices*sizeof(texCoords[0]), &texCoords[0],GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); glBindVertexArray(0); } Mesh::~Mesh(){ glDeleteVertexArrays(1,& m_vertexArrayObject); } void Mesh::Draw(){ glBindVertexArray(m_vertexArrayObject); glDrawArrays(GL_TRIANGLES, 0, m_drawCount); glBindVertexArray(0); } And I use it in my main.cpp #include <iostream> #include <GL/glew.h> #include "display.h" #include "shader.h" #include "mesh.h" #include "texture.h" #include "glm/glm.hpp" int main(){ Display display(800, 600, "OpenGL"); Vertex vertices[] = { Vertex(glm::vec3(-0.5, -0.5, 0), glm::vec2(0.0,0.0)), Vertex(glm::vec3(0, 0.5, 0), glm::vec2(0.5,1.0)), Vertex(glm::vec3(0.5, -0.5, 0), glm::vec2(1.0,0.0)),}; Mesh mesh(vertices, sizeof(vertices)/sizeof(vertices[0])); Shader shader("./res/basicShader"); Texture texture("./res/bricks.jpg"); while(!display.IsClosed()){ display.Clear(0.0f,0.15f,0.3f,1.0f); shader.Bind(); texture.Bind(0); mesh.Draw(); display.Update(); } return 0; } But when I run my app in the debug mode it shows me this   The line 42 is glDrawArrays(GL_TRIANGLES, 0, m_drawCount); from mesh.cpp   It is really confusing because ,as I've said, I just typed the whole code as it was done in the tutorial. Unfortunately I can not download the source code because it is not available for this part.   Can it be somehow connected with my hardware specifications?   I apologize beforehand if the answer is too simple and/or obvious. 
  • 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!