tre

Members
  • Content count

    206
  • Joined

  • Last visited

Community Reputation

168 Neutral

About tre

  • Rank
    Member
  1. Make sure that you've linked your JPEG library correctly.
  2. Problems with OBJ-loader

    Phew! I found my error as I posted in my previous (last) edit. The error was that a few rows in my OBJ-file was empty. I solved this by checking for the length of the current string. If it is larger than X (in my case I chose 4) then we can parse the string, if not we should continue to the next one. [source lang="cpp"]void Models::parseAndLoad(const char* filename){ std::ifstream myfile; myfile.open(filename); if(!myfile.is_open()){ alert(L"No file!"); return; } std::string currentString; std::vector<std::string> expline; std::vector<std::string> expline_f; float currentVertex; int inFace; int i = 1; while(!myfile.eof()){ getline(myfile, currentString); if(currentString.length() >= 4){ // check the length of the current string, so that it actually contains something if(currentString[0] == 'v' && currentString[1] == ' '){ // vertex positions expline = explode(" ", currentString); from_string<float>(currentVertex, expline.at(2), std::dec); vertices.push_back(currentVertex); from_string<float>(currentVertex, expline.at(3), std::dec); vertices.push_back(currentVertex); from_string<float>(currentVertex, expline.at(4), std::dec); vertices.push_back(currentVertex); }else if(currentString[0] == 'v' && currentString[1] == 't'){ // vertex texturecoordinates expline = explode(" ", currentString); from_string<float>(currentVertex, expline.at(2), std::dec); texcoords.push_back(currentVertex); from_string<float>(currentVertex, expline.at(3), std::dec); texcoords.push_back(currentVertex); from_string<float>(currentVertex, expline.at(4), std::dec); texcoords.push_back(currentVertex); }else if(currentString[0] == 'v' && currentString[1] == 'n'){ // vertex normals expline = explode(" ", currentString); from_string<float>(currentVertex, expline.at(2), std::dec); normals.push_back(currentVertex); from_string<float>(currentVertex, expline.at(3), std::dec); normals.push_back(currentVertex); from_string<float>(currentVertex, expline.at(4), std::dec); normals.push_back(currentVertex); }else if(currentString[0] == 'f'){ // faces expline = explode(" ", currentString); // splits the row into the three parts that contain the polygon face information expline_f = explode("/", expline.at(1)); from_string<int>(inFace, expline_f.at(0), std::dec); vFaces.push_back(inFace-1); from_string<int>(inFace, expline_f.at(1), std::dec); tFaces.push_back(inFace-1); from_string<int>(inFace, expline_f.at(2), std::dec); nFaces.push_back(inFace-1); expline_f = explode("/", expline.at(2)); from_string<int>(inFace, expline_f.at(0), std::dec); vFaces.push_back(inFace-1); from_string<int>(inFace, expline_f.at(1), std::dec); tFaces.push_back(inFace-1); from_string<int>(inFace, expline_f.at(2), std::dec); nFaces.push_back(inFace-1); expline_f = explode("/", expline.at(3)); from_string<int>(inFace, expline_f.at(0), std::dec); vFaces.push_back(inFace-1); from_string<int>(inFace, expline_f.at(1), std::dec); tFaces.push_back(inFace-1); from_string<int>(inFace, expline_f.at(2), std::dec); nFaces.push_back(inFace-1); }else{ // contains none of the above characters, skip the rest continue; } }else{ // the string contains nothing, just continue to the next string continue; } } myfile.close(); initVBO(); }[/source] If you have any tips or pointers on the above code, you're welcome to comment. Thanks!
  3. Problems with OBJ-loader

    [quote name='Buckeye' timestamp='1305352516' post='4810572'] Instead of testing the value of myfile, use myfile.isopen(). The variable myfile should never be null. Also, instead of using while( getline(...) ), try using while( !myfile.eof() && !myfile.bad() ) or something similar. Then use getline(...) inside the while loop. [/quote] Thanks for the tips. I'm now using this instead of my old code. I'll read more on the ifstream functions as well. However, I'm still getting my debug assertion error: "string subscript out of range". [i]Edit[/i] The following change to my while loop gives me a message box with the message "Space!" once and then throws the error. Still can't figure this out. [source lang="cpp"]while(!myfile.eof() && myfile.good()){ std::getline(myfile, c); if(c[1] == ' '){ alert(L"Space!"); } }[/source] [i]Edit 2 [/i]And removing the while loop removes the error. So I guess I've at least found where it goes south... [i]Edit 3 [/i]So, I've allocated a console so that I can get some output while parsing the file. I think I've located the error. In my OBJ file, while reading everything is outputted until line 2865. The strange thing is that row 2866 is looking just the same as row 2865, save one more character (9 turns to 10 in the first value). [code]v -9.99746 -10.42154 300.79782 v -10.16290 -10.42154 300.99942[/code] It is however at the end of the vertex position list. At row 2872 there's a whitespace. I've tried looking for this and telling the program to "continue". But it doesn't help. So I guess it's the size of the line at row 2866 that's messing with my code. Could this be true? And how do I fix this? It's really a show stopper, if I can't change it. Thanks! [i]Edit 4 [/i]New code [source lang="cpp"]while(getline(myfile, currentString)){ if(currentString[0] == 'v' && currentString[1] == ' '){ std::cout << i << ": " << currentString << std::endl; }else if(isspace(currentString.at(0))){ continue; }else{ continue; } i++; }[/source] [i]Edit 5 [/i]Allright, the amount of edits is getting extreme, now However, now I've noticed that the problem can't be with line 2866. I'm getting correct output. Totally missed that. I've figured out that the problem is with lines that contain no characters at all. I don't know how to check for that. I've tried "currentString.empty()", "currentString[0] == '\n'", "isspace(currentString[0])" and of course the "else" statement which I thought would handle everything that wasn't covered in the if/else-if statements. Hope you guys have any insight. I'm out of ideas for the moment.
  4. Hi. I'm working on migrating to a newer version of OpenGL, because of this I'm reworking quite a lot of code. The thing that's bugging out is my OBJ-loader. The following function throws the "String subscript out of range" error message at the "while"-loop. [source lang="cpp"]void Models::parseAndLoad(const char* filename){ std::ifstream myfile; myfile.open(filename); if(!myfile){ alert(L"No file!"); return; } std::string c; std::vector<std::string> expline; std::vector<std::string> expline_f; float currentVertex; int inFace; while(getline(myfile, c)){ if(c[0] == 'v' && c[1] == ' '){ expline = explode(" ", c); currentVertex = convertFromString(expline.at(2)); // first value vertices.push_back(currentVertex); currentVertex = convertFromString(expline.at(3)); // second value vertices.push_back(currentVertex); currentVertex = convertFromString(expline.at(4)); // third value vertices.push_back(currentVertex); }else if(c[0] == 'v' && c[1] == 't'){ expline = explode(" ", c); currentVertex = convertFromString(expline.at(2)); // first value texcoords.push_back(currentVertex); currentVertex = convertFromString(expline.at(3)); // second value texcoords.push_back(currentVertex); currentVertex = convertFromString(expline.at(4)); // third value texcoords.push_back(currentVertex); }else if(c[0] == 'v' && c[1] == 'n'){ expline = explode(" ", c); currentVertex = convertFromString(expline.at(2)); // first value normals.push_back(currentVertex); currentVertex = convertFromString(expline.at(3)); // second value normals.push_back(currentVertex); currentVertex = convertFromString(expline.at(4)); // third value normals.push_back(currentVertex); }else if(c[0] == 'f'){ expline = explode(" ", c); // splits the row into three parts that contain the face information expline_f = explode("/", expline.at(1)); // splits the first row into vertex, texture and normal information inFace = convertFromString(expline_f.at(0), 2); vFaces.push_back(inFace-1); inFace = convertFromString(expline_f.at(1), 2); tFaces.push_back(inFace-1); inFace = convertFromString(expline_f.at(2), 2); nFaces.push_back(inFace-1); expline_f = explode("/", expline.at(2)); // splits the second row as above inFace = convertFromString(expline_f.at(0), 2); vFaces.push_back(inFace-1); inFace = convertFromString(expline_f.at(1), 2); tFaces.push_back(inFace-1); inFace = convertFromString(expline_f.at(2), 2); nFaces.push_back(inFace-1); expline_f = explode("/", expline.at(3)); // splits the third row inFace = convertFromString(expline_f.at(0), 2); vFaces.push_back(inFace-1); inFace = convertFromString(expline_f.at(1), 2); tFaces.push_back(inFace-1); inFace = convertFromString(expline_f.at(2), 2); nFaces.push_back(inFace-1); }else{ // failsafe continue; // do nothing } } myfile.close(); initVBO(); }[/source] In the above the first "subscript" error occurs at the declaration of the while loop (while(getline(myfile, c))). I really don't know what the error message means. As I understand it, some people get it when trying to load an empty file. The file I'm using is not empty. I've checked Also, the code above used to work in Visual C++ 2008 and a lower OpenGL version. Thanks in advance, Marcus
  5. Linker errors in Visual C++ 2010

    [quote name='mateo' timestamp='1304970876' post='4808690'] Hello, tre Looks like it is not finding the glew library. In Visual Studio 2010 the include/library directories are setup differently that in VS2008, in VS2008 the directories were global in scope. In VS2010, each project has its own independant directory info. So go into your projects properties, goto 'VC++ Directories' and setup your directories to point to the windows sdk include/library directories, and see if this doesn't help. Don't forget to drop the glew include/libraries into the windows sdk include/library folders. Also, drop the glew dll's in the system32 directory (windows xp,vista,7). [/quote] Hi mateo! Thanks for replying. You're correct in that it didn't find the GLEW library. I really couldn't find out why, since I had the libs and dll's in the right place (several right places, even). It turns out that if you use a explicit path ("C:/.../.../.../somelib.lib") to the lib rather than using a relative path ("somelib.lib") in the project properties or (even though it's discouraged in a previous post) in a [i]#pragma comment [/i]it finds the library. If this is because it finds old versions or if it's because of what you point out, a different way of using directories in VC2010, I don't know. By the way, the GLEW dll can be placed in the project "root" and will be found by the project. This way you can redistribute it when you've finished your project.
  6. Linker errors in Visual C++ 2010

    [quote name='kiwibonga' timestamp='1304900089' post='4808308'] I googled around because this is also something I wondered about (is it possible to put DLLs in a subfolder rather than in the same folder as the program?) .. Turns out the OS is entirely responsible for locating DLLs. So apparently, the only solution is to add the custom folder to the PATH environment variable (meaning it'll break on other machines unless they have the path set as well). [/quote] Sounds like "it's possible but not recommended" then. Since I guess Windows won't let you alter the environment variable without regarding the program as a virus or something. Allright. Thanks for letting me know.
  7. Linker errors in Visual C++ 2010

    [quote name='karwosts' timestamp='1304896362' post='4808278'] [quote] By explicitly you mean something like "C:/programming/my project/data/libs/somelib.lib", right? [/quote] I put the .dll's right in the folder alongside my visual studio solution (and in the debug/release directories if you want to run them as standalone exe's). For the libs I don't put them in the project folders, but rather in a central place that any projects can include (so I don't have them duplicated all over the place. I just have : C:\SDKs\glew-1.5.7 C:\SDKs\glew-1.5.8 C:\SDKs\Assimp-1.1.7 C:\SDKs\boost_1_44_0 etc. Inside these folders are the headers and libs to include. That's just personal preference though, you're welcome to do it however you like. [quote] Can I specify somewhere to collect the dll from like "C:/programming/my project/data/dll/" as well? Or should it just be right there in the "root"? [/quote] I'm not aware of ways to specify a location for dll's, I usually just drop them in the project root. The thing about dll's is that you have to redistribute them alongside your binary for someone to run your exe on another computer. There's no such requirement for the libs (they get compiled into the .exe itself). [/quote] I'm allways eager to learn new and more efficient ways of doing things, and it seems like a much better idea to put them all in one place than to have them all over the place. What I meant about the dll's was that if I could put them in a folder inside my project and point my project to them. That way they'd be redistributed but in a "safer" place than alongside the .exe. I'll take a look at if I can find anything about this. Thanks for all the great help!
  8. Linker errors in Visual C++ 2010

    [quote name='kiwibonga' timestamp='1304882122' post='4808206'] Note that the compiled executables will be in [project name]\release and [project name]\debug, but the working directory by default (where the dlls should be) is [project name]\[project name] You can normally put the dlls in system32, however the executable will probably use the dlls in your project folder first if present; make sure both the lib and dll are the same version [/quote] [quote name='karwosts' timestamp='1304883775' post='4808219'] You can put the .dll's in system32 as well, but for me, rather than mess with polluting my visual studio install directory with libs and my system32 with dll's that I use for development, I just put all my sdk's and libs in one place, and always include them explicitly through "additional include directories", and then always put my .dll's in the project folder. This saves a lot of confusion as to what is included versus what isn't, especially when changing versions of things. Then I know exactly what I'm including all the time, and I don't have to look around deep in system files to try to find if I have old libs there or not. [/quote] By explicitly you mean something like "C:/programming/my project/data/libs/somelib.lib", right? (english isn't my native language) I guess that would make it easier to compile a program to be run on other computers as well, since all the files are right there. Can I specify somewhere to collect the dll from like "C:/programming/my project/data/dll/" as well? Or should it just be right there in the "root"? [quote name='abeylin' timestamp='1304883689' post='4808217'] To find out which dlls are actually used, I highly recommend sysinternals. They are free tools from Microsoft, which you can find here: [url="http://technet.microsoft.com/en-us/sysinternals/bb795533"]http://technet.micro...ernals/bb795533[/url] process explorer - great replacement for 'task manager', it tells you which dll's are loaded, which files are opened, etc. per process process monitor - great tool which tells you the files/registry your process uses. Process explorer gives you a snapshot (does not show you which files were opened, only currently opened files), process monitor shows you entire history of the process. There are plenty of other important tools there as well. [/quote] Thanks for the great tips! I'm sure they'll all be a great resource.
  9. Linker errors in Visual C++ 2010

    Sorry for making ANOTHER post... that's three in a row. [s]A few things. I have now noticed that I had written "glewInit()" wrong... so, that's fixed. I also added a few alerts in there:[/s] [code]GLenum err = glewInit(); if(GLEW_OK != err){ alert(L"GLEW is OK"); }else{ alert(L"GLEW is not OK!"); }[/code] [s]This gives me "GLEW is not OK!". But... when I get to the part that checks for "WGL_ARB_create_context" I get my message "Using 3.x context!". Now I'm really confused... why is GLEW not OK and still functions? Does it function? How can I find out? [i]edit[/i] quickly... I mean I can check it out by using non 3.2+ context stuff but that takes quite some programming [/s] Never mind. Nothing to see here I'm being a dork. if(GLEW_OK != err) means that there's a problem with GLEW. Obviously it's not OK then. I put my alerts in the wrong order. *facepalm* [quote name='karwosts' timestamp='1304875027' post='4808154'] Well, if you're using glew32.lib, make sure that the glew32.dll is located somewhere your project can find it (in the project directory is the easiest place). Also make sure that the program can find glew32.lib as well (you may have to add its folder under Additional Library Directories in Linker/General). [/quote] I was under the impression that I allways had to put the dll's in system32 and/or SysWOW64. Is this incorrect?
  10. Linker errors in Visual C++ 2010

    [quote name='abeylin' timestamp='1304878561' post='4808173'] [quote name='tre' timestamp='1304874485' post='4808150'] Specifically, I went into [i]"project name" properties[/i] then under [i]Linker[/i] > [i]Input[/i] (I selected [i]All configurations[/i] first) I entered "glew32.lib" and "opengl32.lib" in the [i]Additional Dependencies[/i] option. Then I tried to [i]Build Solution[/i] in the [i]Build [/i]menu. [/quote] Try giving full path to library, it may still be finding old versions. [/quote] Allright. This made the errors go away and my project compiles. Although... this won't work: [code]if(wglewIsSupported("WGL_ARB_create_context") == 1){ alert(L"Using 3.x context!"); hrc = wglCreateContextAttribsARB(hdc, NULL, attributes); wglMakeCurrent(NULL, NULL); wglDeleteContext(tmpOGLContext); wglMakeCurrent(hdc, hrc); }else{ alert(L"Using 2.1 context."); hrc = tmpOGLContext; }[/code] So now I'm thinking that maybe it hid the errors but that it's still there. Everytime this code is run, it gives me the 2.1-message. And according to the OpenGL Extensions Viewer 3.0, I have the "WGL_ARB_create_context" available. As well as its function "wglCreateContextAttribsARB"... Thanks for this!
  11. Linker errors in Visual C++ 2010

    [quote name='karwosts' timestamp='1304875027' post='4808154'] Well, if you're using glew32.lib, make sure that the glew32.dll is located somewhere your project can find it (in the project directory is the easiest place). Also make sure that the program can find glew32.lib as well (you may have to add its folder under Additional Library Directories in Linker/General). [/quote] I've done that. I've also tried putting it in [i]System32[/i] and [i]SysWOW64[/i]. Will not help. How difficult would it be to check for extensions on your own? Because, that's what GLEW's used for, isn't it? Shouldn't I just be able to use [i]glGetString[/i] and see if the extensions are available and then use them? Or does GLEW do other things as well? "GLEW provides efficient run-time mechanisms for determining which OpenGL extensions are supported on the target platform." From the site. [quote name='mhagain' timestamp='1304876880' post='4808164'] I'm not sure about 2010, but in 2008 if you want to statically link to GLEW you need to link to glew32s.lib and #define GLEW_STATIC before including glew.h, so maybe try that. [/quote] This did not work. Could not find any glew32s.lib and defining GLEW_STATIC before including [i]glew.h[/i] did nothing. Thanks for trying to help, though! Thanks again guys. Any more tips?
  12. Linker errors in Visual C++ 2010

    [quote name='karwosts' timestamp='1304868664' post='4808114'] [quote] Allright, so I've removed my pragma comments and added the libraries to the project properties instead. [/quote] What did you do exactly, in what menus? [/quote] Specifically, I went into [i]"project name" properties[/i] then under [i]Linker[/i] > [i]Input[/i] (I selected [i]All configurations[/i] first) I entered "glew32.lib" and "opengl32.lib" in the [i]Additional Dependencies[/i] option. Then I tried to [i]Build Solution[/i] in the [i]Build [/i]menu.
  13. Linker errors in Visual C++ 2010

    I tried using the files provided by karwosts, but it gave me the same issues (no matter how I tried to use them). So I'm still stuck.
  14. Linker errors in Visual C++ 2010

    [quote name='karwosts' timestamp='1304799076' post='4807780'] I had the same issue with that, a lot of VC6 projects don't convert directly to VC++2010. I was able to upgrade it by converting it first to vc++2008, and then converting that to vc++2010. If you don't have both versions on hand and don't want to bother with it, you can use mine if you like. Its 1.5.7 which is a little older than the most recent, but it should be fine. If you want the latest version you'll have to convert it yourself. [/quote] Thanks! Will try this tomorrow. I'll report back. Thanks again.
  15. Linker errors in Visual C++ 2010

    [quote name='karwosts' timestamp='1304796071' post='4807767'] Did you recompile glew for VS2010? I could be mistaken but I didn't think the libs were compatible across different versions of VC++. [/quote] I've downloaded the most recent source and as I understand it, I'm supposed to use the "glew.dsw" in build/vc6. When I try to convert the project I get four error messages regarding the three project files. For example "'glew_shared.dsp' cannot be loaded". The same error message for all the projects. So if I can't convert them... how am I going to compile them? Sigh.