meiryousa

Members
  • Content count

    6
  • Joined

  • Last visited

Community Reputation

117 Neutral

About meiryousa

  • Rank
    Newbie
  1. I'm messing around trying to make a water effect. The thing is, it's messing up and I'm not sure how to fix it. I've tried to cull the face wtih glEnable(GL_CULL_FACE) and various glCallFunc, but it didn't work. I have depth testing enabled. Yeah, I'm fairly new to opengl so I'm not sure what is causing this issue:   EDIT: I managed to figure out that it has to do with the blending     glEnable(GL_BLEND);     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);   trying to figure out how to fix it still.
  2. Well, I have a third-person camera working. It's "ok" I guess. It just doesn't quite work the way I want it to.  It rotates around the target perfectly. Exactly how I want it to. It zooms in and out on the target perfectly too. What I am having troubles with is having it rotate over the target. The reason this is difficult is because it depends on the direction I am facing. These are my functions so far:   void ViewManager::rotateOver(float amt){     y_theta += amt;     position.y = target.y + radius * cos(y_theta * M_PI / 180.0f);     v_matrix = glm::lookAt(position, target, glm::vec3(0.0f,1.0f,0.0f));     return; } void ViewManager::rotateAround(float amt){     x_theta += amt;     z_theta += amt;     position.x = target.x + radius * sin(x_theta * M_PI / 180.0f);     position.z = target.z + radius * cos(z_theta * M_PI / 180.0f);     v_matrix = glm::lookAt(position, target, glm::vec3(0.0f,1.0f,0.0f));     return; } void ViewManager::zoomIn(float amt){     radius += amt;     position.x = target.x + radius * sin(x_theta * M_PI / 180.0f);     position.y = target.y + radius * cos(y_theta * M_PI / 180.0f);     position.z = target.z + radius * cos(z_theta * M_PI / 180.0f);     v_matrix = glm::lookAt(position, target, glm::vec3(0.0f,1.0f,0.0f));     return; } I've tried a lot of different things. I've had it rotating over one axis, both axes, but never the correct axes. I don't think I need 3 angles... I just did that recently trying different ideas... there are angles created between the x-y axes and x-z axes. This is based on polar coordinates. I hope I gave enough information...
  3. I'm having problems understanding/getting the hang of some basic concepts. My program works ok so far except a two things. I'll try to explain what happens:   If I start the object at 0,0,0 i can't see the object. As I move the camera in the -z direction the object becomes visible and things seem to work fine. This makes sense to me a bit because my perspective has the clip plane at 0.1 to 100.0. The object starts out at 0 which is behind 0.1.   It seems no matter where I draw my object it's 0.1 from being clipped. I've tried doing the translations via the model matrix and the view matrix and the results are the same. My other problem is that if I move forward once then move back once it crashes with this error:      
  4. Ok, I am forcing a OpenGL 3.2 context. Using GLSL 330. I've had models with no textures working in my custom format. But I've done a major reworking of everything to make it cleaner and smoother.  The model that was working was just the traditional colored triangle I wrote in my file format by hand using a hex editor. At this point, I decided to write my exporter to export .3ds files to my format. It's completed. I've tested it thoroughly. I wrote a set of importer functions and tested them out and it all gets loaded in the data structures in the same form that I was originally using. Anyways, I took your suggestion. There are no matrix transformations occuring in my program at the moment.  The view, projection and everything hasn't been touched. I'm using a grey colored cube. with dimenions in the range of 1,1,1 to -1,-1,-1. I clear the background to black, and draw this grey cube. Nothing shows up. Is my problem that I'm looking from inside the cube out? Interestingly enough if I turn the background color to something like blue, go into wireframe mode then I can see the polygons of a square. This is what I'd expect. a grey square taking up the entire view... but yeah
  5. I am trying to draw a model that I loaded into memory using a custom format. I think it might have to do with the way I'm handling textures. I'm not getting any GLSL errors. These are the two functions I use that deal with loading and drawing the model /************************************************** Model object has the following functions to load and to draw: **************************************************/   bool Model::loadModel(const std::string& fname, GLuint pgm_id){           ModelTexture* texture = nullptr;           unsigned int vbo_size = 0;         unsigned int tbo_size = 0;           program_id = pgm_id;           if(!BPFImporter::importBPFModel(fname,data)){                 return false;         }           vbos.resize(data.file_header.object_count);         glGenBuffers(data.file_header.object_count, &vbos.front());           for(unsigned int obj = 0; obj < data.file_header.object_count; obj++){                 vbo_size = data.objects.at(obj).object_header.vertex_count*sizeof(ModelVertex);                 glBindBuffer(GL_ARRAY_BUFFER, vbos.at(obj));                 if(data.objects.at(obj).object_header.animated_flag != 0){                         glBufferData(GL_ARRAY_BUFFER,vbo_size,&data.objects.at(obj).vertices.front(),GL_STREAM_DRAW);                 }else{                         glBufferData(GL_ARRAY_BUFFER,vbo_size,&data.objects.at(obj).vertices.front(),GL_STATIC_DRAW);                 }         }           tbos.resize(data.file_header.material_count);         glGenTextures(data.file_header.material_count, &tbos.front());           //store appropriate textures... (only does first texture of every material...)         for(unsigned int mat = 0; mat < data.file_header.material_count; mat++){                 texture = &data.materials.at(mat).textures.front();                   glBindTexture(GL_TEXTURE_2D, tbos.at(mat));                 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,                                          texture->texture_header.width,                                          texture->texture_header.height,                                          0,                                          GL_RGBA,                                          GL_UNSIGNED_BYTE,                                          &texture->texels.front());                   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);         }           return true; }   void Model::drawModel(){           ModelObjectHeader *object_header;         std::vector<ModelFace> *faces;           glUseProgram(program_id);           for(unsigned int obj = 0; obj < data.file_header.object_count; obj++){                   object_header = &data.objects.at(obj).object_header;                 faces = &data.objects.at(obj).faces;                   glBindBuffer(GL_ARRAY_BUFFER,vbos.at(obj));                 glBindTexture(GL_TEXTURE_2D, tbos.front());                                 //setup vertex position pointer                 glEnableVertexAttribArray(0);                 glVertexAttribPointer(0,4,GL_FLOAT,GL_FALSE,sizeof(ModelVertex),(void*)COORD_OFFSET);                   //setup vertex normal pointer                 glEnableVertexAttribArray(1);                 glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,sizeof(ModelVertex),(void*)NORMAL_OFFSET);                   //setup vertex texture pointer                 glEnableVertexAttribArray(2);                 glVertexAttribPointer(2,2,GL_FLOAT,GL_FALSE,sizeof(ModelVertex),(void*)TEXTURE_OFFSET);                     glDrawElements(GL_TRIANGLES, object_header->face_count,GL_UNSIGNED_BYTE, (void*)&faces->front());                 glDisableVertexAttribArray(0);                 glDisableVertexAttribArray(1);                 glDisableVertexAttribArray(2);         }         return; }   I've tested data in the structures that hold the model data. This is what I got printed out:   Object[0] ---------           Object Header         -------------           vertex_count:24         face_count:12         material_index:0         coord_flag:1         color_flag:0         normal_flag:1         texture_flag:1         animated_flag:0                   Vertex Positions                 ----------------                   1,1,-1,1                 1,-1,-1,1                 -1,-1,-1,1                 -1,1,-1,1                 1,0.999999,1,1                 -1,1,1,1                 -1,-1,1,1                 0.999999,-1,1,1                 1,1,-1,1                 1,0.999999,1,1                 0.999999,-1,1,1                 1,-1,-1,1                 1,-1,-1,1                 0.999999,-1,1,1                 -1,-1,1,1                 -1,-1,-1,1                 -1,-1,-1,1                 -1,-1,1,1                 -1,1,1,1                 -1,1,-1,1                 1,0.999999,1,1                 1,1,-1,1                 -1,1,-1,1                 -1,1,1,1                                 Vertex Normals                 --------------                   0.666667,0.333333,-0.666667                 0.408248,-0.816497,-0.408248                 -0.666667,-0.333333,-0.666667                 -0.408248,0.816497,-0.408248                 0.333333,0.666666,0.666667                 -0.816496,0.408249,0.408248                 -0.333333,-0.666667,0.666667                 0.816496,-0.408249,0.408248                 0.666667,0.333333,-0.666667                 0.333333,0.666666,0.666667                 0.816496,-0.408249,0.408248                 0.408248,-0.816497,-0.408248                 0.408248,-0.816497,-0.408248                 0.816496,-0.408249,0.408248                 -0.333333,-0.666667,0.666667                 -0.666667,-0.333333,-0.666667                 -0.666667,-0.333333,-0.666667                 -0.333333,-0.666667,0.666667                 -0.816496,0.408249,0.408248                 -0.408248,0.816497,-0.408248                 0.333333,0.666666,0.666667                 0.666667,0.333333,-0.666667                 -0.408248,0.816497,-0.408248                 -0.816496,0.408249,0.408248                                 Vertex TCoords                 --------------                   0.9999,0.9999                 0.0001,0.0001                 0.0001,0.0001                 0.9999,0.9999                 0.9999,0.9999                 0.0001,0.0001                 0.0001,0.0001                 0.999899,0.999899                 0.9999,0.9999                 0.9999,0.9999                 0.0001,0.0001                 0.0001,0.0001                 0.9999,0.9999                 0.9999,0.9999                 0.0001,0.0001                 0.0001,0.0001                 0.0001,0.0001                 0.0001,0.0001                 0.9999,0.9999                 0.9999,0.9999                 0.9999,0.9999                 0.9999,0.9999                 0.0001,0.0001                 0.0001,0.0001   /********************************************************** data.objects.at(obj).faces contains the following: **********************************************************/                 Vertex Indices                 --------------                   0,1,2                 0,2,3                 4,5,6                 4,6,7                 8,9,10                 8,10,11                 12,13,14                 12,14,15                 16,17,18                 16,18,19                 20,21,22                 20,22,23   The model is just a simple crate with one texture. Something easy to test values on. I've printed out and checked the texel values too and they are correct. I matched the rgba values to what I get in gimp. They all match.
  6. The problem I have kinda has to do with glDrawArrays. Basically, if I have a number of vertices that isn't divisible by 3 it won't work. It works based on triangles. I need it to work generically. If I have 4 verts I need it to draw a quad if I have 3 it needs to draw a triangle. This is my drawModel function right now:     void Model::drawModel(glm::mat4& v2s_matrix, glm::mat4& w2v_matrix){     glm::mat4 mvp = v2s_matrix * w2v_matrix * m2w_matrix;     GLuint mvploc = glGetUniformLocation(data.file_header.shader_program, "mvp");     glUniformMatrix4fv(mvploc, 1, GL_FALSE, &mvp[0][0]);     glUseProgram(data.file_header.shader_program);     for(int x = 0; x < data.file_header.object_count; x++){         glBindBuffer(GL_ARRAY_BUFFER,vbo_list.at(x));         if(data.model_object.at(x).object_header.coord_flag != 0){             glEnableVertexAttribArray(0);             glVertexAttribPointer(0,4,GL_FLOAT,GL_FALSE,sizeof(ModelVertex),(void*)COORD_OFFSET);         }         if(data.model_object.at(x).object_header.color_flag != 0){             glEnableVertexAttribArray(1);             glVertexAttribPointer(1,4,GL_FLOAT,GL_FALSE,sizeof(ModelVertex),(void*)COLOR_OFFSET);         }         glDrawArrays(GL_TRIANGLES,0,data.model_object.at(x).object_header.vertex_count);         glDisableVertexAttribArray(0);         glDisableVertexAttribArray(1);     }     return; }   I have two basic models. A square and a triangle I am testing. 4 verts and 3 verts. This works for the triangle. For the square, it draws a triangle not including the last point. Any suggestions would be greatly appreciated. Thanks.