• What do you need help with? Version 5
    5,752 replies, posted
You can't call GL functions from the destructor, it's executed on a different thread. No idea what causes this error though. [editline]13th August 2012[/editline] Maybe there's more info in the Exception object, I think OpenTK includes the error message somewhere.
Ahh shit, how could I do the automatic deleting of OpenGL Resources?
[QUOTE=Richy19;37205644]Ahh shit, how could I do the automatic deleting of OpenGL Resources?[/QUOTE] glDelete?
[QUOTE=Meatpuppet;37205700]glDelete?[/QUOTE] Yes, but if I cant call it in the destructor then is there any other method whereby I dont have to call a custom function myself to delete it all.
[QUOTE=Richy19;37205933]Yes, but if I cant call it in the destructor then is there any other method whereby I dont have to call a custom function myself to delete it all.[/QUOTE] I have an Action queue that is filled with lambda closures from by the destructors and emptied by a function called in the main loop. [csharp] ~Texture() { RenderingMethodQueue.Enqueue(() => { GL.DeleteTexture(_textureId); Trace.TraceDeleteTexture(_name); }); } [/csharp] Something like that. No idea if it's thread-safe. The destructors are also cancelled after a few seconds, so it's important to avoid long running code.
[QUOTE=Richy19;37205933]Yes, but if I cant call it in the destructor then is there any other method whereby I dont have to call a custom function myself to delete it all.[/QUOTE] You could (maybe) make a list with glNewList() and put all your resources in there, then clear resources with glDeleteLists()
[QUOTE=Richy19;37205644]Ahh shit, how could I do the automatic deleting of OpenGL Resources?[/QUOTE] The way I do it is that I make all OpenGL "objects" (anything that needs to glGen* and glDelete*) implement IDisposable [url=http://msdn.microsoft.com/en-us/library/ms244737(v=vs.80).aspx](make sure to implement it correctly)[/url], and in debug mode I throw an exception when it's not properly disposed. I'm actually planning on replacing this with a better system later on, but it very effectively lets us know when we're leaking OpenGL resources. [csharp] private void Dispose(bool disposing) { if (!disposed) { if (disposing) { if (Exists) { GL.DeleteBuffers(1, ref id); id = 0; } } disposed = true; #if DEBUG if (id != 0) throw new Exception("VBO not disposed properly"); #endif } } [/csharp]
[QUOTE=robmaister12;37209302]The way I do it is that I make all OpenGL "objects" (anything that needs to glGen* and glDelete*) implement IDisposable [url=http://msdn.microsoft.com/en-us/library/ms244737(v=vs.80).aspx](make sure to implement it correctly)[/url], and in debug mode I throw an exception when it's not properly disposed. I'm actually planning on replacing this with a better system later on, but it very effectively lets us know when we're leaking OpenGL resources. [csharp] private void Dispose(bool disposing) { if (!disposed) { if (disposing) { if (Exists) { GL.DeleteBuffers(1, ref id); id = 0; } } disposed = true; #if DEBUG if (id != 0) throw new Exception("VBO not disposed properly"); #endif } } [/csharp][/QUOTE] Does C# automatically call Dispose for you or do you put all your resources nto a list and dispose of them all at the end? Using this method tho, wouldnt leaving the dispose call to the destructor make it leak the resources? [editline]13th August 2012[/editline] This is how i have it now [csharp] public class FBO : IDisposable { uint fbo; uint depthBuff; uint texture; bool disposed; public FBO () { GL.GenRenderbuffers (1, out depthBuff); GL.GenTextures (1, out texture); GL.GenFramebuffers (1, out fbo); disposed = false; } public void Dispose () { Dispose (true); //GC.SuppressFinalize(this); } ~FBO () { Dispose (false); } protected virtual void Dispose (bool disposing) { if (!disposed) { if (disposing) { if (texture != 0) GL.DeleteTextures (1, ref texture); if (depthBuff != 0) GL.DeleteRenderbuffers (1, ref depthBuff); if (fbo != 0) GL.DeleteFramebuffers (1, ref fbo); fbo = 0; depthBuff = 0; texture = 0; } disposed = true; if (fbo != 0) throw new Exception ("FrameBuffer not disposed properly"); if (depthBuff != 0) throw new Exception ("DepthBuffer not disposed properly"); if (texture != 0) throw new Exception ("Texture not disposed properly"); } }[/csharp]
[QUOTE=Richy19;37210956]Does C# automatically call Dispose for you or do you put all your resources nto a list and dispose of them all at the end?[/QUOTE] Usually it's used with the [URL="http://msdn.microsoft.com/en-gb/library/yh598w02%28v=vs.100%29.aspx"]using statement[/URL]. Dispose is also (explicitly) called from the finalizer in most cases, but that wouldn't work for OpenGL. The only options are manual resource management or some kind of queue or collector that runs on the main thread. (Or possibly a hack involving shared contexts if you can delete textures created in the other context. I don't know enough about OpenGL to know whether that would work.)
yea just created a list and run it in the background at the end of the program. Next up im trying to write the shader code: from this: [cpp] bool Shader::linkShader() { GLint Result = GL_FALSE; int InfoLogLength; /// Link the program //fprintf(stdout, "Linking program "); glAttachShader(shaderID, VertexShaderID); glAttachShader(shaderID, FragmentShaderID); glLinkProgram(shaderID); /// Check the program glGetProgramiv(shaderID, GL_LINK_STATUS, &Result); glGetProgramiv(shaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); std::vector<char> ProgramErrorMessage( glm::max(InfoLogLength, int(1)) ); glGetProgramInfoLog(shaderID, InfoLogLength, NULL, &ProgramErrorMessage[0]); if(Result == GL_FALSE) fprintf(stdout, "%s\n", &ProgramErrorMessage[0]); if(Result = GL_TRUE) return true; else return false; }[/cpp] to [csharp] bool linkShader () { int Result; int InfoLogLength; /// Link the program //fprintf(stdout, "Linking program "); GL.AttachShader(shaderID, VertexShaderID); GL.AttachShader(shaderID, FragmentShaderID); GL.LinkProgram(shaderID); /// Check the program GL.GetProgram(shaderID, ProgramParameter.LinkStatus, Result); GL.GetProgram(shaderID, ProgramParameter.InfoLogLength, InfoLogLength); if(Result = true) return true; else return false; } [/csharp] but how do I do all the error checking that is done in the C++ version [editline]13th August 2012[/editline] Anyone mind having a look and tell me what/if I can improve? oh and if it works with the fbo on your computer [url]http://dl.dropbox.com/u/18453712/OpenTKGaem.zip[/url]
For an android game GUI, should I use the built in buttons and stuff, or should I just make my own bounding boxes checking for where the pointers are and stuff like that?
[I]GL.GetProgramInfoLog(int program)[/I] returns the info log as string. [csharp]if(Result = true) return true;[/csharp] This part doesn't compile. You can't compare or assign bools to int variables. (It's also wrong in the C++ code, it always returns true.) You should probably just throw an exception if the program isn't linked properly and change the method to void. Using error codes is very uncommon in .NET, the only place it's used in the framework that I know of is the Dictionary's TryGetValue method.
with: GL.GetProgram(shaderID, ProgramParameter.LinkStatus, out Result); Does Result only equal 0 when everything has been done correctly?
[QUOTE=Richy19;37211908]Anyone mind having a look and tell me what/if I can improve? oh and if it works with the fbo on your computer [URL]http://dl.dropbox.com/u/18453712/OpenTKGaem.zip[/URL][/QUOTE] You try to create the frame buffer twice. The parameterless constructor of IGame (the I prefix should be reserved for interfaces) is called implicitly and calls the base (GameWindow) constructor. You can remove the empty overrides from IGame if you make the class abstract, this also forces any derived classes to implement these methods.
[QUOTE=Tamschi;37212780][I]GL.GetProgramInfoLog(int program)[/I] returns the info log as string. [csharp]if(Result = true) return true;[/csharp] This part doesn't compile. You can't compare or assign bools to int variables. (It's also wrong in the C++ code, it always returns true.) You should probably just throw an exception if the program isn't linked properly and change the method to void. Using error codes is very uncommon in .NET, the only place it's used in the framework that I know of is the Dictionary's TryGetValue method.[/QUOTE] Changed it to: [csharp] void linkShader () { int Result = 0; string InfoLog; /// Link the program GL.AttachShader(shaderID, VertexShaderID); GL.AttachShader(shaderID, FragmentShaderID); GL.LinkProgram(shaderID); GL.GetProgram(shaderID, ProgramParameter.LinkStatus, out Result); InfoLog = GL.GetProgramInfoLog(shaderID); if(Result == 0) { System.Console.WriteLine(InfoLog); throw new Exception("Linking program failed"); } } void compileVertexShader (string vertCode) { int Result = 0; string InfoLog; GL.ShaderSource(VertexShaderID, vertCode); GL.CompileShader(VertexShaderID); GL.GetShader(VertexShaderID, ShaderParameter.CompileStatus, out Result); InfoLog = GL.GetShaderInfoLog(VertexShaderID); if(Result == 0) { System.Console.WriteLine(InfoLog); throw new Exception("Vertex shader compilation failed"); } } void compileFragmentShader (string fragCode) { int Result = 0; string InfoLog; GL.ShaderSource(FragmentShaderID, fragCode); GL.CompileShader(FragmentShaderID); GL.GetShader(FragmentShaderID, ShaderParameter.CompileStatus, out Result); InfoLog = GL.GetShaderInfoLog(FragmentShaderID); if(Result == 0) { System.Console.WriteLine(InfoLog); throw new Exception("Fragment shader compilation failed"); } } [/csharp]
[QUOTE=Richy19;37213037]with: GL.GetProgram(shaderID, ProgramParameter.LinkStatus, out Result); Does Result only equal 0 when everything has been done correctly?[/QUOTE] No, that's GL_FALSE. It's set to 1 if there were no errors.
[QUOTE=Tamschi;37213128]You try to create the frame buffer twice. The parameterless constructor of IGame (the I prefix should be reserved for interfaces) is called implicitly and calls the base (GameWindow) constructor. You can remove the empty overrides from IGame if you make the class abstract, this also forces any derived classes to implement these methods.[/QUOTE] Il remove IGame and change the game class to partial class So I can have the same effect(having code that doesnt affect the game directly in one file and game stuff in a nother)
[QUOTE=Richy19;37213143]-code-[/QUOTE] Looks good so far. Nitpicking: You don't have to initialise Result before passing it as out parameter and local variables are usually lowerCamelCase while methods start with upper case. [URL="http://msdn.microsoft.com/en-us/library/ff926074.aspx"]There's an article on MSDN about C# Coding Conventions.[/URL] Something that isn't mentioned there: It's useful to prefix non-public fields with an underscore to distinguish them from local variables. This is suggested by ReSharper, so it's relatively common.
[QUOTE=Tamschi;37213497]Looks good so far. Nitpicking: You don't have to initialise Result before passing it as out parameter and local variables are usually lowerCamelCase while methods start with upper case. [URL="http://msdn.microsoft.com/en-us/library/ff926074.aspx"]There's an article on MSDN about C# Coding Conventions.[/URL] Something that isn't mentioned there: It's useful to prefix non-public fields with an underscore to distinguish them from local variables. This is suggested by ReSharper, so it's relatively common.[/QUOTE] Done :) Now to try and figure out why the fbo crashes it
Do you know about a java library used for image (texture) loading? I have read that the native ones are not good but the only alternative are imagemagick, that is a C wrapper, as far as I know. If anyone know about something else I would like to know. I am gonna use it to develop an andriod application, but the simulator is damn slow on my computer.
[QUOTE=Tamschi;37213497][URL="http://msdn.microsoft.com/en-us/library/ff926074.aspx"]There's an article on MSDN about C# Coding Conventions.[/URL][/QUOTE] The ones that apply to other C-family languages as well (such as classes not having any prefices) seem generally pretty nice. Damn, guess they figured after that whole Sys Hungarian mess they actually better make a set of actually great guidelines.
Can someone walk me through linking glfw with Code::Blocks? I can't figure this out.
My C++ game is starting to get a tangled web of file dependencies and I think my builds are failing just because things aren't being included well. In terms of file: dependencies, I've got [code]tread turret: projectile, tank projectile: tank chassis tank: factory, tread, turret, chassis, projectile factory: tread, turret, chassis main: factory, tank, projectile, turret[/code] In this sort of situation, what file structure makes the build process less painful? Should I forward declare every class that gets included? Should I try to include as few headers as possible and let recursion do the rest?
You should have a header who's sole purpose is to manage including files. Then you should include this header in every cpp file. You can see my example of the globalized header here: [url]https://github.com/naelstrof/Astrostruct/blob/master/src/NEngine.hpp[/url] If you [url=https://github.com/naelstrof/Astrostruct/blob/master/src/NCamera.cpp]look in any cpp file[/url] it'll be included, and not a single hpp file will have an include inside of it. If you have trouble with dependencies you should look into forward declaration.
I'm too tired to think straight, so maybe you can help me with this... let's call it a puzzle. I have an item with a numerical index. I want to generate a string from that number. The string needs to be successive from (number - 1). For example: Let's say the base index is 1. 1 = a ... 26 = z 27 = A ... 52 = Z 53 = aa 54 = ab ... 2808 = ZZ 2809 = aaa 2810 = aab etc. Here's what I have: [url]http://codepad.org/caw0msKb[/url] What I tried was basically converting the number to n-base (where n = 53) and accessing a table of characters with it, but the script still has some problems; there's an extra string after every a-Z sequence. I've tried a few different methods, but all of them have had some annoying problems.
[QUOTE=raBBish;37227041]Some Lua related problem[/QUOTE] Try this: [lua]local a = string.byte 'a' - 1 local A = string.byte 'A' - 1 local chars = {} for i = 1, 26 do chars[i] = string.char( a + i ) end for i = 1, 26 do chars[i + 26] = string.char( A + i ) end local function getstr( num ) local res = {} while num > 0 do res[#res + 1] = chars[(num - 1) % 52 + 1] num = math.floor( num/53 ) end return table.concat( res ):reverse() end for i=1, 3000 do print( getstr( i ) ) end[/lua] The modulo part needed to be adjusted so that it loops between 1 and 53, not 0 and 52. [editline]14th August 2012[/editline] You are probably not concerned with the speed of the code, but it is slightly faster (in LuaJIT at least) if you concatenate the characters to a string in the while loop instead of storing it in a table and concatenating it later. i.e: [lua]res = res .. chars[(num - 1) % 52 + 1][/lua]
Is there a free .NET/C# decompiler that can create projects and is both good and not extremely slow? JustDecompile produces good readable code but it's taking hours for larger files, and ILSpy is almost instant but the code isn't correct.
What's the keyboard shortcut for this menu in Visual Studio? [IMG]https://dl.dropbox.com/u/5013896/forum/Facepunch/Programming/WDYNHW/VSContextShortcut.png[/IMG]
If I have a mirror's normal ({0,0,-1} for example) and model and view matrix, can I find the view matrix for the mirror image? Or is it a bad idea to calculate it like this every frame?
I am clueless when it comes to regex. Is there any way to split by commas and unlimited whitespace but only outside of speech marks " [B]For example:[/B] lol 5, "my name is killerlua, hello!" [B]or something like:[/B] myname 5, ",,,, " [B]With a non-niggly practical example being:[/B] set hello,"Hello my name is KillerLUA, What is yours?",2
Sorry, you need to Log In to post a reply to this thread.