1. Post #2521
    Taught by John Lua
    MakeR's Avatar
    May 2007
    2,914 Posts
    Alright that makes sense now. I'm still not sure what they're for, do they allow you to create multiple instances of something?

    Also, do you know if there are any sites with more examples and exercises?
    Lua is not a class based language and therefore doesn't have instances. Stateless iterators are purely for iterating.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  2. Post #2522
    Gold Member
    LaughingStock's Avatar
    August 2010
    8,078 Posts
    I think I may need to take a few steps backward. Thanks for the help though.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Friendly Friendly x 1 (list)

  3. Post #2523
    muslim obama's Avatar
    February 2012
    16 Posts
    How do I compile and link a .c file using vim in linux, so that I can execute it?
    Reply With Quote Edit / Delete Linux United States Show Events

  4. Post #2524
    Gold Member
    Naelstrom's Avatar
    June 2010
    2,725 Posts
    How do I compile and link a .c file using vim in linux, so that I can execute it?
    Yay a fellow Linux dev!

    Add me on steam if you want direct help and tips, for that particular question you can easily just write a command like
    Code:
    :!gcc -o main main.c test.c blah.c
    but you should really to look into makefiles, it's a more standard way of compiling your projects. Vim has a handy command "make" (or "mak" for short) that runs the local makefile; then lets you zoom to errors or warnings that the compiler produces.

    I have more tips on how to make your life easier! Add me as a friend on steam as posting them all on here would be lengthy.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Useful Useful x 2 (list)

  5. Post #2525
    Gold Member

    August 2012
    30 Posts
    I have a problem with my Visual Studio.
    I recently switched from Visual Basic to C#. When I try to inherit from an other class in C#, I can't see the Methods I can override.
    In Visual Basic I could simply choose a Method of the Base-Class from a Dropdown-Menu I wanted to override.

    Is this possible in Visual C#, too?
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  6. Post #2526
    Gold Member
    robmaister12's Avatar
    January 2008
    4,969 Posts
    I have a problem with my Visual Studio.
    I recently switched from Visual Basic to C#. When I try to inherit from an other class in C#, I can't see the Methods I can override.
    In Visual Basic I could simply choose a Method of the Base-Class from a Dropdown-Menu I wanted to override.

    Is this possible in Visual C#, too?
    Type in "public override " and intellisense brings up a list of methods in the base class that can be overridden (has the "virtual" keyword)
    Reply With Quote Edit / Delete Windows 7 United States Show Events Friendly Friendly x 1 (list)

  7. Post #2527
    Meatpuppet's Avatar
    July 2010
    6,696 Posts
    Do you guys recommend that I further my knowledge of openGL (I've gotten to the end of what's finished of open.gl) or apply and practice my current knowledge until Overv releases the next part?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  8. Post #2528
    open.gl
    Overv's Avatar
    February 2007
    7,431 Posts
    Do you guys recommend that I further my knowledge of openGL (I've gotten to the end of what's finished of open.gl) or apply and practice my current knowledge until Overv releases the next part?
    Guess you just got ninja'd.
    Reply With Quote Edit / Delete Windows 7 Netherlands Show Events Friendly Friendly x 1 (list)

  9. Post #2529
    Meatpuppet's Avatar
    July 2010
    6,696 Posts
    :) thanks a whole lot everyone here for not being a dick to me when I ask questions that seem stupid and especially Overv for making the fantastic tutorial!
    Reply With Quote Edit / Delete Windows 7 United States Show Events Friendly Friendly x 1 (list)

  10. Post #2530
    Gold Member
    Themage's Avatar
    September 2007
    1,910 Posts
    Edit:I literally figured out the problem as soon as I posted this.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Winner Winner x 3 (list)

  11. Post #2531
    Certified Catgirl Maid
    slayer20's Avatar
    January 2006
    9,562 Posts
    Ok so I made this little random dice roller. You enter in a high number (such as 20), and it will pick a number from 1 to 20. I even set it up so that it tells you if you roll a critical or not. Anyway, I want to ask about entering in things that aren't numbers. If I enter in a letter or symbol, the program goes haywire and starts spewing stuff out.

    How do I prevent people from entering in things they shouldn't?

    Also it's in C++

    Code:
    #include <iostream>
    #include <cstdlib>
    #include <time.h>
    using namespace std;
    
    int dice_rnd(int low, int high) {
        return (rand() % high + 1);
    }
    
    int main()
    {
        srand ( time(NULL) );
        int dice_low, dice_high, dice_outcome;
        dice_low = 0;
        while(true)
        {
            cout << "Roll: ";
            cin >> dice_high;
    
            dice_outcome = dice_rnd(dice_low, dice_high);
            if (dice_outcome == dice_high)
            {
                cout << dice_outcome << " CRITIAL!\n";
            }
            if (dice_outcome == 1)
            {
                cout << dice_outcome << " CRITIAL FAIL!\n";
            }
            else
            {
                cout << dice_outcome << "\n";
            }
        }
        return 0;
    }
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  12. Post #2532
    Gold Member
    Naelstrom's Avatar
    June 2010
    2,725 Posts
    Grab a line and parse it yourself, check to see if the parsing failed so you can slap the user silly.
    Unfortunately I don't know of an easy pure C++ way of doing this; here's an example using sscanf:

    Code:
    std::string Line;
    getline(std::cin,Line);
    float Input;
    int NumberOfParses = sscanf(Line.c_str(),"%f",&Input);
    if (NumberOfParses != 1)
    {
        std::cout << "You twat, that's not a number.\n";
    } else {
        std::cout << "Yay, you inserted a number!\n";
    }
    Reply With Quote Edit / Delete Linux United States Show Events

  13. Post #2533
    Certified Catgirl Maid
    slayer20's Avatar
    January 2006
    9,562 Posts
    Could you maybe put that into simple terms for me? I'm still quite new to C++
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  14. Post #2534
    egomanyak's Avatar
    June 2010
    77 Posts
    Could you maybe put that into simple terms for me? I'm still quite new to C++
    well im an idiot and also dont know c++ and this is probably worst way possible but cant you just put try - catch in dice_rnd function ? you can try rand() % high + 1 and if it fails return something else
    Reply With Quote Edit / Delete Windows 7 Turkey Show Events

  15. Post #2535
    Gold Member
    BackwardSpy's Avatar
    May 2008
    6,540 Posts
    I wrote you a simple example to show you how you could do it:
    #include <iostream>
    
    int main()
    {
    	int num;
    
    	std::cout << "Enter a number: ";
    
    	// When you use cin to pipe a value into a variable, it can return true or false.
    	// In this case, if we try to put a non-number value into 'num', it will return
    	// a value of false, so the while loop will execute its block of code
    	while(!(std::cin >> num))
    	{
    		std::cout << "That isn't a number!" << std::endl;
    
    		// These two lines discard whatever might be left over in std::cin
    		std::cin.clear();
    		std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    
    		std::cout << "Enter a number: ";
    	}
    
    	// If we ever break out of the while loop, it's because the user entered a number
    	std::cout << "The number you entered was: " << num << std::endl;
    
    	return 0;
    }
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Useful Useful x 1 (list)

  16. Post #2536
    sim642's Avatar
    July 2010
    1,039 Posts
    I wrote you a simple example to show you how you could do it:
    #include <iostream>
    
    int main()
    {
    	int num;
    
    	std::cout << "Enter a number: ";
    
    	// When you use cin to pipe a value into a variable, it can return true or false.
    	// In this case, if we try to put a non-number value into 'num', it will return
    	// a value of false, so the while loop will execute its block of code
    	while(!(std::cin >> num))
    	{
    		std::cout << "That isn't a number!" << std::endl;
    
    		// These two lines discard whatever might be left over in std::cin
    		std::cin.clear();
    		std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    
    		std::cout << "Enter a number: ";
    	}
    
    	// If we ever break out of the while loop, it's because the user entered a number
    	std::cout << "The number you entered was: " << num << std::endl;
    
    	return 0;
    }
    Yours handles most of the cases, but not all. When user inputs "123asd" then your code would happily get 123 as number and leave the "asd" part hanging in input buffer that would get read the next time you ask for some input.

    I once wrote a custom input function for this purpose, which also checks if all input got parsed properly to the end:
    #include <iostream>
    #include <limits>
    
    using namespace std;
    
    template<typename T>
    bool valid_input(istream &stream, T &value)
    {
        bool good = true;
    
        stream >> value;
    
        if (!stream || stream.peek() != '\n') // checks if value was parsed correctly and all input was parsed too
        {
            good = false;
        }
    
        if (!good) // stream gets reset if parsing went bad
        {
            stream.clear();
            stream.ignore(numeric_limits<streamsize>::max(), '\n');
        }
    
        return good;
    }
    
    int main()
    {
        int n;
    
        while (cout << "Enter a number: ", !valid_input(cin, n)) // nifty way to use this function together with input prompt
        {
            cout << "Not a number!" << endl;
        }
    
        cout << "Your number was " << n << endl;
        return 0;
    }
    
    Reply With Quote Edit / Delete Windows Vista Estonia Show Events

  17. Post #2537
    Gold Member
    BackwardSpy's Avatar
    May 2008
    6,540 Posts
    Yours handles most of the cases, but not all. When user inputs "123asd" then your code would happily get 123 as number and leave the "asd" part hanging in input buffer that would get read the next time you ask for some input.

    I once wrote a custom input function for this purpose, which also checks if all input got parsed properly to the end:
    <code snorp>
    Very true, thanks for pointing that out.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  18. Post #2538
    Richy19's Avatar
    May 2010
    5,401 Posts
    As part of my wanting to expand my C# knowledge im diving into OGL with OpenTK, I have attempted to re-write some of my utility classes in C# but my FBO class gives me this error, I remember OGL giving an error in C++ when I tried to create an FBO but it would never crash.
    This is the error:
    Code:
    mono ./OpenTKGaem.exe
    
    Unhandled Exception: OpenTK.Graphics.GraphicsErrorException: InvalidOperation
      at OpenTK.Graphics.OpenGL.ErrorHelper.CheckErrors () [0x00000] in <filename unknown>:0 
      at OpenTK.Graphics.OpenGL.ErrorHelper.Dispose () [0x00000] in <filename unknown>:0 
      at OpenTK.Graphics.OpenGL.GL.FramebufferRenderbuffer (FramebufferTarget target, FramebufferAttachment attachment, RenderbufferTarget renderbuffertarget, UInt32 renderbuffer) [0x00000] in <filename unknown>:0 
      at OpenTKGaem.GLUtilities.FBO.Create (Int32 w, Int32 h) [0x00000] in <filename unknown>:0 
      at OpenTKGaem.Game.OnLoad (System.EventArgs e) [0x00000] in <filename unknown>:0 
      at OpenTK.GameWindow.OnLoadInternal (System.EventArgs e) [0x00000] in <filename unknown>:0 
      at OpenTK.GameWindow.Run (Double updates_per_second, Double frames_per_second) [0x00000] in <filename unknown>:0 
      at OpenTK.GameWindow.Run (Double updateRate) [0x00000] in <filename unknown>:0 
      at OpenTKGaem.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0 
    [ERROR] FATAL UNHANDLED EXCEPTION: OpenTK.Graphics.GraphicsErrorException: InvalidOperation
      at OpenTK.Graphics.OpenGL.ErrorHelper.CheckErrors () [0x00000] in <filename unknown>:0 
      at OpenTK.Graphics.OpenGL.ErrorHelper.Dispose () [0x00000] in <filename unknown>:0 
      at OpenTK.Graphics.OpenGL.GL.FramebufferRenderbuffer (FramebufferTarget target, FramebufferAttachment attachment, RenderbufferTarget renderbuffertarget, UInt32 renderbuffer) [0x00000] in <filename unknown>:0 
      at OpenTKGaem.GLUtilities.FBO.Create (Int32 w, Int32 h) [0x00000] in <filename unknown>:0 
      at OpenTKGaem.Game.OnLoad (System.EventArgs e) [0x00000] in <filename unknown>:0 
      at OpenTK.GameWindow.OnLoadInternal (System.EventArgs e) [0x00000] in <filename unknown>:0 
      at OpenTK.GameWindow.Run (Double updates_per_second, Double frames_per_second) [0x00000] in <filename unknown>:0 
      at OpenTK.GameWindow.Run (Double updateRate) [0x00000] in <filename unknown>:0 
      at OpenTKGaem.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
    And while im at it if anyone can tell me if there is anything I could improve with this code:
    using System;
    
    using OpenTK;
    using OpenTK.Graphics.OpenGL;
    
    namespace OpenTKGaem.GLUtilities
    {
    	public class FBO
    	{
    		uint fbo;
        	uint depthBuff;
        	uint texture;
    		
    		public FBO ()
    		{
    			GL.GenRenderbuffers(1, out depthBuff);
        		GL.GenTextures(1, out texture);
        		GL.GenFramebuffers(1, out fbo);
    		}
    		
    		~FBO ()
    		{
    			GL.DeleteTextures( 1, ref texture );
        		GL.DeleteRenderbuffers(1, ref depthBuff);
        		GL.DeleteFramebuffers( 1, ref fbo );
    		}
    		
    		public bool Create(int w, int h)
    		{
    			GL.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, depthBuff);
        		GL.RenderbufferStorage(RenderbufferTarget.RenderbufferExt,RenderbufferStorage.DepthComponent16, 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);
            		return false;
        		}
        		GL.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, 0);
    			GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
        		return true;
    		}
    		
    		public void SetActive(bool setActive = true)
    		{
    			if(setActive)
    		        GL.BindFramebuffer(FramebufferTarget.FramebufferExt, fbo);
    		    else
    		        GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
    		}
    
        	public uint GetTexture()
    		{
    			return texture;
    		}
    		
        	public void Clear(float r = 0.0f, float g = 0.0f, float b = 0.0f, float a = 1.0f)
    		{
    			this.SetActive(true);
        		GL.ClearColor(r, g, b, a);
        		GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
    		}
    	}
    }
    
    

    Oh btw in C++ I would use null as te last argument of TexImage2d but C# doesnt let me do this so I used IntPtr.Zero

    GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, w, h, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  19. Post #2539
    Tamschi's Avatar
    December 2009
    3,435 Posts
    You can't call GL functions from the destructor, it's executed on a different thread. No idea what causes this error though.

    Edited:

    Maybe there's more info in the Exception object, I think OpenTK includes the error message somewhere.
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  20. Post #2540
    Richy19's Avatar
    May 2010
    5,401 Posts
    Ahh shit, how could I do the automatic deleting of OpenGL Resources?
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  21. Post #2541
    Meatpuppet's Avatar
    July 2010
    6,696 Posts
    Ahh shit, how could I do the automatic deleting of OpenGL Resources?
    glDelete?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  22. Post #2542
    Richy19's Avatar
    May 2010
    5,401 Posts
    glDelete?
    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.
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  23. Post #2543
    Tamschi's Avatar
    December 2009
    3,435 Posts
    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.
    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.

    ~Texture()
        {
            RenderingMethodQueue.Enqueue(() =>
            {
                GL.DeleteTexture(_textureId);
    
                Trace.TraceDeleteTexture(_name);
            });
        }
    
    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.
    Reply With Quote Edit / Delete Windows 7 Germany Show Events Agree Agree x 1 (list)

  24. Post #2544
    Meatpuppet's Avatar
    July 2010
    6,696 Posts
    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.
    You could (maybe) make a list with glNewList() and put all your resources in there, then clear resources with glDeleteLists()
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  25. Post #2545
    Gold Member
    robmaister12's Avatar
    January 2008
    4,969 Posts
    Ahh shit, how could I do the automatic deleting of OpenGL Resources?
    The way I do it is that I make all OpenGL "objects" (anything that needs to glGen* and glDelete*) implement IDisposable (make sure to implement it correctly), 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.

    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
    	}
    }
    
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  26. Post #2546
    Richy19's Avatar
    May 2010
    5,401 Posts
    The way I do it is that I make all OpenGL "objects" (anything that needs to glGen* and glDelete*) implement IDisposable (make sure to implement it correctly), 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.

    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
    	}
    }
    
    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?

    Edited:

    This is how i have it now
    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");
    			}
    		}
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  27. Post #2547
    Tamschi's Avatar
    December 2009
    3,435 Posts
    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?
    Usually it's used with the using statement. 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.)
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  28. Post #2548
    Richy19's Avatar
    May 2010
    5,401 Posts
    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:
    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;
    }

    to
    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;
    		}
    

    but how do I do all the error checking that is done in the C++ version

    Edited:

    Anyone mind having a look and tell me what/if I can improve? oh and if it works with the fbo on your computer
    http://dl.dropbox.com/u/18453712/OpenTKGaem.zip
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  29. Post #2549
    Gold Member
    WTF Nuke's Avatar
    March 2009
    4,467 Posts
    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?
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  30. Post #2550
    Tamschi's Avatar
    December 2009
    3,435 Posts
    GL.GetProgramInfoLog(int program) returns the info log as string.

    if(Result = true) return true;
    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.
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  31. Post #2551
    Richy19's Avatar
    May 2010
    5,401 Posts
    with:
    GL.GetProgram(shaderID, ProgramParameter.LinkStatus, out Result);
    Does Result only equal 0 when everything has been done correctly?
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  32. Post #2552
    Tamschi's Avatar
    December 2009
    3,435 Posts
    Anyone mind having a look and tell me what/if I can improve? oh and if it works with the fbo on your computer
    http://dl.dropbox.com/u/18453712/OpenTKGaem.zip
    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.
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  33. Post #2553
    Richy19's Avatar
    May 2010
    5,401 Posts
    GL.GetProgramInfoLog(int program) returns the info log as string.

    if(Result = true) return true;
    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.
    Changed it to:
    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");
    			}
    		}
    
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  34. Post #2554
    Tamschi's Avatar
    December 2009
    3,435 Posts
    with:
    GL.GetProgram(shaderID, ProgramParameter.LinkStatus, out Result);
    Does Result only equal 0 when everything has been done correctly?
    No, that's GL_FALSE. It's set to 1 if there were no errors.
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  35. Post #2555
    Richy19's Avatar
    May 2010
    5,401 Posts
    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.
    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)
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  36. Post #2556
    Tamschi's Avatar
    December 2009
    3,435 Posts
    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.

    There's an article on MSDN about C# Coding Conventions.

    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.
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  37. Post #2557
    Richy19's Avatar
    May 2010
    5,401 Posts
    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.

    There's an article on MSDN about C# Coding Conventions.

    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.
    Done :)
    Now to try and figure out why the fbo crashes it
    Reply With Quote Edit / Delete Linux United Kingdom Show Events

  38. Post #2558
    AlienCat's Avatar
    October 2011
    508 Posts
    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.
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  39. Post #2559
    Gold Member
    esalaka's Avatar
    July 2007
    10,201 Posts
    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.
    Reply With Quote Edit / Delete Windows 7 Finland Show Events

  40. Post #2560
    Meatpuppet's Avatar
    July 2010
    6,696 Posts
    Can someone walk me through linking glfw with Code::Blocks? I can't figure this out.
    Reply With Quote Edit / Delete Windows 7 United States Show Events