[QUOTE=Noi;41929253]I can't understand where to get started with OpenGL programming.
Hurr, I tried doing something, mixing up glfw, glee, but any try of compiling haven't succeeded.[/QUOTE]
What are your issues? Are you unable to compile GLFW and GLEE? Or is your code not compiling? What are the errors?
I haven't use glee or g++, but are you including the libs?
C#:
What would be the best way to pass the reference of a form from the main program to other methods?
I tried making the variable global, but it errors about "Object reference not set to an instance of an object".
[QUOTE=vexx21322;41934989]C#:
What would be the best way to pass the reference of a form from the main program to other methods?
I tried making the variable global, but it errors about "Object reference not set to an instance of an object".[/QUOTE]
Put the instance in a static field in a class, if you absolutely need it.
If you properly separate UI from logic this shouldn't be necessary though.
[QUOTE=vexx21322;41934989]C#:
What would be the best way to pass the reference of a form from the main program to other methods?
I tried making the variable global, but it errors about "Object reference not set to an instance of an object".[/QUOTE]
Ninja edit: As Tamschi said seconds ago you should make it a static field. If it still errors the same thing, then the stuff below applies:
The error you sent means the reference is null, i.e. you didn't set it at all or the form closed.
When a form closes, it removes itself and gets garbage collected. All references pointing to it get null'd.
You need to use Form.Hide() instead of Form.Close() if you want to keep it alive. Maybe there's some property that prevents it's removal, too.
[QUOTE=Tamschi;41936983]Put the instance in a static field in a class, if you absolutely need it.
If you properly separate UI from logic this shouldn't be necessary though.[/QUOTE]
I mean in the main Program.cs.
[csharp]
static Form1 form;
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
form = new Form1();
Application.Run(form);
}
static void DoSomething()
{
form.doSomethingElse(); // Error: Object reference not set to an instance of an object.
}
[/csharp]
[QUOTE=vexx21322;41937147]I mean in the main Program.cs.
[csharp]
static Form1 form;
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
form = new Form1();
Application.Run(form);
}
static void DoSomething()
{
form.doSomethingElse(); // Error: Object reference not set to an instance of an object.
}
[/csharp][/QUOTE]
Either DoSomething() is called before Main() runs or the Form1 constructor runs DoSomething().
Are you sure you can't move DoSomething into Form1?
[QUOTE=Smashmaster;41928280]Basically, what are the rules for Java precomputation? How extreme can it be?[/QUOTE]
I'm pretty sure Java does none of that. Java can, in a way, never be sure that functions have no side-effects (except static analysis, though I'm not sure if you can somehow, without non-standard hackary, modify code or or hook into calls).
You could also switch out the standard library for something that upon Math.sin() does something else, or perhaps just with a different precision.
[QUOTE=Lemmingz95;41930320]Thank you for the replies, ill be sure to post progress. Yes I was thinking of variadic delegates, to sort of 'cover all bases' but ill leave it to the user to add their own.
And to tamschi, I do have global game time, but im looking into ways to shedule things on the fly, eg. when you click x, in two seconds call functions; x, y and z. repeat y and z every 2 seconds 5 times.
I could be missing something obvious, but i cant think of an easy way to do that with one game timer.
still, both helpful and i'm very thankful![/QUOTE]
You could do something like C++, where you pass a void* for user-data. In C# you can use Object for that.
You can let the user supply an Object with fields for relevant data, so when this parameter gets supplied in the callback, they can just cast it to the actual Object type and access all the fields.
[QUOTE=Noi;41932669]Yes, probably sure.[/QUOTE]
Can you post some of the undefined references you get?
They mean that the compiler was promised that the linker will find the definition of some functions, but the promise was not fulfilled.
[QUOTE=Icedshot;41864051]Does anyone know of a way to send keyboard events to windows that'll be picked up by games? Currently I'm using keybd_event(VK_CODE, 0, KEYEVENTF_EXTENDEDKEY, 0) which works on the desktop, but doesn't appear to be picked up by games[/QUOTE]
Turns out, VK codes are ignored by dinput applications (ie games), you have to use scancodes instead. So instead, I have (the equivalent sendinput of)
keybd_event(0, MapVirtualKey(vk, MAPVK_VK_TO_VSC), KEYEVENTF_SCANCODE, 0);
This works pretty swimmingly
[QUOTE=Lemmingz95;41930320]And to tamschi, I do have global game time, but im looking into ways to shedule things on the fly, eg. when you click x, in two seconds call functions; x, y and z. repeat y and z every 2 seconds 5 times.
I could be missing something obvious, but i cant think of an easy way to do that with one game timer.[/QUOTE]
The most elegant way to do this is with continuations, then you can just Wait(2) in a loop a few times and calculate the end time of the delay somewhere central.
[URL="http://facepunch.com/showthread.php?t=1297403&p=41829839&viewfull=1#post41829839"]This is my implementation.[/URL] The struct is just an interface to C#'s async/await feature.
For a game I'd probably add some kind of success signalling to check if the entity was destroyed and the script should be aborted.
[editline]23rd August 2013[/editline]
[QUOTE=ZeekyHBomb;41937601]You could do something like C++, where you pass a void* for user-data. In C# you can use Object for that.
You can let the user supply an Object with fields for relevant data, so when this parameter gets supplied in the callback, they can just cast it to the actual Object type and access all the fields.[/QUOTE]
An easier way in C# would be to catch relevant data in an Action lambda where possible. This implicitly creates an instance with the necessary fields and avoids explicit casts.
(The C# type is object, not Object. The latter is the .NET framework type object is an alias for (It's in the System namespace while object is a keyword.), but not actually part of the language specification afaik.)
[QUOTE=Tamschi;41937376]Either DoSomething() is called before Main() runs or the Form1 constructor runs DoSomething().
Are you sure you can't move DoSomething into Form1?[/QUOTE]
I guess the best method is to move it to the form1 code. That feels dirty to me, though.
[QUOTE=vexx21322;41938688]I guess the best method is to move it to the form1 code. That feels dirty to me, though.[/QUOTE]
You could also pass a reference to the form into the method, but usually methods referencing a UI window belong into that UI window.
If you want to remove the unrelated things in DoSomething, keep logic and UI separate.
What are some projects I should do to throw in my github in a code samples thing, to show some concepts people should know? I've done like a merge sort, and that kinda stuff. I'm trying to get into a class, they said I'm near the top of the list to be accepted but they can't guarantee that I'll get in until they're done with interviews and that I should update my github and stuff in the meantime. The class is for Django and I'd like to learn some of it beforehand, but the tutorials I've tried don't keep my attention and don't seem to teach me but tell me step by step how to make stuff without describing what's happening.
Anyways, just basic algorithms I could do or simple projects would be cool. I'd like to start doing at least one thing a day, between the interview questions I did for the class and the vacation I took I've been having a hard time getting motivated to code again.
Hi guys, I've recently decided to start learning C++ with SFML, but I'm stuck with the damn pointers.
I've tried making a resource manager for textures, but it's still being drawn as a white texture, which indicates the sf::Texture is not valid anymore.
Here's the code for my resource manager:
ResourceManager.h:
[code]
#ifndef __H_RESOURCE_MANAGER__
#define __H_RESOURCE_MANAGER__
#include <SFML/Graphics.hpp>
#include "Texture.h"
#include <map>
typedef std::map<std::string, Texture> TextureMap;
class ResourceManager
{
public:
static Texture GetTexture( std::string );
static bool IsTextureLoaded( std::string );
static bool LoadTexture( std::string );
private:
static TextureMap Textures;
};
#endif
[/code]
ResourceManager.cpp:
[code]
#include <SFML/Graphics.hpp>
#include "ResourceManager.h"
TextureMap ResourceManager::Textures;
Texture ResourceManager::GetTexture( std::string Name )
{
return ResourceManager::Textures[ Name ];
}
bool ResourceManager::IsTextureLoaded( std::string Name )
{
return ResourceManager::Textures.count( Name ) > 0;
}
bool ResourceManager::LoadTexture( std::string Name )
{
if( ResourceManager::IsTextureLoaded( Name ) )
return true;
TextureMap::iterator it;
it = ResourceManager::Textures.begin( );
ResourceManager::Textures.insert( it, std::pair<std::string, Texture>( Name, Texture( ) ) );
if( !ResourceManager::Textures[ Name ].Load( Name ) )
return false;
return true;
}
[/code]
My Texture class is just a class containing a std::string Name and sf::Texture, and a Load method to set those two to the file path and the sf::Texture.loadFromFile( )'s texture.
Here's my Graphics::DrawTexture method, which is the part that draws a white texture:
[code]
void Graphics::DrawTexture( float X, float Y, float W, float H, sf::Color Color, std::string TextureName )
{
//std::cout << Graphics::Sprite.getTexture( ) << ", " << &Graphics::GetTexture( TextureName ) << std::endl;
if( ResourceManager::IsTextureLoaded( TextureName ) )
{
Texture Tex = ResourceManager::GetTexture( TextureName );
Graphics::Sprite.setTexture( Tex.Image );
}
else
{
std::cout << ResourceManager::LoadTexture( TextureName ) << std::endl;
}
Graphics::Sprite.setPosition( X, Y );
Engine::Window->draw( Graphics::Sprite );
}
[/code]
Could anyone help me figure out the problem here and explain it to me so it won't happen again?
I need some advice again from the grand Facepunch wizards. :tinfoil:
So I am working with OpenGL. Right now I have a lovely randomly generated terrain, but I want to add in a model.
I know how to get all of the vertices and normals from the .obj and all of that.
My question is what would be a good way of implementing multiple draw calls within the program?
Currently I just have the main draw loop drawing the terrain from the vertex buffer.
[QUOTE=xThaWolfx;41940384]Hi guys, I've recently decided to start learning C++ with SFML, but I'm stuck with the damn pointers.
I've tried making a resource manager for textures, but it's still being drawn as a white texture, which indicates the sf::Texture is not valid anymore.
Here's the code for my resource manager:
[code]//code[/code]
My Texture class is just a class containing a std::string Name and sf::Texture, and a Load method to set those two to the file path and the sf::Texture.loadFromFile( )'s texture.
Here's my Graphics::DrawTexture method, which is the part that draws a white texture:
[code]//code[/code]
Could anyone help me figure out the problem here and explain it to me so it won't happen again?[/QUOTE]
iirc stuff with double underscored in the beginning (__) is reserved for future language usage (looking at your header guards there).
You should definitely read up on references.
A subjectively better implementation for IsTextureLoaded would be return Textures.find( Name ) != Textures.end( );.
count() seems like it could do more than you want it to. In a std::map keys are unique, but otherwise it looks like it would do more work than required.
But yeah, I think this is only subjectively.
You could make use of that iterator in LoadTexture though, to provide an exact hint to the insert( )-function.
If you decide against that for whatever reason, there's still a shorter way of writing what you're doing there: Textures.insert( std::make_pair( Name, Texture( ) ) );
At least of the first DrawTexture call the Sprite won't be assigned, because when the texture is not loaded, you load it but don't assign it to the Sprite.
If you're just rendering a single frame, fixing this could solve your issue.
Also, in all of the code I only saw one pointer: Engine::Window?
And I'd even question that that has to be a pointer.
I also have to ask why you prefix anything member-related with Classname::. It seems overly verbose.
Are there any documents for C# coding styles? I started messing with Unity and I couldn't figure out how to format my code well.
[QUOTE=Agent766;41944637]Are there any documents for C# coding styles? I started messing with Unity and I couldn't figure out how to format my code well.[/QUOTE]
[url]http://msdn.microsoft.com/en-us/library/ms229042.aspx[/url]
[QUOTE=robmaister12;41944755][url]http://msdn.microsoft.com/en-us/library/ms229042.aspx[/url][/QUOTE]
Worth noting is that Unity doesn't follow those for some things.
Best C++ tutorial?
[url]http://www.learncpp.com/[/url]
or
[url]http://www.cplusplus.com/doc/tutorial/[/url]
I cannot recommend either if you're starting out with programming. But if you already know a programming language and are looking to expand in this direction they might be good enough.
I started with learncpp, but switched to cplusplus because it clicked better. Except for pointers. Those fucked me for a long time.
Any advice for making a 2d game in c++?
This turned out too long for a PM (>5000 characters), so I'm putting it here instead.
[QUOTE=Lemmingz95][original PM][/QUOTE]
It's a slightly advanced topic and not a core feature of C++, so I'm not surprised it wasn't covered [in the first year].
Async is C#'s name for coroutines, what they do would affect the game's logic scripts rather than the event queue.
Basically, coroutines instruct the compiler to rewrite methods into small state machines.
(You can find libraries for C/C++ if you search for "coroutine" instead of "async", I'm sure this is possible with templates/whatever else is available.)
Here's a simplified example:
If a write methods like this
[code]async void JumpThreeTimes()
{
for (int i = 0; i < 3; i++)
{
bool success = await Jump();
if (success == false) return;
}
}
async bool Jump()
{
if (this.OnFloor == false) return false;
else
{
this.Velocity.Y = 10;
while (this.Velocity.Y > 0) { await WaitFrame(); }
while (this.OnFloor == false) { await WaitFrame(); }
}
}[/code]
the compiler can turn the methods into classes like this
[code]class JumpThreeTimes
{
Entity @this; // caught "field" from outer class, I used an escaped keyword as variable name for clarity, the compiler doesn't actually do this afaik
int state = 0;
int i;
public JumpThreeTimes(Entity @this)
{ this.@this = @this; }
public void MoveNext()
{
switch(state)
{
case 0: break;
case 1: goto asyncSite0; // This jump is illegal in C#, but not in C++ I think
case 2: return;
}
for (int i = 0; i < 3; i++)
{
// start of rewritten coroutine call line
var awaitable0 = new Jump(@this);
state = 1;
awaitable0.AddContinuation(this.MoveNext);
awaitable0.MoveNext();
return;
asyncSite0:
bool success = awaitable0.Result;
// unmanaged: delete awaitable0 here
// end of rewritten coroutine call line
if (success == false)
{
state = 2;
return;
}
}
state = 2;
}
}
class Jump
{
Entity @this;
int state = 0;
public bool Result;
public Jump(Entity @this)
{ this.@this = @this; }
public void MoveNext()
{
switch (state)
{
case 0: break;
case 1: goto asyncSite0;
case 2: goto asyncSite1;
case 3: return;
}
if (@this.OnFloor == false)
{
Result = false;
state = 3;
CallContinuations();
return;
}
else
{
@this.Velocity.Y = 10;
while (@this.Velocity.Y > 0)
{
// start of rewritten coroutine call line
var awaitable0 = new WaitFrame();
state = 1;
awaitable0.AddContinuation(this.MoveNext);
awaitable0.MoveNext();
return;
asyncSite0: ;
// unmanaged: delete awaitable0 here
// end of rewritten coroutine call line
}
while (@this.OnFloor == false)
{
// start of rewritten coroutine call line
var awaitable1 = new WaitFrame();
state = 2;
awaitable1.AddContinuation(this.MoveNext);
awaitable1.MoveNext();
return;
asyncSite1: ;
// unmanaged: delete awaitable1 here
// end of rewritten coroutine call line
}
Result = true;
state = 3;
CallContinuations();
return;
}
// + a list of queued continuations and the relevant methods.
}[/code]
[someone please check if this is correct, syntax-wise]
, which are a lot more tedious to write manually but are amazing for organizing "parallel" actions with durations without using threads.
The call stack is more or less reversed by the second time MoveNext is called, exception handling works a bit different due to that:
In C#, the classes actually have try/catch wrappers (iirc), can enter a failed state and Result is GetResult(), which throws if there was an exception.
Throwing through an async call stack is expensive and unhandled exceptions (where no continuation is registered) stop the program, so it should even less be used for expected flow control than usually.
(An awaitable method/class can be threaded, the continuation is just a bit more complicated in that case.
C#'s implementation is more indirect and there are tons of helper classes, so it's very powerful but the default, data-centric implementation is complex.)
Parameters can be caught the same way as the reference to the outer class's instance.
WaitFrame is a normal class/struct with the same interface as the awaitable methods.
[u]The actual implementation is a bit different, so look it up in the specification if you want to write custom awaitables.[/u]
Is C, C++ or C# the most useful to know, and which can do the most? I really don't know much about any so any explanation would be really appreciated
[QUOTE='Rain [Amber];41963269']Is C, C++ or C# the most useful to know, and which can do the most? I really don't know much about any so any explanation would be really appreciated[/QUOTE]
There's a lot more to it than this, but essentially it doesn't matter. Just pick whichever one seems nicest to you and go with it. Most things can be done just fine in all three languages, and if you ever need to switch then it's not a lot of effort to learn the differences.
I'd want a software which lets me program in C# for android. The only one I know of is monogame, but I'm not really working on a "game", more of an app. Any other like this? Oh and, IPhone support if possible.
[QUOTE=Donkie;41964290]I'd want a software which lets me program in C# for android. The only one I know of is monogame, but I'm not really working on a "game", more of an app. Any other like this? Oh and, IPhone support if possible.[/QUOTE]
[url=http://xamarin.com/monoforandroid]Xamarin.Android[/url] and [url=http://xamarin.com/monotouch]Xamarin.iOS[/url].
[editline]25th August 2013[/editline]
previously known as MonoDroid and MonoTouch, respectively.
[QUOTE=robmaister12;41964742][url=http://xamarin.com/monoforandroid]Xamarin.Android[/url] and [url=http://xamarin.com/monotouch]Xamarin.iOS[/url].
[editline]25th August 2013[/editline]
previously known as MonoDroid and MonoTouch, respectively.[/QUOTE]
Can a useful app even be made in 32kb? I know he didnt ask for it to be free but the fact they offer it...
A little bit of searching also brought up [url=http://monocross.net/]MonoCross[/url], which appears to be free and works on iOS, Android, and WP
Sorry, you need to Log In to post a reply to this thread.