Jump to content
  • Advertisement

sniper227

Member
  • Content Count

    26
  • Joined

  • Last visited

Community Reputation

153 Neutral

About sniper227

  • Rank
    Member
  1. sniper227

    tutorial for opengl 1.4?

    http://glew.sourceforge.net/   if you download glew and run the .exe in the bin folder it'll generate a text file and tell you what version of OpenGL you can run, I personally try and make my videos noob friendly as possible, I explain every single line so you know what you're doing instead of just typing in lines.
  2. sniper227

    tutorial for opengl 1.4?

    1.4 is very very old and out dated like from the 2000s the latest version is 4.5 I believe but the video tutorials I linked you to are from 3.3 
  3. sniper227

    tutorial for opengl 1.4?

    that's a video on how to create a win32 opengl window.   Here's some good tutorials :   http://nehe.gamedev.net/tutorial/lessons_01__05/22004/
  4. sniper227

    Dynamically create meshes in opengl

    Yes, you can access individual vector elements as an array. However, if you plan to iterate through the vector, iterators are best:   for(auto it = com.begin();it != com.end();++it) { it->vertices...; // Do something with the vertices.... } That is functionally equivalent to this: for(int i = 0;i < com.size();++i) { com[i].vertices...; // Do something with the vertices.... } There are benefits to using the iterator version, but I am less than clear on those benefits.   Hey so I got it working but I get a weird but everytime I add more than one mesh it messes up the faces and changes the index values. For example the first object would have the index value of 0 because I use color based selection to check and it returns 0 and when I add a second object that should be index 1 I click it and I get 0 for the second and 1 for the first? any ideas   Here's my code to load the model and render it. Note that if i go back to my regular CentralObjectSystem com[100]; pointer instead of the vector it comes out perfect...? //Load int COS::LoadTriDAE(string filename, int objects) { string info_t; ifstream dae; string line; int dummy = 0; int counter = 0; string temp = " ", second = " ", normal = " "; // CentralObjectManifest temp_obj; // dae.open(filename, ios::in); while (!dae.eof()) { getline(dae, line); if (line.find(" <mesh>") != line.npos) { for (int i = 0; i < 2; i++) { getline(dae, line); } if (line.find(" <float_array id") != line.npos) { //cout<<"hey"; while (line != "</float_array>") { getline(dae, line); sscanf_s(line.c_str(), "%f %f %f", &temp_obj.Object.Triangle.xyz[0], &temp_obj.Object.Triangle.xyz[1], &temp_obj.Object.Triangle.xyz[2]); temp_obj.Object.Triangle.vertices.push_back(temp_obj.Object.Triangle.xyz[0]); temp_obj.Object.Triangle.vertices.push_back(temp_obj.Object.Triangle.xyz[1]); temp_obj.Object.Triangle.vertices.push_back(temp_obj.Object.Triangle.xyz[2]); } } } if (line.find(" <triangles count=") != line.npos) { int start = line.find("<p>"); int end = line.find("</p>"); start = start + 4; end = end + 1; int length = end - start; string info = line.substr(start, length); stringstream ss(info); int x; while (ss >> x) { temp_obj.Object.Triangle.faces.push_back(x); } } if (line.find(" <float_array id") != line.npos) { cout << dummy << endl; //cout << "uv"; if (dummy == 0) { while (line != "</float_array>") { getline(dae, line); sscanf_s(line.c_str(), "%f %f %f", &temp_obj.Object.Triangle.norms.normals[0], &temp_obj.Object.Triangle.norms.normals[1], &temp_obj.Object.Triangle.norms.normals[2]); temp_obj.Object.Triangle.norms.normal.push_back(temp_obj.Object.Triangle.norms.normals[0]); temp_obj.Object.Triangle.norms.normal.push_back(temp_obj.Object.Triangle.norms.normals[1]); temp_obj.Object.Triangle.norms.normal.push_back(temp_obj.Object.Triangle.norms.normals[2]); } } if (dummy == 1) { while (line != "</float_array>") { getline(dae, line); sscanf_s(line.c_str(), "%f %f", &temp_obj.Object.Triangle.Texture.uv[0], &temp_obj.Object.Triangle.Texture.uv[1]); temp_obj.Object.Triangle.Texture.tex.push_back(temp_obj.Object.Triangle.Texture.uv[0]); temp_obj.Object.Triangle.Texture.tex.push_back(temp_obj.Object.Triangle.Texture.uv[1]); } } dummy += 1; } if (line.find(" <image id=") != line.npos) { int start = line.find("<init_from>"); int end = line.find("</init_from>"); start += 18; int len = end - start; info_t= line.substr(start, len); info_t = ReplaceAll(info_t, "\\", "/"); temp_obj.Object.Triangle.Texture.texpath = info_t.c_str(); // temp_obj.Object.Triangle.Texture.TexID = LoadTGATexture((char *)temp_obj.Object.Triangle.Texture.texpath.c_str()); temp_obj.Object.Triangle.Texture.is_textured= true; } } dae.close(); temp_obj.Object.Triangle.draw = true; temp_obj.type = MESH; temp_obj.Object.frames = 2; //cout << "tex path"<<temp_obj.Object.Triangle.Texture.texpath; GenerateColors(temp_obj.Object.Triangle.rgb[0], temp_obj.Object.Triangle.rgb[1], temp_obj.Object.Triangle.rgb[2]); //temp_obj.eb.rgb[3] = 0.2f; glGenBuffers(1, &temp_obj.Object.Triangle.vbo); glBindBuffer(GL_ARRAY_BUFFER, temp_obj.Object.Triangle.vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*temp_obj.Object.Triangle.vertices.size(), &temp_obj.Object.Triangle.vertices[0], GL_STATIC_DRAW); glGenBuffers(1, &temp_obj.Object.Triangle.vio); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, temp_obj.Object.Triangle.vio); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint)*temp_obj.Object.Triangle.faces.size(), &temp_obj.Object.Triangle.faces[0], GL_STATIC_DRAW); glEnable(GL_TEXTURE_2D); com.push_back(temp_obj); obj_tot = obj_tot + 1; return 0; } void CentralObjectSystem::RenderFullScene(int obj) { glPushMatrix(); //bind VBOS glVertexPointer(3, GL_FLOAT, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, out_vertex[obj].vbo); glEnableClientState(GL_VERTEX_ARRAY); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, out_vertex[obj].vio); //Texture check only applies if object has texture if (out_vertex[obj].has_texture) { glTexCoordPointer(2, GL_FLOAT, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, out_vertex[obj].vto); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glColor3d(0.5, 0.5, 1); glBindTexture(GL_TEXTURE_2D, out_vertex[obj].TexID[0]); } if (!out_vertex[obj].has_texture) //insert color creation code here glTranslatef(2*obj_tot, 2, 0); //Code to change object red if selected if (out_vertex[obj].sel_col == false) glColor3ub(out_vertex[obj].rgb[0], out_vertex[obj].rgb[1], out_vertex[obj].rgb[2]); else if (out_vertex[obj].sel_col == true) glColor3ub(255, 0, 0); //Actual draw call glDrawElements(GL_TRIANGLES, out_vertex[obj].indices.size(), GL_UNSIGNED_INT, 0); glDisableClientState(GL_VERTEX_ARRAY); if (out_vertex[obj].has_texture) glDisableClientState(GL_TEXTURE_COORD_ARRAY); glPopMatrix(); } //render
  5. sniper227

    Dynamically create meshes in opengl

    You're pushing an empty object into the vector and then trying to work with it. The correct code would be something like this: vector<CentralObjectManifest> com; void createObject() { CentralObjectManifest temp; temp.vertices.push_back(...); //.. rest of creation code here.. com.push_back(temp); obj_tot+=1; } I'm hoping the global "com" variable is just to make the code snippet smaller and you're actually wrapping it in a class. It would be nice to see all of the code relating to this issue.   I'll try that out first and see if I still get issues. If i understand this correctly would I access the vertices vector like this: com[0].vertices ?
  6. Hey so I created the code to create multiple meshes in opengl but it's not very dynamic.   I was wondering if there was a way to dynamically create pointer as of now this is how it looks. CentralObjectManifest com[100]; //CentralObjectManifest is the structure int obj_tot = 0; com[obj_tot].vertices.push_back(...); //.. rest of creation code here.. obj_tot +=1; now the above works but it's not dynamic because if we get above 100 objects the program would crash. How would I make it dynamic I tried using  vector<CentralObjectManifest> com; void createObject() { com.push_back(CentralObjectManifest()); // insertion code obj_tot+=1; } but It keeps crashing saying the vector is out of range. how would I make this dynamic. Once again Thanks!
  7. Hey there, so for a while I've been trying to switch to glDrawArrays and I've been using glDrawElements. I tried to use the indices to create a new list with the new vertices in it so I don't need to use indices but it's not coming drawing properly :/   Any Ideas? Sorry for the messy code its my experiment project. extern struct TEST { vector<GLfloat>vertices; vector<GLfloat>texcoords; vector<GLuint>indices; }; extern vector<TEST> out_vertex; int LOBJ_Loader::LoadTriOBJ(char *filename,int num) { ifstream fobj; string line; fobj.open(filename,ios::in); while(!fobj.eof()) { getline(fobj,line); if(line[0] == 'v') { sscanf_s(line.c_str(),"v %f %f %f",&obj[num].x,&obj[num].y,&obj[num].z); obj[num].vertices.push_back(obj[num].x); obj[num].vertices.push_back(obj[num].y); obj[num].vertices.push_back(obj[num].z); } if (line[0] == 'f ') { sscanf_s(line.c_str(), "f %d %d %d ", &obj[num].f1, &obj[num].f2, &obj[num].f3); obj[num].f1 = obj[num].f1 - 1; obj[num].f2 = obj[num].f2 - 1; obj[num].f3 = obj[num].f3 - 1; obj[num].faces.push_back(obj[num].f1); obj[num].faces.push_back(obj[num].f2); obj[num].faces.push_back(obj[num].f3); } } fobj.close(); //convert old vertex to new vertex for (int i = 0; i < obj[obj_num].faces.size(); i++) { out_vertex[0].vertices.push_back(obj[obj_num].vertices[obj[obj_num].faces[i]]); //the line above runs through the indices using I and adds the vertex[indices] to the out_vertex vector } obj_num = obj_num+1; return 0; } // rendering triangle bool LRender::Render() { current = tim->GetTime(); if (GetKey[SPACEBAR]) { tim->ResetTimer(); } if(GetKey[LEFT_ARROW]) { Camera.RAngleY(sensitivity); //Display(); } if(GetKey[VK_RIGHT]) { Camera.RAngleY(-sensitivity); //Display(); } if(GetKey[W]) { Camera.MoveForwards( -fSpeed ) ; //Display(); } if(GetKey[S]) { Camera.MoveForwards( bSpeed) ; //Display(); } if(GetKey[UP_ARROW]) { Camera.RAngleX(sensitivity); //Display(); } if(GetKey[DOWN_ARROW]) { Camera.RAngleX(-sensitivity); //Display(); } if(GetKey[A]) { Camera.StrafeRight(-StrafeSpeed); //Display(); } if(GetKey[D]) { Camera.StrafeRight(StrafeSpeed); //Display(); } if(GetKey[E]) { Camera.Move(F3dVector(0.0,-upSpeed,0.0)); //Display(); } if(GetKey[Q]) { Camera.Move(F3dVector(0.0,downSpeed,0.0)); //Display(); } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glClearColor(0.1f, 0.4f, 0.7f, 0.3f); Camera.Render(); for (int i = 0; i < 1; i++) { glPushMatrix(); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, &out_vertex[objt].vertices[0]); glColor3d(1, 1, 1); glTranslatef(com[i].Object.Triangle.translate[0], com[i].Object.Triangle.translate[1], com[i].Object.Triangle.translate[2]); glScalef(com[i].Object.Triangle.scale[0] + 1, com[i].Object.Triangle.scale[1] + 1, com[i].Object.Triangle.scale[2] + 1); glRotatef(com[i].Object.Triangle.rotation[0], com[i].Object.Triangle.rotation[1], com[i].Object.Triangle.rotation[2], com[i].Object.Triangle.rotation[3]); glDrawArrays(GL_TRIANGLES, 0, out_vertex[objt].vertices.size()); glDisableClientState(GL_VERTEX_ARRAY); glPopMatrix(); } return true; };
  8. sniper227

    OpenGL Transparency with glColor4b?

    Thanks a lot guys ! It works :D
  9. Hey guys, so I got transparency working using glColor4f and a couple of other functions but glColor4f is used to set how transparent an object is and i'm curious on how I could use glColor4b instead because I need it since i generate different colors from 0-255 and I cant figure out how to get transparency working with it like in glColor4f. Thanks
  10. sniper227

    Animation timer?

    helped a lot I had an issue with my camera changing speeds depedning on how fast your pc is but now its constant thanks to your comment!   Appreciate it!
  11. sniper227

    Animation timer?

    i'm getting a memory error on this line :     double Diff = (newTime.QuadPart - oldTime.QuadPart);
  12. sniper227

    Animation timer?

    Hey guys,   So I ran into a very obvious problem, I've been trying to run an animation but it runs too quick. I hate to fetch for code but I have no idea how to write a timer function.   basically all i need to do is create a timer function and after every 800 milliseconds or so it will update the frame to the next animation. I already have the animation data and know how to update it I just need the timer part.   Here's sort of what it would look like if(timer%800 == 0) { Play->Animation(); }
  13. sniper227

    Weird particle lag?

    thank you, I tried that solution and couldn't figure out why it didn't reduce lag but then I read your post and looked at my code and forgot to take out the for loop for the render function 
  14. sniper227

    Weird particle lag?

    Still get lag not as significant, I just had a thought I havent confirmed that the fps is dropping my camera just slows down a lot after I render it and since my camera uses glTranslatef() could it just be the camera that slows down and not the fps?
  15. sniper227

    Weird particle lag?

    Already tried that before posting here, tied all the vertices to one vbo and tried to translate it seperately but I probably only got 1-3 fps boost :/
  • 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!