• What do you need help with? Version 5
    5,752 replies, posted
I'm making a dictionary library for C and I got a problem: theres no compile error, he executes normal. If you see in the picture, the first key will return with the value, but the 2nd, 3rd, 4th.... does not return as I want. And also, when I want to destroy the dictionary (struct), he does not show that the dictionary is empty (as you can see in "Is disct empty"). Maybe the problem is with memory allocation for string, I dunno. Look the second return value, I wanted to return the value of pineaple wich is 2.5 (return double). [img]http://img269.imageshack.us/img269/9141/ajudaj.jpg[/img] Here's my code: [code] typedef struct dictionary { char *key; double value; struct dictionary *next; } DICTIONARY; typedef DICTIONARY* DICT; /* Pointer for struct DICTIONARY */ void dictInit(DICT *elem) /* Initialize the Dictionary */ { *elem = NULL; } void destroyDict(DICT *elem) /* Destroy all elements from dictionary */ { DICTIONARY *temp = *elem; if (*elem == NULL); return; /* No elements */ *elem = (*elem)->next; free(temp); destroyDict(&(*elem)->next); } void insertElement(DICT *elem, char *keyInput, double valueInput) /* Insert a new element to the dictionary */ { if (*elem == NULL) { *elem = (DICT) malloc(sizeof(DICTIONARY)); if (*elem == NULL) { fprintf(stderr, "Error: could not insert allocate a new element to dictionary"); return; } (*elem)->key = (char *) malloc(strlen(keyInput)+1); strcpy((*elem)->key, keyInput); (*elem)->value = valueInput; (*elem)->next = NULL; } else insertElement(&(*elem)->next, keyInput, valueInput); } void showDict(DICT elem) /* Show the elements of dictionary one by one */ { if (elem == NULL) return; /* No elements */ printf("\"%s\": %.4f\n", elem->key, elem->value); showDict(elem->next); /* Show the next dictionary element */ } double showKeyVal(DICT elem, char *keyInput) /* Show the value from the specific key */ { if (elem == NULL) return; /* No elements */ if (strcmp(elem->key, keyInput) == 0) return elem->value; showKeyVal(elem->next, keyInput); } int isDictEmpty(DICT elem) { return (elem == NULL); } [/code]
[QUOTE=KillerLUA;37233567]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[/QUOTE] I'm no regex master but something like [code](".*?"(,|$))|(.*?(,|$))[/code] should work (iterating left to right and not matching overlapping substrings, however you tell that to your regex library). Though you need to manually trim() away the surrounding whitespace and the trailing comma I wouldn't use regex for this. It's simple enough to iterate through the string yourself.
[QUOTE=Meatpuppet;37217677]Can someone walk me through linking glfw with Code::Blocks? I can't figure this out.[/QUOTE] Repost for new page. Anyone?
I need help clearing the depth buffer in OpenTK. Here's what I have: [URL="http://pastebin.com/WLrFqGZ3"]http://pastebin.com/WLrFqGZ3[/URL] The stencil is set somewhere else. I tried different values for position and fragment depth, but I can only get it to either ignore everything or have it render the colour without writing a new depth value.
[QUOTE=Tamschi;37233390]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?[/QUOTE] Yeah, I suggest you calculate it in beforehand.
[QUOTE=Tamschi;37235778]I need help clearing the depth buffer in OpenTK. Here's what I have: [URL="http://pastebin.com/WLrFqGZ3"]http://pastebin.com/WLrFqGZ3[/URL] The stencil is set somewhere else. I tried different values for position and fragment depth, but I can only get it to either ignore everything or have it render the colour without writing a new depth value.[/QUOTE] Where is your clear call?
[QUOTE=Overv;37236502]Where is your clear call?[/QUOTE] Nowhere. I don't want to clear the whole buffer, only the stencilled area. [editline]14th August 2012[/editline] Is it possibly to temporarily switch the depth buffer but keep the colour and stencil buffer the same?
[QUOTE=Meatpuppet;37234359]Repost for new page. Anyone?[/QUOTE] Tried this? [url]http://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/[/url]
[QUOTE=Tamschi;37237273]Nowhere. I don't want to clear the whole buffer, only the stencilled area. [editline]14th August 2012[/editline] Is it possibly to temporarily switch the depth buffer but keep the colour and stencil buffer the same?[/QUOTE] It's definately possible to clear only the depth of a stencilled area, I've done this previously using a shader identical to the one you have in the pasted code. As I also had a similar configuration: depth write enabled, depth test disabled & color write disabled; all I can suggest is checking your stencil func and stencil op arguments when clearing the depth. As for swapping the depth buffer you can do this by copying the contents of the depth buffer to a second framebuffer buffer and back, or by switching framebuffer attachments.
[QUOTE=AlienCat;37238391]Tried this? [url]http://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/[/url][/QUOTE] That doesn't explain how to link glfw with code blocks.
[QUOTE=bean_xp;37240282]It's definately possible to clear only the depth of a stencilled area, I've done this previously using a shader identical to the one you have in the pasted code. As I also had a similar configuration: depth write enabled, depth test disabled & color write disabled; all I can suggest is checking your stencil func and stencil op arguments when clearing the depth. As for swapping the depth buffer you can do this by copying the contents of the depth buffer to a second framebuffer buffer and back, or by switching framebuffer attachments.[/QUOTE] It's working now, I had to leave depth testing enabled and instead set DepthFunc to Always.
Working on my ever lasting OpenTK problems. Next i im making a general purpose VBO class [csharp] using System; using OpenTK; using OpenTK.Graphics.OpenGL; using OpenTKGaem; namespace OpenTKGaem.GLUtilities { public class VBO : IDisposable { bool _disposed; int _bufferID = 0; BufferTarget _target; int _attributeIndex = 0; public VBO () { _disposed = false; GL.GenBuffers(1, out _bufferID); } public void Dispose () { Dispose (true); //GC.SuppressFinalize(this); } ~VBO () { Dispose (false); } protected virtual void Dispose (bool disposing) { if (!_disposed) { if (disposing) { GL.DeleteBuffers(1, ref _bufferID); _bufferID = 0; } _disposed = true; if(_bufferID != 0) throw new Exception("Failed to delete buffer"); } } void AddData( , BufferTarget target = BufferTarget.ArrayBuffer, BufferUsageHint usageHint = BufferUsageHint.StaticDraw ) { _target = target; GL.BindBuffer( _target, _bufferID); //GL.BufferData( _target, , , usageHint); } void SetAttribIndex(int attribIndex) { _attributeIndex = attribIndex; } void Bind( int size, VertexAttribPointerType type = VertexAttribPointerType.Float, bool normalized = false, int stride = 0 ) { GL.EnableVertexAttribArray(_attributeIndex); GL.BindBuffer(_target, _bufferID); GL.VertexAttribPointer(_attributeIndex, size, type, normalized, stride, IntPtr.Zero); } void Unbind() { GL.DisableVertexAttribArray(_attributeIndex); } } } [/csharp] Im stuck on how I could do this part: [csharp] void AddData( , BufferTarget target = BufferTarget.ArrayBuffer, BufferUsageHint usageHint = BufferUsageHint.StaticDraw ) { _target = target; GL.BindBuffer( _target, _bufferID); //GL.BufferData( _target, , , usageHint); }[/csharp] Ie how to pass in an array of some unknown type of variable (int, float, vector2, vector3...) I tried generics with: [csharp] void AddData(T []data,int dataSize, BufferTarget target = BufferTarget.ArrayBuffer, BufferUsageHint usageHint = BufferUsageHint.StaticDraw ) { _target = target; GL.BindBuffer( _target, _bufferID); GL.BufferData( _target, (IntPtr)dataSize, data , usageHint); }[/csharp] But I get: [quote]VAO.cs(20,20): Error CS1502: The best overloaded method match for `OpenTK.Graphics.OpenGL.GL.BufferData(OpenTK.Graphics.OpenGL.BufferTarget, System.IntPtr, System.IntPtr, OpenTK.Graphics.OpenGL.BufferUsageHint)' has some invalid arguments (CS1502) (OpenTKGaem) VAO.cs(20,20): Error CS1503: Argument `#3' cannot convert `T[]' expression to type `System.IntPtr' (CS1503) (OpenTKGaem)[/quote]
[QUOTE=Naelstrom;37226056]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.[/QUOTE] That is a hell of a lot simpler. Thanks! I feel like my C++ book never mentioned anything like this...
[QUOTE=Naelstrom;37226056]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.[/QUOTE] I prefer hierarchical headers because when you do your method if you change one thing in that header you have to recompile the entire project instead of just a few files.
[QUOTE=ECrownofFire;37243727]I prefer hierarchical headers because when you do your method if you change one thing in that header you have to recompile the entire project instead of just a few files.[/QUOTE] I agree that that is a good system when your project can be described as a hierarchy. For projects organized in more of a tangled clusterfuck (where small changes are going to affect lots of files anyway), I think the monolithic approach is nice.
[QUOTE=Richy19;37243035][...][csharp]throw new Exception("Failed to delete buffer");[/csharp][...][/QUOTE] This exception is silently caught on the GC thread. If you want it to alert you if you forget to dispose the instance you have to use either logging or throw on a different thread.
[QUOTE=Meatpuppet;37241940]That doesn't explain how to link glfw with code blocks.[/QUOTE] Basically, the principle should be the same. When you download glfw you will (hopefully, I do not know) get a folder with include header files and one with libraries (assuming that there are a binary package for glfw and that you downloaded that and not just source code). Then you just put your glfw folder somewhere, say C:\glfw, and then you do like step 3 in [url]http://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/[/url]. You tell Code::Blocks about header files that are probably in C:\glfw\include or something and then you do like step 4 and paste in the path to all lib files you found in C:\glfw\lib or whatever it is called. Note that I have never linked glfw before and that was long time since I used Code::Blocks. Oh I found this also: [url]http://wiki.codeblocks.org/index.php?title=Using_GLFW_with_Code::Blocks[/url] That is a bit different method than I described.
[QUOTE=MakeR;37228039]Try this: -snip The modulo part needed to be adjusted so that it loops between 1 and 53, not 0 and 52.[/QUOTE] Almost, but not quite. Look at the parts where double characters switch (like aZ -> ba) [code]aZ aa bb bc ... bZ ba bb cc cd ... cZ ca cb cc dd de[/code] I'm not tired anymore but I still can't figure it out for some reason [img]http://www.facepunch.com/fp/emoot/smith.gif[/img]
Here you go: [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 - 1)/52 ) end return table.concat( res ):reverse() end for i=1, 3000 do print( i, getstr( i ) ) end[/lua]
Hi everyone. I'm getting into C# so I made a little Tic Tac Toe console game that isn't anything special at all but it works. There is no AI, it just picks a random space. Anyway, I'm just wondering if there is any better ways to do anything here. [CODE]using System; class MainProgram { public static void Main() { bool gameEnd = false; string[] currentSpaces = {"B", "B", "B", "B", "B", "B", "B", "B", "B"}; bool playerTurn = true; string winner = "None"; int playerChoice; int AIChoice; MainProgram mp = new MainProgram(); do { mp.drawCurrentBoard(currentSpaces); if (playerTurn == true) { playerChoice = mp.getPlayerChoice(currentSpaces); currentSpaces[playerChoice] = "X"; playerTurn = false; } else { AIChoice = mp.getAIChoice(currentSpaces); currentSpaces[AIChoice] = "O"; playerTurn = true; } winner = mp.checkForWinner(currentSpaces); if (winner != "None") { Console.WriteLine("{0} wins!", winner); gameEnd = true; } } while (gameEnd == false); } void drawCurrentBoard(string[] spaces) { Console.WriteLine("{0}{1}{2}", spaces[0], spaces[1], spaces[2]); Console.WriteLine("{0}{1}{2}", spaces[3], spaces[4], spaces[5]); Console.WriteLine("{0}{1}{2}", spaces[6], spaces[7], spaces[8]); } int getPlayerChoice(string[] spaces) { int choice; do { Console.WriteLine("Which space do you choose: "); choice = Int32.Parse(Console.ReadLine()); } while (spaces[choice] == "X" || spaces[choice] == "O"); return choice; } int getAIChoice(string[] spaces) { Random rand = new Random(); int choice = rand.Next(10); do { choice = rand.Next(10); } while (spaces[choice] == "X" || spaces[choice] == "O"); return choice; } string checkForWinner(string[] spaces) { if (spaces[0] == "X" && spaces[3] == "X" && spaces[6] == "X") return "Player"; else if (spaces[1] == "X" && spaces[4] == "X" && spaces[7] == "X") return "Player"; else if (spaces[2] == "X" && spaces[5] == "X" && spaces[8] == "X") return "Player"; else if (spaces[0] == "X" && spaces[1] == "X" && spaces[2] == "X") return "Player"; else if (spaces[3] == "X" && spaces[4] == "X" && spaces[5] == "X") return "Player"; else if (spaces[6] == "X" && spaces[7] == "X" && spaces[8] == "X") return "Player"; else if (spaces[0] == "X" && spaces[4] == "X" && spaces[8] == "X") return "Player"; else if (spaces[2] == "X" && spaces[4] == "X" && spaces[6] == "X") return "Player"; else if (spaces[0] == "O" && spaces[3] == "O" && spaces[6] == "O") return "AI"; else if (spaces[1] == "O" && spaces[4] == "O" && spaces[7] == "O") return "AI"; else if (spaces[2] == "O" && spaces[5] == "O" && spaces[8] == "O") return "AI"; else if (spaces[0] == "O" && spaces[1] == "O" && spaces[2] == "O") return "AI"; else if (spaces[3] == "O" && spaces[4] == "O" && spaces[5] == "O") return "AI"; else if (spaces[6] == "O" && spaces[7] == "O" && spaces[8] == "O") return "AI"; else if (spaces[0] == "O" && spaces[4] == "O" && spaces[8] == "O") return "AI"; else if (spaces[2] == "O" && spaces[4] == "O" && spaces[6] == "O") return "AI"; else return "None"; } }[/CODE] Sorry for any potential blindness that may occur when you look at my method for checking for winners. Again I'm just asking if theres better ways to do anything in there.
New problem: [csharp] public void Draw(float time, ref Matrix4 modelMatrix, ref Matrix4 viewMatrix, ref Matrix4 projectionMatrix) { //GL.Enable(EnableCap.StencilTest); GL.StencilFunc(StencilFunction.Always, 1, 0xFF); GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Replace); GL.StencilMask(0xFF); GL.Clear(ClearBufferMask.StencilBufferBit); var identityMatrix = Matrix4.Identity; MirrorVisual.Draw(time: time, modelMatrix: ref modelMatrix, viewMatrix: ref viewMatrix, projectionMatrix: ref projectionMatrix); GL.StencilFunc(StencilFunction.Equal, 1, 0xFF); GL.StencilMask(0x00); GL.ColorMask(false, false, false, false); Utils.ClearDepthByStencil(); GL.ColorMask(true, true, true, true); Matrix4 mirrorViewMatrix = new Matrix4(viewMatrix.Row0, viewMatrix.Row1, -viewMatrix.Row2, viewMatrix.Row3); { // Update plane equation // Probably wrong var normal = Vector4.UnitZ; Vector4 temp; Vector4.Transform(ref normal, ref modelMatrix, out temp); Vector4.Transform(ref temp, ref mirrorViewMatrix, out normal); Vector4.Transform(ref normal, ref projectionMatrix, out temp); normal = temp; _planeEquation[0] = normal.X; _planeEquation[1] = normal.Y; _planeEquation[2] = normal.Z; _planeEquation[3] = 0; GL.ClipPlane(ClipPlaneName.ClipPlane0, _planeEquation); } GL.Enable(EnableCap.ClipPlane0); ReflectedVisual.Draw(time: time, modelMatrix: ref identityMatrix, viewMatrix: ref mirrorViewMatrix, projectionMatrix: ref projectionMatrix); GL.Disable(EnableCap.ClipPlane0); // Reset depth buffer to mirror surface GL.ColorMask(false, false, false, false); MirrorVisual.Draw(time: time, modelMatrix: ref modelMatrix, viewMatrix: ref viewMatrix, projectionMatrix: ref projectionMatrix); GL.ColorMask(true, true, true, true); //GL.Disable(EnableCap.StencilTest); }[/csharp] I tried enabling the clip plane before and after setting it. There seems to be no clipping at all, reversing the normal in the plane equation leaves all of ReflectedVisual visible too.
[QUOTE=AlienCat;37247272]Basically, the principle should be the same. When you download glfw you will (hopefully, I do not know) get a folder with include header files and one with libraries (assuming that there are a binary package for glfw and that you downloaded that and not just source code). Then you just put your glfw folder somewhere, say C:\glfw, and then you do like step 3 in [url]http://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/[/url]. You tell Code::Blocks about header files that are probably in C:\glfw\include or something and then you do like step 4 and paste in the path to all lib files you found in C:\glfw\lib or whatever it is called. Note that I have never linked glfw before and that was long time since I used Code::Blocks. Oh I found this also: [url]http://wiki.codeblocks.org/index.php?title=Using_GLFW_with_Code::Blocks[/url] That is a bit different method than I described.[/QUOTE] I've already googled this. I've linked many libraries already. The second tutorial isn't working for me. Can someone who has linked glfw with code blocks please help me?
[QUOTE=Tamschi;37250021]New problem: I tried enabling the clip plane before and after setting it. There seems to be no clipping at all, reversing the normal in the plane equation leaves all of ReflectedVisual visible too.[/QUOTE] Hey again, when I needed stencil reflections I too had this issue with getting the clipping plane to cooperate with shaders. The solution according to the opengl specification is to write to gl_ClipDistance[n] in the vertex shader, however I had a hard time getting this to work correctly on all GPUs. I can't remember the exact details but iirc there were differences between gl_ClipDistance on AMD and nVidia cards. The solution I used was to emulate the behaviour by using the vertex position dotted with the clip plane and discarding negative values in the pixel shader, if necessary I can provide example shader code for that.
[QUOTE=Meatpuppet;37251602]I've already googled this. I've linked many libraries already. The second tutorial isn't working for me. Can someone who has linked glfw with code blocks please help me?[/QUOTE] Alright, have you already built and placed GLFW in the correct folder (include and lib directories)?
[QUOTE=bean_xp;37252095]Hey again, when I needed stencil reflections I too had this issue with getting the clipping plane to cooperate with shaders. The solution according to the opengl specification is to write to gl_ClipDistance[n] in the vertex shader, however I had a hard time getting this to work correctly on all GPUs. I can't remember the exact details but iirc there were differences between gl_ClipDistance on AMD and nVidia cards. The solution I used was to emulate the behaviour by using the vertex position dotted with the clip plane and discarding negative values in the pixel shader, if necessary I can provide example shader code for that.[/QUOTE] Apparently it's possible to use the projection matrix for this. I'll try it and post the code if it works. [editline]:([/editline] ...or not. My computer just broke.
I currently have 2 threads in an android game, a logic and a graphics thread. What would be the best way to push updated from the logic to the graphics thread? I was thinking of the graphics thread having 2 sets of info on each entity, one of the currently rendered state and one of the next state. The logic thread would edit the next state, and then change a bool of whether the next update has been pushed. The graphics thread will check this bool, and then change the current state to the information of the next state. However, I fear that as the game gets more complex, the copying of states or the checking of the bool would become desynced, and the game would look weird (half the states were updated while others weren't, or a new state isn't read because it was refreshed right between the check and the reset of the bool). What would be the way of going about it? I tried synchronized blocks, but it brought the FPS to a crawl (and I am unsure why). [editline]15th August 2012[/editline] How about a shared data class that is synchronized when either one wants to access it? And should graphics and logic be locked in step? I don't see the point of rendering the same scene if nothing has changed, so if I do that then maybe graphics would sleep until interrupted by logic because it pushed an update?
[QUOTE=ECrownofFire;37252332]Alright, have you already built and placed GLFW in the correct folder (include and lib directories)?[/QUOTE] Built?
Is there any reason why this would cause an exception: [csharp]GL.BindRenderbuffer (RenderbufferTarget.RenderbufferExt, _depthBuff); GL.RenderbufferStorage (RenderbufferTarget.RenderbufferExt, RenderbufferStorage.DepthComponent32, w, h); GL.FramebufferRenderbuffer (FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, RenderbufferTarget.RenderbufferExt, _depthBuff); GL.BindTexture (TextureTarget.Texture2D, _texture); GL.TexImage2D (TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, w, h, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero); GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureParameterName.ClampToEdge); GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureParameterName.ClampToEdge); GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.BindTexture (TextureTarget.Texture2D, 0); GL.BindFramebuffer (FramebufferTarget.FramebufferExt, _fbo); GL.FramebufferTexture2D (FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, _texture, 0); GL.FramebufferRenderbuffer (FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, RenderbufferTarget.RenderbufferExt, _depthBuff); FramebufferErrorCode status = GL.CheckFramebufferStatus (FramebufferTarget.FramebufferExt); if (status != FramebufferErrorCode.FramebufferCompleteExt) { System.Console.WriteLine ("Couldn't create frame buffer"); GL.BindFramebuffer (FramebufferTarget.FramebufferExt, 0); ErrorChecking.ThrowErrors (); return false; } GL.BindRenderbuffer (RenderbufferTarget.RenderbufferExt, 0); GL.BindFramebuffer (FramebufferTarget.FramebufferExt, 0); ErrorChecking.ThrowErrors (); return true;[/csharp] these are my available extensions: [code] GL_ARB_multisample is available GL_EXT_abgr is available GL_EXT_bgra is available GL_EXT_blend_color is available GL_EXT_blend_minmax is available GL_EXT_blend_subtract is available GL_EXT_copy_texture is available GL_EXT_polygon_offset is available GL_EXT_subtexture is available GL_EXT_texture_object is available GL_EXT_vertex_array is available GL_EXT_compiled_vertex_array is available GL_EXT_texture is available GL_EXT_texture3D is available GL_IBM_rasterpos_clip is available GL_ARB_point_parameters is available GL_EXT_draw_range_elements is available GL_EXT_packed_pixels is available GL_EXT_point_parameters is available GL_EXT_rescale_normal is available GL_EXT_separate_specular_color is available GL_EXT_texture_edge_clamp is available GL_SGIS_generate_mipmap is available GL_SGIS_texture_border_clamp is available GL_SGIS_texture_edge_clamp is available GL_SGIS_texture_lod is available GL_ARB_framebuffer_sRGB is available GL_ARB_multitexture is available GL_EXT_framebuffer_sRGB is available GL_IBM_multimode_draw_arrays is available GL_IBM_texture_mirrored_repeat is available GL_3DFX_texture_compression_FXT1 is available GL_ARB_texture_cube_map is available GL_ARB_texture_env_add is available GL_ARB_transpose_matrix is available GL_EXT_blend_func_separate is available GL_EXT_fog_coord is available GL_EXT_multi_draw_arrays is available GL_EXT_secondary_color is available GL_EXT_texture_env_add is available GL_EXT_texture_filter_anisotropic is available GL_EXT_texture_lod_bias is available GL_INGR_blend_func_separate is available GL_NV_blend_square is available GL_NV_light_max_exponent is available GL_NV_texgen_reflection is available GL_NV_texture_env_combine4 is available GL_SUN_multi_draw_arrays is available GL_ARB_texture_border_clamp is available GL_ARB_texture_compression is available GL_EXT_framebuffer_object is available GL_EXT_texture_env_combine is available GL_EXT_texture_env_dot3 is available GL_MESA_window_pos is available GL_NV_packed_depth_stencil is available GL_NV_texture_rectangle is available GL_NV_vertex_program is available GL_ARB_depth_texture is available GL_ARB_occlusion_query is available GL_ARB_shadow is available GL_ARB_texture_env_combine is available GL_ARB_texture_env_crossbar is available GL_ARB_texture_env_dot3 is available GL_ARB_texture_mirrored_repeat is available GL_ARB_window_pos is available GL_ATI_envmap_bumpmap is available GL_EXT_stencil_two_side is available GL_EXT_texture_cube_map is available GL_NV_depth_clamp is available GL_NV_vertex_program1_1 is available GL_APPLE_packed_pixels is available GL_APPLE_vertex_array_object is available GL_ARB_draw_buffers is available GL_ARB_fragment_program is available GL_ARB_fragment_shader is available GL_ARB_shader_objects is available GL_ARB_vertex_program is available GL_ARB_vertex_shader is available GL_ATI_draw_buffers is available GL_ATI_texture_env_combine3 is available GL_ATI_texture_float is available GL_EXT_shadow_funcs is available GL_EXT_stencil_wrap is available GL_MESA_pack_invert is available GL_MESA_ycbcr_texture is available GL_ARB_depth_clamp is available GL_ARB_fragment_program_shadow is available GL_ARB_half_float_pixel is available GL_ARB_point_sprite is available GL_ARB_shading_language_100 is available GL_ARB_sync is available GL_ARB_texture_non_power_of_two is available GL_ARB_vertex_buffer_object is available GL_ATI_blend_equation_separate is available GL_EXT_blend_equation_separate is available GL_OES_read_format is available GL_ARB_color_buffer_float is available GL_ARB_pixel_buffer_object is available GL_ARB_texture_compression_rgtc is available GL_ARB_texture_float is available GL_ARB_texture_rectangle is available GL_EXT_packed_float is available GL_EXT_pixel_buffer_object is available GL_EXT_texture_compression_rgtc is available GL_EXT_texture_rectangle is available GL_EXT_texture_sRGB is available GL_EXT_texture_shared_exponent is available GL_ARB_framebuffer_object is available GL_EXT_framebuffer_blit is available GL_EXT_framebuffer_multisample is available GL_EXT_packed_depth_stencil is available GL_APPLE_object_purgeable is available GL_ARB_vertex_array_object is available GL_ATI_separate_stencil is available GL_EXT_draw_buffers2 is available GL_EXT_gpu_program_parameters is available GL_EXT_texture_array is available GL_EXT_texture_integer is available GL_EXT_texture_sRGB_decode is available GL_OES_EGL_image is available GL_MESA_texture_array is available GL_ARB_copy_buffer is available GL_ARB_depth_buffer_float is available GL_ARB_half_float_vertex is available GL_ARB_map_buffer_range is available GL_ARB_texture_rg is available GL_ARB_texture_swizzle is available GL_ARB_vertex_array_bgra is available GL_EXT_separate_shader_objects is available GL_EXT_texture_swizzle is available GL_EXT_vertex_array_bgra is available GL_NV_conditional_render is available GL_ARB_ES2_compatibility is available GL_ARB_draw_elements_base_vertex is available GL_ARB_explicit_attrib_location is available GL_ARB_fragment_coord_conventions is available GL_ARB_provoking_vertex is available GL_ARB_sampler_objects is available GL_ARB_seamless_cube_map is available GL_ARB_shader_texture_lod is available GL_EXT_provoking_vertex is available GL_EXT_texture_snorm is available GL_MESA_texture_signed_rgba is available GL_ARB_robustness is available [/code]
Is there any weird reason why GL.GetUniformLocation would give back an invalid ID? My shader class works by caching all requested attributes and uniforms: [csharp] using System; using System.Collections.Generic; using OpenTK; using OpenTK.Graphics.OpenGL; using OpenTKGaem; namespace OpenTKGaem.GLUtilities { public class Shader : IDisposable { int _vertexShaderID; int _fragmentShaderID; int _shaderID; Dictionary< string, int > _uniformVariableIDList; Dictionary< string, int > _attributeVariableIDList; bool _disposed; public Shader () { _uniformVariableIDList = new Dictionary<string, int> (); _attributeVariableIDList = new Dictionary<string, int> (); _shaderID = GL.CreateProgram(); _vertexShaderID = GL.CreateShader (ShaderType.VertexShader); _fragmentShaderID = GL.CreateShader (ShaderType.FragmentShader); _disposed = false; } public void Dispose () { Dispose (true); //GC.SuppressFinalize(this); } ~Shader () { Dispose (false); } protected virtual void Dispose (bool disposing) { if (!_disposed) { if (disposing) { if (_vertexShaderID != 0) GL.DeleteShader ( _vertexShaderID); if (_fragmentShaderID != 0) GL.DeleteShader ( _fragmentShaderID); if (_shaderID != 0) GL.DeleteProgram ( _shaderID); _shaderID = 0; _fragmentShaderID = 0; _vertexShaderID = 0; } _disposed = true; if (_vertexShaderID != 0) System.Console.WriteLine("VertexShader not disposed properly"); if (_fragmentShaderID != 0) System.Console.WriteLine("FragmentShader not disposed properly"); if (_shaderID != 0) System.Console.WriteLine("Shader not disposed properly"); } } void LinkShader () { int result; 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; 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; 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"); } } public void LoadShaderFiles (string vertFileName, string fragFileName) { string vertexShaderCode = ""; string fragmentShaderCode = ""; bool filesWork = true; try { vertexShaderCode = System.IO.File.ReadAllText(vertFileName); } catch(Exception) { System.Console.WriteLine( "Error opening: " + vertFileName);// + " : " + e.ToString() ); filesWork = false; } try { fragmentShaderCode = System.IO.File.ReadAllText(fragFileName); } catch(Exception ) { System.Console.WriteLine( "Error opening: " + fragFileName);// + " : " + e.ToString()); filesWork=false; } if(filesWork == false) { vertexShaderCode = "#version 120\n" + "uniform mat4 MVP;\n" + "attribute vec4 Position;\n"+ "void main(){\n" + "gl_Position = MVP * Position;\n" + "}"; fragmentShaderCode = "#version 120\n" + "void main(){\n" + "gl_FragColor = vec4(1.0f, 1.0f, 1.0f, 1.0f);\n" + "}"; } LoadShaderCode(vertexShaderCode, fragmentShaderCode); } public void LoadShaderCode (string vertCode, string fragCode) { _attributeVariableIDList.Clear (); _uniformVariableIDList.Clear (); CompileVertexShader (vertCode); CompileFragmentShader (fragCode); LinkShader (); } public int GetShaderID () { return _shaderID; } public void Bind () { GL.UseProgram (_shaderID); } public static void Unbind () { GL.UseProgram (0); } public int GetAttribute (string attName) { if (_attributeVariableIDList.ContainsKey (attName)) { int ret; _attributeVariableIDList.TryGetValue (attName, out ret); return ret; } int attrib = GL.GetAttribLocation (_shaderID, attName); _attributeVariableIDList.Add (attName, attrib); return attrib; } public int GetUniform (string uniName) { if (_uniformVariableIDList.ContainsKey (uniName)) { int ret; _uniformVariableIDList.TryGetValue (uniName, out ret); return ret; } int uniform = GL.GetUniformLocation (_shaderID, uniName); _uniformVariableIDList.Add (uniName, uniform); return uniform; } } } [/csharp] and my skybox is doing: [csharp] using System; using OpenTK; using OpenTK.Graphics.OpenGL; using OpenTKGaem.GLUtilities; using System.Collections.Generic; namespace OpenTKGaem { public class Skybox : IDisposable { protected List<IDisposable> _toDispose = new List<IDisposable>(); Texture skyboxTexture; VBO<Vector3> Positions; VBO<Vector2> UV; Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, 1024/576.0f, 1.0f, 101.0f); Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY); Shader shader; public Skybox () { Positions = new VBO<Vector3>(); UV = new VBO<Vector2>(); shader = new Shader(); skyboxTexture = new Texture(); skyboxTexture.LoadImage("./Resource/skybox.png"); List<Vector3> posList = new List<Vector3>(); posList.Add(new Vector3(-50.0f, 50.0f, 50.0f)); posList.Add(new Vector3(-50.0f,-50.0f, 50.0f)); posList.Add(new Vector3( 50.0f, 50.0f, 50.0f)); posList.Add(new Vector3( 50.0f, 50.0f, 50.0f)); posList.Add(new Vector3(-50.0f,-50.0f, 50.0f)); posList.Add(new Vector3( 50.0f,-50.0f, 50.0f)); posList.Add(new Vector3( 50.0f, 50.0f,-50.0f)); posList.Add(new Vector3( 50.0f,-50.0f,-50.0f)); posList.Add(new Vector3( 50.0f, 50.0f, 50.0f)); posList.Add(new Vector3( 50.0f, 50.0f, 50.0f)); posList.Add(new Vector3( 50.0f,-50.0f,-50.0f)); posList.Add(new Vector3( 50.0f,-50.0f, 50.0f)); posList.Add(new Vector3( 50.0f, 50.0f, 50.0f)); posList.Add(new Vector3( 50.0f,-50.0f, 50.0f)); posList.Add(new Vector3(-50.0f, 50.0f, 50.0f)); posList.Add(new Vector3(-50.0f, 50.0f, 50.0f)); posList.Add(new Vector3( 50.0f,-50.0f, 50.0f)); posList.Add(new Vector3(-50.0f,-50.0f, 50.0f)); posList.Add(new Vector3(-50.0f, 50.0f, 50.0f)); posList.Add(new Vector3(-50.0f,-50.0f, 50.0f)); posList.Add(new Vector3(-50.0f, 50.0f,-50.0f)); posList.Add(new Vector3(-50.0f, 50.0f,-50.0f)); posList.Add(new Vector3(-50.0f,-50.0f, 50.0f)); posList.Add(new Vector3(-50.0f,-50.0f,-50.0f)); posList.Add(new Vector3(-50.0f, 50.0f, 50.0f)); posList.Add(new Vector3(-50.0f, 50.0f,-50.0f)); posList.Add(new Vector3( 50.0f, 50.0f, 50.0f)); posList.Add(new Vector3( 50.0f, 50.0f, 50.0f)); posList.Add(new Vector3(-50.0f, 50.0f,-50.0f)); posList.Add(new Vector3( 50.0f, 50.0f,-50.0f)); posList.Add(new Vector3(-50.0f,-50.0f,-50.0f)); posList.Add(new Vector3(-50.0f,-50.0f, 50.0f)); posList.Add(new Vector3( 50.0f,-50.0f,-50.0f)); posList.Add(new Vector3( 50.0f,-50.0f,-50.0f)); posList.Add(new Vector3(-50.0f,-50.0f, 50.0f)); posList.Add(new Vector3( 50.0f,-50.0f, 50.0f)); Positions.AddData(posList.ToArray(), Vector3.SizeInBytes); List<Vector2> uvList = new List<Vector2>(); for(int i = 0; i < 6; i++){ uvList.Add(new Vector2(0.0f , 0.0f)); uvList.Add(new Vector2(0.0f, 1.0f)); uvList.Add(new Vector2(1.0f, 0.0f)); uvList.Add(new Vector2(1.0f, 0.0f)); uvList.Add(new Vector2(0.0f, 1.0f)); uvList.Add(new Vector2(1.0f, 1.0f)); } UV.AddData(uvList.ToArray(), Vector2.SizeInBytes); shader.LoadShaderCode( "#version 120\n" + "uniform mat4 MVP;\n" + "attribute vec4 Position;\n"+ "attribute vec2 UV;\n"+ "varying vec2 uv;\n"+ "void main(){\n" + "uv = UV;\n"+ "gl_Position = MVP * Position;\n" + "}", "#version 120\n" + "varying vec2 uv;\n"+ "uniform sampler2D TEXTURE0;\n"+ "void main(){\n" + "gl_FragColor = vec4(1.0f, 0.0f, 1.0f, 1.0f);\n" + "}"); Positions.SetAttribIndex(shader.GetAttribute( "Position")); UV.SetAttribIndex(shader.GetAttribute( "UV")); _toDispose.Add(this.Positions); _toDispose.Add(this.shader); _toDispose.Add(this.skyboxTexture); _toDispose.Add(this.UV); } public void Dispose() { for(int i = 0; i < _toDispose.Count; i++) { _toDispose[i].Dispose(); } } public void Draw() { Matrix4 MVP = projection * modelview; GL.UniformMatrix4(shader.GetUniform("MVP"), false, ref MVP); GL.ActiveTexture(TextureUnit.Texture0); skyboxTexture.Bind(); GL.Uniform1(shader.GetUniform("TEXTURE0"), 0); Positions.Bind(3); UV.Bind(2); GL.DrawArrays(BeginMode.Triangles, 0, 36); UV.Unbind(); Positions.Unbind(); Texture.Unbind(); Shader.Unbind(); } } } [/csharp] However MVP is apparently 0, Position = 1, and UV = 0? and GL.UniformMatrix4(shader.GetUniform("MVP"), false, ref MVP); is failing with invalid operation
Hey guys this is my second program, but I really need help, it's a simple OOP program that you initialize with a range of numbers, it internally finds the primes and then you can print them to whatever output stream you like. However I seem to keep getting this error on my use of remove_copy_if function: [code] 1>c:\users\max\documents\visual studio 2010\projects\primesearch\primesearch\primesearch.cpp(23): error C3867: 'PrimeSearch::m_predicate': function call missing argument list; use '&PrimeSearch::m_predicate' to create a pointer to member 1>c:\users\max\documents\visual studio 2010\projects\primesearch\primesearch\primesearch.cpp(23): error C2784: '_OutTy *std::remove_copy_if(_InIt,_InIt,_OutTy (&)[_OutSize],_Pr)' : could not deduce template argument for '_OutTy (&)[_OutSize]' from 'std::_Vector_iterator<_Myvec>' [/code] All I'm trying to do in that line, is remove all the non-prime numbers using my predicate and place them in another vector. [B]PrimeSearch.h:[/B] [code] #include <iostream> #include <vector> class PrimeSearch { public: PrimeSearch (); explicit PrimeSearch (const int arraySize); ~PrimeSearch(); void m_print (std::ostream& stream); private: void m_findPrimes (std::vector<int> vector, std::vector<int> othervector); bool m_predicate (std::vector<int>::iterator i); std::vector<int> p_primes; std::vector<int> p_nonprimes; int sizeTemp; }; [/code] [B]PrimeSearch.cpp:[/B] [code] #include <iostream> #include <fstream> #include <algorithm> #include <vector> #include <Primesearch.h> PrimeSearch::PrimeSearch (const int ArraySize) : sizeTemp(ArraySize) { for(int inc = 0; inc < ArraySize; inc++) { p_primes.push_back (inc); }; m_findPrimes(p_primes, p_nonprimes); }; PrimeSearch::PrimeSearch() : sizeTemp(0){}; void PrimeSearch::m_findPrimes(std::vector<int> vector, std::vector<int> othervector) { std::remove_copy_if (p_primes.begin(), p_primes.end(), p_nonprimes.begin(), m_predicate); }; bool PrimeSearch::m_predicate(std::vector<int>::iterator i) { return (!( *i % 2 == 0 || *i % 3 == 0 || *i % 5 == 0)); }; void PrimeSearch::m_print(std::ostream& out) { std::vector<int>::iterator iter; for(iter = p_primes.begin(); iter < p_primes.end(); iter++) { out << "Prime numbers in range: " << sizeTemp << "\n" << *iter << std::endl; }; for(iter = p_nonprimes.begin(); iter < p_nonprimes.end(); iter++) { out << "Non-Prime numbers in range: " << sizeTemp << "\n" << *iter << std::endl; }; }; [/code] [B]Search.cpp:[/B] [code] #include <iostream> #include <fstream> #include <PrimeSearch.h> int main() { std::ofstream File("Primes.txt"); PrimeSearch p(100); p.m_print(File); File.close(); }; [/code]
Sorry, you need to Log In to post a reply to this thread.