[QUOTE=pyschomc;44856858]What's the best way to learn C++?[/QUOTE]
And if the stuff you require C++ for can't be accomplished in C#; don't use C++ anyway and use C. And if you ever get stuck somewere or have questions, i can help you with your C++/C/C# problems.
[editline]20th May 2014[/editline]
That is, shoot me a steam message.
[QUOTE=cartman300;44857306]And if the stuff you require C++ for can't be accomplished in C#; don't use C++ anyway and use C. And if you ever get stuck somewere or have questions, i can help you with your C++/C/C# problems.
[editline]20th May 2014[/editline]
That is, shoot me a steam message.[/QUOTE]
My education taught me C++ as my first actual programming language, and it was a huge clusterfuck (from 0 to polymorphism in 4 months). They teach you all these things that might come in useful but at the time you just didn't need them. They tried to teach us OOP by letting is write a fluid dynamics solver class, but they forced the OOP on it so half the time we barely knew what (and especially [U]why[/U]) we were doing. It's a huge language, so many aspects and so many things you can do wrong.
I've also noticed that most "C++" projects I do are mostly C-code. I would suggest trying C first and see if it fits your needs. It's what I would've preferred. You can then dip your feet in OOP/C++ and try to find projects that would greatly benefit from it.
A huge benefit that C++ has over C is the STL (Standard Template Library). The C Library doesn't have any container objects (vectors, maps, etc), so if you use C and you need them you have to write your own (though I'm sure there are libraries that you can find that have them defined).
So if you're thinking about using C and you want to use any containers other than arrays easily, I'd suggest using C++. Most of the code will be exactly the same, save the container stuff and the headers (cstdio instead of stdio.h, etc if you want to use the C library).
There's also plenty of other features in C++ that you might consider using, but like others said it is a huge language and the learning curve is larger than that of other languages.
C++'s STL falls short with basically everything considering you'll be writing boilerplate code, and C++ is in general a horror to work with when it comes to third party libraries. I'd skip C++ and go to a good language like Python, C#, Java, etc.
I know this isn the web dev section but i thought it would be better to ask here.
I have this project I'm working on which graphs and stuff but I can't get one thing working right.
I'm trying to make it so the point (or shapes) reshape themselves as the scroll wheel gets used, but I have no idea how.
[vid]http://a.pomf.se/vvvdjj.mp4[/vid]
here's the code which does whatever when the mouse wheel gets turned.
[url]https://github.com/jung3o/OpenSketch/blob/master/js/mouse.type.js#L298[/url]
[QUOTE=Jookia;44862205]C++'s STL falls short with basically everything considering you'll be writing boilerplate code, and C++ is in general a horror to work with when it comes to third party libraries. I'd skip C++ and go to a good language like Python, C#, Java, etc.[/QUOTE]
I agree but it really depends on what you are doing. You wouldn't want to use Python if speed (as in how fast the program runs, not how fast you can write the program) is crucial, and C# and Java run on VMs which you may not want or may not have available to you.
But again there is a big learning curve and you do end up writing a lot more code compared to languages like Python and Ruby. It's really up to the programmer.
[QUOTE=Fredo;44863152]I agree but it really depends on what you are doing. You wouldn't want to use Python if speed (as in how fast the program runs, not how fast you can write the program) is crucial, and C# and Java run on VMs which you may not want or may not have available to you.
But again there is a big learning curve and you do end up writing a lot more code compared to languages like Python and Ruby. It's really up to the programmer.[/QUOTE]
Speed is almost never a concern, and when it is, it's only like 1% of code. it's not worth using an unproductive language for speed.
There's no such thing as a knife for all cuts. Choose your tools for the project you have in hands.
You need portable code with small footprint? C
You need small code where execution time is not important? Python is likely a good idea.
You need to write small file parsing tools? Python is also a likely good idea.
Simple 2D Games? Löve2D.
And the list goes on. [sp]And Java is nearly useless.[/sp]
[QUOTE=JohnnyOnFlame;44865260]You need portable code with small footprint? C[/QUOTE]
Portability isn't to do with the language. You're only as portable as the least portable code you have linked to your program.
[QUOTE=Jookia;44866033]Portability isn't to do with the language. You're only as portable as the least portable code you have linked to your program.[/QUOTE]
That's a half-truth, really. I'd have a hard time finding an open source C# compiler for Nintendo DS for example.
[QUOTE=Tamschi;44866435]That's a half-truth, really. I'd have a hard time finding an open source C# compiler for Nintendo DS for example.[/QUOTE]
Yes but that's the tools, not the language. You could port Mono to the Nintendo DS.
[QUOTE=Jookia;44866477]Yes but that's the tools, not the language. You could port Mono to the Nintendo DS.[/QUOTE]
With a lot of work. It's "portable" at best in that regard, meaning portability is not an on-off situation.
[QUOTE=Tamschi;44866502]With a lot of work. It's "portable" at best in that regard, meaning portability is not an on-off situation.[/QUOTE]
Yes.
[QUOTE=jung3o;44862490]I know this isn the web dev section but i thought it would be better to ask here.
I have this project I'm working on which graphs and stuff but I can't get one thing working right.
I'm trying to make it so the point (or shapes) reshape themselves as the scroll wheel gets used, but I have no idea how.
[vid]http://a.pomf.se/vvvdjj.mp4[vid]
here's the code which does whatever when the mouse wheel gets turned.
[url]https://github.com/jung3o/OpenSketch/blob/master/js/mouse.type.js#L298[/url][/QUOTE]
Your point coordinates will just need to be scaled with the zoom factor.
Since today, I hate InitializeComponent();
So i got an external DLL which exports Methods, I wanna call them:
I put my code in front of InitializeComponent:
[CODE]
public MainWindow1()
{
OverlayManager manager = new OverlayManager();
manager.doshit(); //This method is calls DLLImport Method
InitializeComponent();
}
[/CODE]
Working as expected...
Putting it after InitializeComponent: Same Return-Value of the method, but no visual-repsonse
(The external Method creates a TextLabel in a Directx Window)
Why you're such a bitch to me :/
[QUOTE=Fredo;44863152]C# runs on a VM which you may not want or may not have available to you.[/QUOTE]
That requirement isn't lasting long, [URL="http://blogs.msdn.com/b/dotnet/archive/2014/04/02/announcing-net-native-preview.aspx"]They already have a native compiler out for shop apps with the rest coming soon.[/URL]
[QUOTE=Jookia;44866477]Yes but that's the tools, not the language. You could port Mono to the Nintendo DS.[/QUOTE]
It's certainly possible and you're not wrong, but I hope you don't mean the original Nintendo DS. Being hardware from 2004, [url=http://en.wikipedia.org/wiki/Nintendo_DS#Technical_specifications]it's not exactly fast[/url]. And to add insult to injury here, it only has four [i]megabytes[/i] of RAM, so you might no just hit speed but also memory limits real quick.
[QUOTE=Alternative Account;44868499]It's certainly possible and you're not wrong, but I hope you don't mean the original Nintendo DS. Being hardware from 2004, [url=http://en.wikipedia.org/wiki/Nintendo_DS#Technical_specifications]it's not exactly fast[/url]. And to add insult to injury here, it only has four [i]megabytes[/i] of RAM, so you might no just hit speed but also memory limits real quick.[/QUOTE]
Wow, they managed to do all of that with only 4MB? That's pretty impressive.
[QUOTE=Alternative Account;44868499]It's certainly possible and you're not wrong, but I hope you don't mean the original Nintendo DS. Being hardware from 2004, [url=http://en.wikipedia.org/wiki/Nintendo_DS#Technical_specifications]it's not exactly fast[/url]. And to add insult to injury here, it only has four [i]megabytes[/i] of RAM, so you might no just hit speed but also memory limits real quick.[/QUOTE]
Then I don't think portability is your biggest concern. :v
Guys, I need the helps. C++ has stumped me.
I have 2 classes. One is "TileMap", one is "Tile".
In TileMap, I have a private vector<Tile>, and a getter method for it.
In Tile, I have a function where a TileMap is passed into it. There, I use the getter method. VS2010 is spouting this error: [IMG]http://puu.sh/8W1sw.jpg[/IMG]
Relevant code.
[I]Tile.cpp[/I]
[code]Tile getTileAtPoint(sf::Vector2f& point, TileMap &map) {
std::vector<Tile> mapTiles = map.getTiles();
}[/code]
[I]TileMap.h[/I]
[code]std::vector<Tile> TileMap::getTiles() { return v_tileMap; }
private:
std::vector<Tile> v_tileMap;[/code]
[QUOTE=Shadow187(FP);44873934]Guys, I need the helps. C++ has stumped me.
I have 2 classes. One is "TileMap", one is "Tile".
In TileMap, I have a private vector<Tile>, and a getter method for it.
In Tile, I have a function where a TileMap is passed into it. There, I use the getter method. VS2010 is spouting this error: [IMG]http://puu.sh/8W1sw.jpg[/IMG]
Relevant code.
[I]Tile.cpp[/I]
[code]Tile getTileAtPoint(sf::Vector2f& point, TileMap &map) {
std::vector<Tile> mapTiles = map.getTiles();
}[/code]
[I]TileMap.h[/I]
[code]std::vector<Tile> TileMap::getTiles() { return v_tileMap; }
private:
std::vector<Tile> v_tileMap;[/code][/QUOTE]
By any chance does TileMap.h include Tile.h and Tile.h include TileMap.h?
[QUOTE=BackwardSpy;44874023]By any chance does TileMap.h include Tile.h and Tile.h include TileMap.h?[/QUOTE]
...yes.
I made a thread about this but no one seems to be interested. To be honest this was a better place for my question but never mind.
So, I am new to OpenGL and relatively new to C++. I followed a tutorial on oppening a window in GLFW and decided it would be a good practice if I tried to add some drawing code to it.
[url]http://pastebin.com/Vpx7xGzZ[/url]
The thing is, it returns error code 1280 (Invvalud enumeration) and crashes. If I remove the call to glDrawArrays it returns error code 1280, then 1282 and then crashes. Could anyone please point out what is wrong cause I went through the code a few times already, using khronos.org as a refference and I can't seem to figure out the error.
Also for those wondering, I read that I should use "homogenous" coordinates, this is why I use vec4 in the shader code.
[QUOTE=Cold;44814500][B]OpenGL[/B]
[I]For starters:[/I]
[url]http://open.gl/[/url]
[url]http://www.arcsynthesis.org/gltut/[/url]
[url]http://www.opengl-tutorial.org/[/url]
[url]http://www.swiftless.com[/url]
[url]http://learningwebgl.com/[/url] (WebGL)
OpenGL SuperBible, Sixth Edition
Interactive Computer Graphics: A Top-Down Approach with Shader-Based OpenGL
[I]Advanced:[/I]
GPU Gems 1 : [url]http://http.developer.nvidia.com/GPUGems/gpugems_part01.html[/url]
GPU Gems 2 : [url]http://http.developer.nvidia.com/GPUGems2/gpugems2_part01.html[/url]
GPU Gems 3 : [url]http://http.developer.nvidia.com/GPUGems3/gpugems3_part01.html[/url]
ShaderX7[/QUOTE]
Okay it's coming along nicely, I didn't start seriously working on it until yesterday but I got this so far (bolded things I've finished(
[quote]Marking Criteria
Object Animation 15
Animation 5
Interaction 5
Collisions 5
Object Drawing 15
[B]Camera/modelview transformations 5[/B]
[B]Perspective transformations 5 [/B]
Vertex attributes 5
[B]World Generation 10 [/B]
[B]Terrain [/B]or Dungeon (BSP/ray cast)
Texturing 10
[B]Colour 5 [/B]
Bump / Normal 5
[B]Lighting 15 [/B]
[B]Diffuse 5 [/B]
Specular 5
[B]Ambient 5 [/B]
[B]Visible Surface Detection 10 [/B]
[B]Backface culling 5 [/B]
[B]z-buffering 5 [/B]
Playability 10
Documentation 15[/quote]
[t]http://i.imgur.com/E7l9CHV.png[/t]
I have a few questions, but I'll just keep it to this one for now: How do I get the game to run at 60 FPS?
Like I want to do:
[code]timeNext = getMicroseconds();
delta = timeLast / timeNext;
timeLast = timeNext;
moveSpeed = 10 * delta;[/code]
Not sure if this is how I would do it.
[QUOTE=Shadow187(FP);44874027]...yes.[/QUOTE]
Circular dependencies are great fun. Luckily, they're quite easy to resolve.
Here's what it looks like now (at least, kind of:)
[code]// TileMap.h
#include "Tile.h"
class TileMap
{
public:
std::vector<Tile> tiles;
};
// Tile.h
#include "TileMap.h"
class Tile
{
public:
void doThing(TileMap map);
};[/code]
The problem here should be obvious; both files include each other resulting in a circular dependency. To fix it, you want to make use of forward declarations:
[code]// TileMap.h
#include "Tile.h"
class TileMap
{
public:
std::vector<Tile> tiles;
};
// Tile.h
// This lets Tile.h knows a class called 'TileMap' exists.
// It doesn't know about TileMap's functionality, but it can reference/point to 'TileMap' instances
// because it does know that the class exists somewhere.
class TileMap;
class Tile
{
public:
void doThing(TileMap &map);
};
// Tile.cpp
#include "Tile.h"
// Including TileMap.h here 'fills out' the functionality of the forward declared class,
// so the 'doThing' function can actually work with TileMap functionality.
#include "TileMap.h"
void Tile::doThing(TileMap &map) { /* stuff! */ }[/code]
Hopefully that helped somewhat!
I wrote all that out in the post editor, so there may be typos and other mistakes.
[QUOTE=KatNotDinner;44875761]I made a thread about this but no one seems to be interested. To be honest this was a better place for my question but never mind.
So, I am new to OpenGL and relatively new to C++. I followed a tutorial on oppening a window in GLFW and decided it would be a good practice if I tried to add some drawing code to it.
[url]http://pastebin.com/Vpx7xGzZ[/url]
The thing is, it returns error code 1280 (Invvalud enumeration) and crashes. If I remove the call to glDrawArrays it returns error code 1280, then 1282 and then crashes. Could anyone please point out what is wrong cause I went through the code a few times already, using khronos.org as a refference and I can't seem to figure out the error.
Also for those wondering, I read that I should use "homogenous" coordinates, this is why I use vec4 in the shader code.[/QUOTE]
[cpp]
glGenBuffers(0, &vbo);
[/cpp]
That should probably be a 1 (Line 190).
My texture loading code loads windows BMP files into OpenGL textures. It works fine for 16x16 images, but it gives errors on 32x32 and 64x64 and larger images:
[code]int Core::loadTexture(char *file)
{
// Load the image
SDL_Surface *tex = IMG_Load(file);
GLuint texture;
cout << "Loading image: " << string(file) << "\n";
if (tex) {
glGenTextures(1, &texture); // Generating 1 texture
glBindTexture(GL_TEXTURE_2D, texture); // Bind the texture
glTexImage2D(GL_TEXTURE_2D, 0, 3, tex->w, tex->h, 0, GL_BGR, GL_UNSIGNED_BYTE, tex->pixels); // Map texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Set minifying parameter to linear
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Set magnifying parameter to linear
SDL_FreeSurface(tex); // Free the surface from memory
cout << " > Image loaded: " << string(file) << "\n\n";
return texture; // return the texture index
} else {
cout << " > Failed to load image: " << IMG_GetError() << "\n\n";
return -1; // return -1 in case the image failed to load
}
}[/code]
[editline]23rd May 2014[/editline]
Never mind, my code loads PNG files of any size just fine as long as the format is set to GL_RGB instead of GL_BGR
So uh, using SDL and I can't get it to display my characters. I hate posting so much code but I cannot figure out what I've missed.
I don't really expect anyone to solve it with this much code but if anyone is feeling generous it would be appreciated.
Font - texture is loaded in Load()
[code]
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using SDL2;
using Shared;
namespace Client.Render
{
class Font : IDisposable
{
public string Name { get; set; }
public IntPtr FontAtlas { get; set; }
public List<CharInfo> Characters = new List<CharInfo>();
public Font(string name)
{
Name = name;
}
public CharInfo GetChar(char c)
{
foreach (CharInfo charInfo in Characters.Where(charInfo => charInfo.CharacterUtf == c))
return charInfo;
throw new Exception("Character " + c + " not found in font: " + Name);
}
public void Load(string fileName)
{
string absDir = Directory.GetCurrentDirectory() + fileName;
string atlasFileName = absDir + "_0.png";
if(!File.Exists(atlasFileName))
throw new Exception("Font Atlas " + atlasFileName + " does not exist.");
FontAtlas = SDL_image.IMG_Load(atlasFileName);
if (FontAtlas == IntPtr.Zero)
throw new Exception("Error: Failed to load font atlas.");
if(SDL_image.IMG_Init(SDL_image.IMG_InitFlags.IMG_INIT_PNG) == 0)
throw new Exception("Error: Failed to initialize font atlas.");
ParseXML(absDir);
}
private void ParseXML(string fileName)
{
XDocument xmlDoc = XDocument.Load(fileName + ".fnt");
if (xmlDoc.Root == null)
throw new Exception("Error getting root xml attribute.");
XElement chars = xmlDoc.Root.Element("chars");
if (chars == null)
throw new Exception("Error getting 'char' elements from xml file.");
foreach (CharInfo newChar in chars.Elements("char").Select(c => new CharInfo()
{
Id = (uint) TryIntAttribute(c, "id"),
Position = new Vec2(TryIntAttribute(c, "x"), TryIntAttribute(c, "y")),
Size = new Vec2(TryIntAttribute(c, "width"), TryIntAttribute(c, "height")),
Offset = new Vec2(TryIntAttribute(c, "xoffset"), TryIntAttribute(c, "yoffset"))
}))
{
string c = char.ConvertFromUtf32((int)newChar.Id);
newChar.CharacterUtf = c.First();
newChar.FontAtlas = FontAtlas;
newChar.CalculateSDL();
Characters.Add(newChar);
}
}
private static int TryIntAttribute(XElement characters, string attrib)
{
int res = 0;
string attributeString = characters.Attribute(attrib).Value;
if(!int.TryParse(attributeString, out res))
throw new Exception("Error getting "+attributeString+" attribute from xml character");
return res;
}
public void Dispose()
{
SDL.SDL_DestroyTexture(FontAtlas);
}
}
}
[/code]
Char - rendering in Draw()
[code]
using System;
using Shared;
using SDL2;
namespace Client.Render
{
internal class CharInfo
{
public char CharacterUtf { get; set; }
public uint Id { get; set; }
public Vec2 Position { get; set; }
public Vec2 Size { get; set; }
public Vec2 Offset { get; set; }
public IntPtr FontAtlas;
private SDL.SDL_Rect TextureCoords;
public CharInfo()
{
}
public void CalculateSDL()
{
TextureCoords = new SDL.SDL_Rect
{
x = Position.x, y = Position.y,
w = Size.x, h = Size.y
};
}
public void Draw(Vec2 pos, IntPtr renderer)
{
SDL.SDL_Rect posC= new SDL.SDL_Rect {x = pos.x, y = pos.y};
SDL.SDL_RenderFillRect(renderer, ref posC);
SDL.SDL_RenderCopy(renderer, FontAtlas, ref posC, ref TextureCoords);
}
}
}[/code]
Display
[code]
using System;
using SDL2;
namespace Client.Render
{
class Display
{
public IntPtr Window { get; set; }
public IntPtr Renderer { get; set; }
public bool IsRunning = false;
public delegate void DisplayDelegate();
public event DisplayDelegate Draw;
public Display(int x, int y, string title)
{
if(SDL.SDL_Init(SDL.SDL_INIT_EVERYTHING) != 0)
throw new Exception("Error: SDL initialization failed: "+ SDL.SDL_GetError());
if(Renderer != IntPtr.Zero)
SDL.SDL_DestroyRenderer(Window);
if (Renderer != IntPtr.Zero)
SDL.SDL_DestroyWindow(Renderer);
Window = SDL.SDL_CreateWindow(title, 100, 100, x, y, SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN);
Renderer = SDL.SDL_CreateRenderer(Window, -1, (uint)SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED | (uint)SDL.SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC);
if(Renderer == IntPtr.Zero)
throw new Exception("Error: Couldn't create Renderer: " + SDL.SDL_GetError());
}
public void Run()
{
IsRunning = true;
while (IsRunning)
{
Update();
}
Dispose();
}
public void Update()
{
SDL.SDL_Event sdlEvent;
SDL.SDL_PollEvent(out sdlEvent);
SDL.SDL_RenderClear(Renderer);
if(Draw != null)
Draw.Invoke();
SDL.SDL_RenderPresent(Renderer);
}
private void Dispose()
{
SDL.SDL_DestroyRenderer(Renderer);
SDL.SDL_DestroyWindow(Window);
SDL.SDL_Quit();
}
}
}
[/code]
[editline]23rd May 2014[/editline]
Draw via..
[code]display.Draw += () => testFont.GetChar('c').Draw(new Vec2(100,100), display.Renderer);[/code]
[QUOTE=ECrownofFire;44880619][cpp]
glGenBuffers(0, &vbo);
[/cpp]
That should probably be a 1 (Line 190).[/QUOTE]
Thanks a lot, I feel really stupid now. But there's another problem. It still reports error 1280, but after tht the triangle appears. Any ideas what enumeration could be wrong?
help whats the deal with this:
[img]http://i.imgur.com/pV5tEq2.png[/img]
[editline]23rd May 2014[/editline]
It's coming from excpt.h which appears to be a windows file. I didn't modify it so I don't know why it's happening.
[editline]23rd May 2014[/editline]
Forgot a ; in a header file, I don't know why it lead me to a different header file though.
Sorry, you need to Log In to post a reply to this thread.