Jump to content
  • Advertisement

Dominic Hughes

Member
  • Content Count

    17
  • Joined

  • Last visited

Community Reputation

112 Neutral

About Dominic Hughes

  • Rank
    Member

Personal Information

  1. frob: I'm trying to compare an entire string "with file contents inside" with a integer value "index value from file scanning each line and getting the pre-set index to use as a the line index used for replacing lines in the text file contents with new content like different positions,etc":   Text file contents: 1 1 XPOS 320 YPOS 294 D 0.50 2 1 XPOS 620 YPOS 494 D 0.18 3 1 XPOS 420 YPOS 512 D 0.18 4 1 XPOS 520 YPOS 512 D 0.18 5 1 XPOS 620 YPOS 512 D 0.40 6 1 XPOS 720 YPOS 512 D 0.18 7 1 XPOS 320 YPOS 530 D 0.50 8 1 XPOS 420 YPOS 530 D 0.18 9 1 XPOS 520 YPOS 530 D 0.20 10 1 XPOS 620 YPOS 530 D 0.18 11 1 XPOS 720 YPOS 530 D 0.10 12 1 XPOS 820 YPOS 530 D 0.2 // do stuff to get strings and indexes and then : if(strnum(filecontentsstring, indexvalue))  {    // replace this line in the file with another line here . }
  2. Nypyren Bregma   I will try those suggestions and honestly let you know if it goes well.
  3. Hi their I've been using C++ for about 4+ years now on an off  and for the life of me I've never had the need too compare strings with specific integers especially  from a text file but now is the day.   I've done some searching around and it yields no useful results apart from conversions between integers and strings which frankly I'm not quite shore if it's needed or not anyways Id label myself as a in the door expert on c++  working my way to the finish line of full expert so you can be complex-ish but Id prefer as simple as possible,  I've looked at the c++ specification in the string class part and yea all I could find was a function call string.find() tried that and it was only giving me the std::string::npos of the converted interger to string not the actual interger value since I need that interger value to write too a text file on a specific line for my tilemap setter and getter.  here is some of the code not all of it but gives you the idea that I've mostly tried:   //THAT TEST PROGRAM TO TRY AND HOPE IT WORKS : D #include <iostream> #include <string> int main() {   std::string fudgepacket = "The Packet of Fudge";   std::string fudgepacketstringtobefoundIthink = "Fudge";   std::size_t found =  fudgepacket,find(fudgepacketstringtobefoundithink);   int thatvalueofmight = 10;     std::string thatstringmight = "hello their this is 10";   std::string mightyvalueofstring = std::to_string(thatvalueofmight);     if(found == std::string::npos)       {           std::cout << "You've Found Me, Packet!";        }    return 0; } So how do I do it , how do I compare a std::string with a specific integer  I was hoping for a function like  strnum(stringcontents, integervalue);      std::string stringcontents = "THIS IS 10"; int  integervalue = 10;  int main() {      if(strnum(stringcontents, integervalue))    {          std::cout << "Found the Number !" << std::endl;         //OR          std::cout << "Found the Number  ! = " << Numthatwasfound << std::endl;     }  }
  4.     if(strstr(objfiletext.c_str(), "f "))         {             sscanf(objfiletext.c_str(), "f %d %d %d", &face.num[0], &face.num[1], &face.num[2]);                 face.num[0]-=1;                 face.num[1]-=1;                 face.num[2]-=1;                 vertexIndices.push_back(face.num[0]);                 vertexIndices.push_back(face.num[1]);                 vertexIndices.push_back(face.num[2]);         }     }
  5. Gooey :      if(strstr(objfiletext.c_str(), "f "))         {             sscanf(objfiletext.c_str(), "f %d %d %d", &face.num[0], &face.num[1], &face.num[2]);                 face.num[0]-1;                 face.num[1]-1;                 face.num[2]-1;                 vertexIndices.push_back(face.num[0]);                 vertexIndices.push_back(face.num[1]);                 vertexIndices.push_back(face.num[2]);         }
  6. What are you talking about ?   kMcDevitt they are modified..?
  7. KMCDevitt :  like this ? :    if(strstr(objfiletext.c_str(), "f ")) { sscanf(objfiletext.c_str(), "f %d %d %d", &face.num[0], &face.num[1], &face.num[2]); vertexIndices.push_back(face.num[0]-1); vertexIndices.push_back(face.num[1]-1); vertexIndices.push_back(face.num[2]-1); }
  8. Okay I thought might post this here since it's related I've successfully got data from a .obj and been able to use it as a vertex data for glbufferdata however when it comes to the cube.obj file it's a totally different story there seems to be issues with faces not showing on framebuffer . :  Here is my main function : Main function : int main ( int argc, char** argv ) { SDL_WM_SetCaption("THE ENGINE", "THE ENGINE"); GL_Helper.Access(); GL_Helper.LoadObj("models/cube.obj"); while(Running) { if(keystate[SDLK_RETURN]) { GL_Helper.ShaderSetup("Vertex.vert", "fragment.frag"); } while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: return 0; break; } } if(keystate[SDLK_ESCAPE]) return 0; //DRAW FUNCTION GL_Helper.Render(); } } This is my shadersetup : void OpenGL::ShaderSetup(const char * vertfile, const char * fragfile) { GLuint VertexShader , FragmentShader; std::ifstream VERTEX_ShaderFile(vertfile); std::string VERTEX_filetext; GLchar VERTEX_ShaderCompileLOG[256]; GLint VERTEX_ShaderCompileSTATUS, VERTEX_ShaderCompileLENGTH; while(VERTEX_ShaderFile.good()) { std::string VERTEX_line; std::getline(VERTEX_ShaderFile, VERTEX_line); VERTEX_filetext.append(VERTEX_line + "\n"); } GLchar const * VERTEX_shader_source = VERTEX_filetext.c_str(); GLint const VERTEX_shader_length = VERTEX_filetext.size(); VertexShader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(VertexShader, 1, &VERTEX_shader_source, &VERTEX_shader_length); glCompileShader(VertexShader); glGetShaderiv(VertexShader, GL_COMPILE_STATUS, &VERTEX_ShaderCompileSTATUS); glGetShaderiv(VertexShader, GL_INFO_LOG_LENGTH, &VERTEX_ShaderCompileLENGTH); glGetShaderInfoLog(VertexShader, VERTEX_ShaderCompileLENGTH,NULL, VERTEX_ShaderCompileLOG ); std::ifstream FRAGMENT_ShaderFile(fragfile); std::string FRAGMENT_filetext; GLchar FRAGMENT_ShaderCompileLOG[256]; GLint FRAGMENT_ShaderCompileSTATUS, FRAGMENT_ShaderCompileLENGTH; while(FRAGMENT_ShaderFile.good()) { std::string FRAGMENT_line; std::getline(FRAGMENT_ShaderFile, FRAGMENT_line); FRAGMENT_filetext.append(FRAGMENT_line + "\n"); } GLchar const * FRAGMENT_shader_source = FRAGMENT_filetext.c_str(); GLint const FRAGMENT_shader_length = FRAGMENT_filetext.size(); FragmentShader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(FragmentShader, 1, &FRAGMENT_shader_source, &FRAGMENT_shader_length); glCompileShader(FragmentShader); glGetShaderiv(FragmentShader, GL_COMPILE_STATUS, &FRAGMENT_ShaderCompileSTATUS); glGetShaderiv(FragmentShader, GL_INFO_LOG_LENGTH, &FRAGMENT_ShaderCompileLENGTH); glGetShaderInfoLog(FragmentShader, FRAGMENT_ShaderCompileLENGTH,NULL, FRAGMENT_ShaderCompileLOG ); GLuint Program = glCreateProgram(); glAttachShader(Program, VertexShader); glAttachShader(Program, FragmentShader); //SETUP GLGETPROGRAMINFOLOG //SETUP GLGETPROGRAMIV glLinkProgram(Program); glUseProgram(Program); //std::cout << VERTEX_shader_source << std::endl; std::cout << FRAGMENT_ShaderCompileLOG << std::endl; std::cout << VERTEX_ShaderCompileLOG << std::endl; // std::cout << << std::endl; } So here is my current .obj file parser so far :   void OpenGL::LoadObj(const char * objfile) { std::ifstream objstream(objfile); std::string objfiletext; while(objstream.good()) { std::getline(objstream, objfiletext); if(strstr(objfiletext.c_str(), "v ")) { sscanf(objfiletext.c_str(), "v %f %f %f", &vertex.x, &vertex.y, &vertex.z); //printf("v %f %f %f", tmpx, tmpy , tmpz); //std::cout << tmpx << tmpy << tmpz << std::endl; vertices.push_back(vertex.x); std::cout << vertices.at(0) << std::endl; vertices.push_back(vertex.y); std::cout << vertices.at(1) << std::endl; vertices.push_back(vertex.z); std::cout << vertices.at(2) << std::endl; } if(strstr(objfiletext.c_str(), "f ")) { sscanf(objfiletext.c_str(), "f %d %d %d", &face.num[0], &face.num[1], &face.num[2]); vertexIndices.push_back(face.num[0]); vertexIndices.push_back(face.num[1]); vertexIndices.push_back(face.num[2]); } } } This is my render function : void OpenGL::Render() { //CLEAR THE FRAMEBUFFER glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glGenVertexArrays(1, &VertexArrayID); glBindVertexArray(VertexArrayID); static const GLfloat g_vertex_buffer_data[] = { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, }; glGenBuffers(1, &vertexbuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(vertex), &vertices[0], GL_STATIC_DRAW); glGenBuffers(1, &elementbuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexIndices.size() * sizeof(int), &vertexIndices[0], GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glEnableVertexAttribArray(0); glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, sizeof(vertex), (void*)0 ); glDrawElements(GL_TRIANGLES, vertexIndices.size(), GL_INT, &vertexIndices[0]); //glDrawArrays(GL_TRIANGLES, 0, 3); glDisableVertexAttribArray(0); //UPDATE FRAMEBUFFER SDL_GL_SwapBuffers(); } This is fragment shader : #version 130 vec4 color = vec4(1.0, 0.0, 0.0, 1.0); void main() { // Setting Each Pixel To Red gl_FragColor = color; } This is my vertex shader : #version 130 in vec4 position; void main() { mat3 modelviewmatrix = mat3( vec3(1.0, 0.0, 0.0), vec3(0.0, 2.0, 0.0), vec3(0.0, 0.0, 1.0) ); gl_Position = vec4(modelviewmatrix * position.xyz, 1.0); } Cube.obj : # Blender v2.74 (sub 0) OBJ File: '' # www.blender.org o Cube v 1.000000 -1.000000 -1.000000 v 1.000000 -1.000000 1.000000 v -1.000000 -1.000000 1.000000 v -1.00000 -1.000000 -1.000000 v 1.000000 1.000000 -0.999999 v 0.999999 1.000000 1.000001 v -1.000000 1.000000 1.000000 v -1.000000 1.000000 -1.000000 s off f 2 3 4 f 8 7 6 f 5 6 2 f 6 7 3 f 3 7 8 f 1 4 8 f 1 2 4 f 5 8 6 f 1 5 2 f 2 6 3 f 4 3 8 f 5 1 8
  9. void OpenGL::LoadObj(const char * objfile){ std::ifstream objstream(objfile); std::string objfiletext; float tmpx, tmpy, tmpz; while(objstream.good()) { std::getline(objstream, objfiletext); if(strstr(objfiletext.c_str(), "v ")) { sscanf(objfiletext.c_str(), "v %f %f %f", &tmpx, &tmpy, &tmpz); std::cout << tmpx << tmpy << tmpz << std::endl; } } } this worked for cout! void OpenGL::LoadObj(const char * objfile) { std::ifstream objstream(objfile); std::string objfiletext; float tmpx, tmpy, tmpz; while(objstream.good()) { std::getline(objstream, objfiletext); if(strstr(objfiletext.c_str(), "v ")) { sscanf(objfiletext.c_str(), "v %f %f %f", &tmpx, &tmpy, &tmpz); printf("v %f %f %f", tmpx, tmpy , tmpz); //std::cout << tmpx << tmpy << tmpz << std::endl; } } } this works for printf "check stdout.txt and or stderr.txt or command prompt or terminal or whatever if using SDL 1.2+ maybe"
  10. I'll try that kMCDevttt This works ! : D value[0] = x , value[1] = y , value[2] = z . now to vectorize it or something. void OpenGL::LoadObj(const char * objfile) {      std::ifstream objstream(objfile);     std::string objfiletext;     float value[256];     char test[256];     int i;     float tmpx, tmpy, tmpz;     while(objstream.good())     {         std::getline(objstream, objfiletext);         if(strstr(objfiletext.c_str(), "v "))         {                 sscanf(objfiletext.c_str(), "v %f %f %f", &value[0], &value[1], &value[2], &value[3]);                 std::cout << value[1] << std::endl;         }     } }
  11. LOL Dave ... that is just no thanks.
  12. URGH.... I'm aware of this ..    However I'm still getting this crappy output :      v 0.000000 0.000000 0.000000v 0.000000 0.000000 0.000000v 0.000000 0.000000 0.000000v 0.000000 0.000000 0.000000v 0.000000 0.000000 0.000000v 0.000000 0.000000 0.000000v 0.000000 0.000000 0.000000v 0.000000 0.000000 0.000000 changed it to c instead for ease "I think" void OpenGL::LoadObj(const char * objfile) {     FILE *objfile_pointer;     long objfile_size;     objfile_pointer = fopen(objfile, "r+w");     float tmpx, tmpy, tmpz;     char i;     char objfile_buffer[256];     if(objfile_pointer!= NULL)     {         while(fgets(objfile_buffer, sizeof(objfile_buffer), objfile_pointer))         {             if(fgetc(objfile_pointer) == 'v')             {                      sscanf(objfile_buffer, "v %f %f %f", &tmpx, &tmpy, &tmpz);                printf("v %f %f %f");                       }         }     } }
  13. Wondering if the only data you can get is from objfiletext.c_str() not from the stored values...?? Just tried that same thing different garbage output : 4.2039e-0452.8026e-0454.83284e-039 4.2039e-0452.8026e-0454.83284e-039 4.2039e-0452.8026e-0454.83284e-039 4.2039e-0452.8026e-0454.83284e-039 4.2039e-0452.8026e-0454.83284e-039 4.2039e-0452.8026e-0454.83284e-039 4.2039e-0452.8026e-0454.83284e-039 4.2039e-0452.8026e-0454.83284e-039 CUBE.OBJ :  # Blender v2.74 (sub 0) OBJ File: '' # www.blender.org o Cube v 1.500000 -1.000000 -1.000000 v 1.500000 -1.000000 1.000000 v -1.500000 -1.000000 1.000000 v -1.500000 -1.000000 -1.000000 v 1.000000 1.000000 -0.999999 v 0.999999 1.000000 1.000001 v -1.000000 1.000000 1.000000 v -1.000000 1.000000 -1.000000 s off f 2 3 4 f 8 7 6 f 5 6 2 f 6 7 3 f 3 7 8 f 1 4 8 f 1 2 4 f 5 8 6 f 1 5 2 f 2 6 3 f 4 3 8 f 5 1 8     UPDATED CODE :  void OpenGL::LoadObj(const char * objfile) {      std::ifstream objstream(objfile);     std::string objfiletext;     float value[2];     while(objstream.good())     {         std::getline(objstream, objfiletext);         if(strstr(objfiletext.c_str(), "v "))         {             sscanf(objfiletext.c_str(), "%f %f %f", value[0], value[1], value[2]);             std::cout << value[0] << value[1] << value[2] << std::endl;         }     } }  
  14. I can't access why and how this code is not outputing the right results and if this is the best way to .obj file parsing with c++ since ".c_str()"?     So far it gets the filename and opens it up with ifstream then checks if the ifstream opened up good then it gets the lines and checks with strstr if the char array contains a  v and space "v " if it does then sscanf the char array "c-string" at that position "I suppose" for the format number.number number number. However even that format specifier is wrong I think... but it's all so confusing to me. The documentation writes "..." for this parameter of sscanf(const char * char, const char *format , ...); Here is the code :    void OpenGL::LoadObj(const char * objfile) {     std::ifstream objstream(objfile);     std::string objfiletext;       int value[3];       while(objstream.good())     {         std::getline(objstream, objfiletext);           if(strstr(objfiletext.c_str(), "v "))         {               sscanf(objfiletext.c_str(), "%d.%d %d %d", value[0], value[1], value[2], value[3]);               std::cout << value[0] << value[1] << value[2] << std::endl;         }     } }   public member function usage :  GLrenderer.LoadObj("cube.obj"); CONSOLE OUTPUT :    3414949232 3414949232 3414949232 3414949232 3414949232 3414949232 3414949232 3414949232 CUBE.OBJ :  # Blender v2.74 (sub 0) OBJ File: '' # www.blender.org o Cube v 1.500000 -1.000000 -1.000000 v 1.500000 -1.000000 1.000000 v -1.500000 -1.000000 1.000000 v -1.500000 -1.000000 -1.000000 v 1.000000 1.000000 -0.999999 v 0.999999 1.000000 1.000001 v -1.000000 1.000000 1.000000 v -1.000000 1.000000 -1.000000 s off f 2 3 4 f 8 7 6 f 5 6 2 f 6 7 3 f 3 7 8 f 1 4 8 f 1 2 4 f 5 8 6 f 1 5 2 f 2 6 3 f 4 3 8 f 5 1 8   Please don't tell me to use a library like assimp , I wanna do this all by myself thank you.
  15. Dominic Hughes

    Why is glGetShaderiv(); crashing my written program.

    vstrakh fixed it !  :D took a few minutes... bloody heck was annoying though.. void OpenGL::ShaderSetup(const char * fragfile, const char * vertfile) {     GLuint VertexShader , FragmentShader;       std::ifstream ShaderFile(fragfile);     std::string  filetext;     //std::string LOG;      // GLchar const * shader_source = filetext.c_str();     GLchar ShaderCompileLOG[256];   //  GLint const shader_length = filetext.size();     GLint ShaderCompileSTATUS, ShaderCompileLENGTH;       while(ShaderFile.good())     {         std::string line;         std::getline(ShaderFile, line);         filetext.append(line + "\n");     }       GLchar const * shader_source = filetext.c_str();       GLint const shader_length = filetext.size();       VertexShader = glCreateShader(GL_VERTEX_SHADER);       glShaderSource(VertexShader, 1, &shader_source, &shader_length);       glCompileShader(VertexShader);      // std::cout << filetext << std::endl;       //std::cout << ShaderCompileSTATUS << std::endl;       glGetShaderiv(VertexShader, GL_COMPILE_STATUS, &ShaderCompileSTATUS);       glGetShaderiv(VertexShader, GL_INFO_LOG_LENGTH, &ShaderCompileLENGTH);       glGetShaderInfoLog(VertexShader, ShaderCompileLENGTH,NULL, ShaderCompileLOG );       //std::cout << ShaderCompileLENGTH << std::endl;     FragmentShader = glCreateShader(GL_FRAGMENT_SHADER);       std::cout << shader_source << std::endl;     std::cout << ShaderCompileLOG << std::endl;    //   std::cout <<  << std::endl; } Vertex shader failed to compile with the following errors: ERROR: 0:5: error(#143) Undeclared identifier: AFAEASGRGTREHETEATJRYTKJTYKTUK ERROR: error(#273) 1 compilation errors.  No code generated  
  • 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!