[QUOTE=Wyzard;37165153]Take a look at [url=https://en.wikipedia.org/wiki/Hashlife]hashlife[/url].[/QUOTE]
[QUOTE=ThePuska;37165297]Cellular automata are [url=https://en.wikipedia.org/wiki/Embarrassingly_parallel]embarrassingly parallel[/url].[/QUOTE]
[QUOTE=esalaka;37165458]Basically you could run a thread for every cell and give it the previous states of the cell in question and its neighbours[/QUOTE]
Thx everyone I will look at them after I wake up(sleep?) I will probably be around if I fail once again.
Do note that actually creating a thread for each cell is not necessarily that smart.
[QUOTE=MakeR;37165584]No, C does not support default arguments. There are some work arounds to achieve a similar effect involving variadic arguments and variadic macros. See [url=http://stackoverflow.com/questions/1472138/c-default-arguments]here[/url].[/QUOTE]
Varargs...yehmmm. I'll try, but would be excellent if C support default arguments. Thanks
[QUOTE=Cesar Augusto;37165856]Varargs...yehmmm. I'll try, but would be excellent if C support default arguments. Thanks[/QUOTE]
That's where C++ comes in, why aren't you using it if you desire its features?
[QUOTE=Naelstrom;37166619]That's where C++ comes in, why aren't you using it if you desire its features?[/QUOTE]
Generally if someone's using C I'd presume there's a good reason for it.
[QUOTE=sim642;37162146]Add -static-libgcc to linker options.[/QUOTE]
It still doesn't work :( I put that in "other linker options".
[editline]10th August 2012[/editline]
The error still comes up, I mean, when I run it from the .exe.
It still comes with a black screen if I compile it from code blocks.
[QUOTE=Naelstrom;37166619]That's where C++ comes in, why aren't you using it if you desire its features?[/QUOTE]
[QUOTE=esalaka;37166848]Generally if someone's using C I'd presume there's a good reason for it.[/QUOTE]
I really like C. C is a powerful language (of course C++ is more due the inumerous libraries) but C is often used to fast applications (daily applications) and that's why I use C for time being. I also use C to training my programming skills.
Note: I also program in C++.
Ok I got the black screen fixed; I had to put the picture in the main folder.
[editline]10th August 2012[/editline]
I'll get to the other error when I need to.
[editline]10th August 2012[/editline]
Ok, here's a question. Can anyone help me with the usage of sin in c++? Throughout the open.gl tutorial, the function has been used to animate. I really don't understand how it works. Can someone teach me?
[QUOTE=Cesar Augusto;37167939]I really like C. C is a powerful language (of course C++ is more due the inumerous libraries) but C is often used to fast applications (daily applications) and that's why I use C for time being. I also use C to training my programming skills.
Note: I also program in C++.[/QUOTE]
I just feel like C++ has no significant downsides while holding numerous significant improvements over C; making it the obvious choice for general programming, but you can code in whatever you want. I just think it's strange.
[editline]10th August 2012[/editline]
[QUOTE=Meatpuppet;37167997]Ok I got the black screen fixed; I had to put the picture in the main folder.
[editline]10th August 2012[/editline]
I'll get to the other error when I need to.
[editline]10th August 2012[/editline]
Ok, here's a question. Can anyone help me with the usage of sin in c++? Throughout the open.gl tutorial, the function has been used to animate. I really don't understand how it works. Can someone teach me?[/QUOTE]
Sure, add me on steam.
I need help understanding this. I think I get the basic concept, but it's really confusing for me.
[url]http://www.lua.org/pil/7.3.html[/url]
[QUOTE=LaughingStock;37182622]I need help understanding this. I think I get the basic concept, but it's really confusing for me.
[url]http://www.lua.org/pil/7.3.html[/url][/QUOTE]
You need to be more specific about which parts you don't understand, but I will try to explain it in a way that might (or might not!) make it clearer to you.
A stateless iterator is a function that, when called with an invariant state and a control variable, returns the next element in the iteration sequence (e.g. next character in a string, or next element in a table).
The invariant state, as it's name suggests, is a variable that will be passed to every call of the iterator function in the iteration; in ipairs, for example, the invariant state is the table that is being iterated over.
The control variable is the variable that will change over the iteration and should be used to get the next element in the sequence; in ipairs the control variable is the current index in the table and is increased by one in each call to the iterator function.
The iteration ends when the stateless iterator returns nil.
The syntax for the for in loop is:
[lua]for a1, a2, ... in iter_function, invariant_state, initial_control_value do
end[/lua]
The ipairs and pairs functions return these values. Pairs is equivalent to (the nil can be omitted):
[lua]for k, v in next, t, nil do -- for k, v in pairs(t) do
end[/lua]
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?
[QUOTE=LaughingStock;37183100]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?[/QUOTE]
Lua is not a class based language and therefore doesn't have instances. Stateless iterators are purely for iterating.
I think I may need to take a few steps backward. Thanks for the help though.
How do I compile and link a .c file using vim in linux, so that I can execute it?
[QUOTE=muslim obama;37188776]How do I compile and link a .c file using vim in linux, so that I can execute it?[/QUOTE]
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[/code]
but you should really to look into [url=http://mrbook.org/tutorials/make/]makefiles[/url], 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.
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?
[QUOTE=monky2k6;37189304]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?[/QUOTE]
Type in "public override " and intellisense brings up a list of methods in the base class that can be overridden (has the "virtual" keyword)
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?
[QUOTE=Meatpuppet;37190223]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?[/QUOTE]
Guess you just got ninja'd.
:) 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!
[B]Edit:[/B]I literally figured out the problem as soon as I posted this.
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;
}
[/CODE]
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";
}[/code]
Could you maybe put that into simple terms for me? I'm still quite new to C++ :v:
[QUOTE=slayer20;37193234]Could you maybe put that into simple terms for me? I'm still quite new to C++ :v:[/QUOTE]
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
I wrote you a simple example to show you how you could do it:
[cpp]#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;
}[/cpp]
[QUOTE=Chris220;37194919]I wrote you a simple example to show you how you could do it:
[cpp]#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;
}[/cpp][/QUOTE]
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:
[cpp]#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;
}
[/cpp]
[QUOTE=sim642;37195052]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>[/QUOTE]
Very true, thanks for pointing that out.
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[/code]
And while im at it if anyone can tell me if there is anything I could improve with this code:
[csharp]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);
}
}
}
[/csharp]
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);
Sorry, you need to Log In to post a reply to this thread.