• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=WTF Nuke;36204242]How do big devs handle things like entity systems? I know they are usually component based and before I start writing code I want to plan this out, lest I get awful and incomprehensible code that I just don't want to deal with. Like what does gamebryo do?[/QUOTE] This one is actually really easy on yourself, considering things with the source engine. Just get the source code for modding, and look at the entity cpp and header files.
[QUOTE=WTF Nuke;36204242]Like what does gamebryo do?[/QUOTE] Nothing that you want to replicate.
[QUOTE=WTF Nuke;36204242]How do big devs handle things like entity systems? I know they are usually component based and before I start writing code I want to plan this out, lest I get awful and incomprehensible code that I just don't want to deal with. Like what does gamebryo do?[/QUOTE] As long as you define components by functionality and not by the type of an object, you really can't go that wrong with a component based entity system. Before I implemented that type of system for the first time, I kept on thinking that it would be really complicated and that it would be hard to build the proper framework around it, etc. Then at some point I just started writing some code and realized that a lot of the complications I thought of were non-issues and a lot of things worked themselves out. The only planning you really need to do right now before you write code: -What data is shared between all components and should be a part of Entity? (hint: position) -How will components communicate with one another? (In my implementation all components store a reference to their parent Entity, and you can request other components through the Entity. Other implementations do things like a message passing interface. Depends on what you need.) -how will I store all the components and update them? (Usually this involves a ComponentManager or something similar. In my implementation it only accepts Entities, but internally stores them as separate components separated by type.) Once you have a plan for those three things, start writing some code and you'll see that a lot of it will start to fall in place.
Having a problem with "'Particle' : base class undefined" after lots of google search it appears its causes by an issue with 2 classes having the same header file but this is not the case with mine. [cpp] #pragma once #include "Particle.h" class blueParticle :public Particle { public: blueParticle(int x, int y, float dirx, float diry); virtual ~blueParticle(); protected: }; [/cpp] [cpp] #pragma once #include "Entity.h" #include "Main.h" class Particle : public Entity { public: Particle(int x, int y, float dirx, float diry); virtual ~Particle(); virtual void Update(float frametime); protected: float life_time_; sf::Vector2f direction; float timeAcc; }; [/cpp]
Does Main.h or Entity.H include blueParticle.h/Particle.h? I don't see any reason for your Particle class to include "Main.h" either.
Does anyone know what are some good values for perlin noise? Im using these values: [cpp] PerlinNoise p; p.Set( 2.25, //Persistance 4.0, //Frequency 0.50, //Amplittude 6, //Octaves 5555); //Seed glGenTextures( 1, &tex ); glBindTexture( GL_TEXTURE_2D, tex ); int imgSize = 512; glm::vec3 img[imgSize*imgSize]; for(int y = 0; y < imgSize; y++) { for(int x = 0; x < imgSize; x++) { int id = x + (y * imgSize); img[id] = glm::vec3(p.GetHeight(x, y)); } } glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, imgSize, imgSize, 0, GL_RGB, GL_FLOAT, img ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glGenerateMipmap( GL_TEXTURE_2D ); [/cpp] But it gives this ugly thing: [IMG]http://i.imgur.com/cU93T.png[/IMG]
Tried setting up a basic opengl window with glut and then binding a shader to it with glew, for some reason the shader doesn't do anything, does anybody have any idea why ? Source : [url]http://dl.dropbox.com/u/28926055/EmpiresOpenGL.rar[/url]
[QUOTE=quincy18;36211174]Tried setting up a basic opengl window with glut and then binding a shader to it with glew, for some reason the shader doesn't do anything, does anybody have any idea why ? Source : [url]http://dl.dropbox.com/u/28926055/EmpiresOpenGL.rar[/url][/QUOTE] You should add shader error checking. You're blindly compiling and linking the shader without actually checking if it succeeded or not. You can use my engine's shader object for reference if you'd like, but it's a little messy: [url]https://github.com/naelstrof/Astrostruct/blob/master/src/NShader.cpp[/url]
Yea, I figured that much, so I added it in and this was the error : [URL]http://dl.dropbox.com/u/28926055/juulbitch.png[/URL] But the vertex and fragment shader are both really simple, can't find anything that could cause this. - Edit - Managed to fix the error by removing the #version 150 but now it doesn't error and still just displays a white cube instead of a yellow one.
Currently messing around with SAT (Separating Axis Theorem), But failing miserably to produce a decent collision response. Does anyone have any examples or old code to share and learn from?
Can anyone see anything wrong with this perlin class, I cant get the desired output. [cpp]#include "PerlinNoise.hpp" PerlinNoise::PerlinNoise() { persistence = 0; frequency = 0; amplitude = 0; octaves = 0; randomseed = 0; } PerlinNoise::PerlinNoise(double _persistence, double _frequency, double _amplitude, int _octaves, int _randomseed) { persistence = _persistence; frequency = _frequency; amplitude = _amplitude; octaves = _octaves; randomseed = 2 + _randomseed * _randomseed; } void PerlinNoise::Set(double _persistence, double _frequency, double _amplitude, int _octaves, int _randomseed) { persistence = _persistence; frequency = _frequency; amplitude = _amplitude; octaves = _octaves; randomseed = 2 + _randomseed * _randomseed; } double PerlinNoise::GetHeight(double x, double y) const { return amplitude * Total(x, y); } double PerlinNoise::Total(double i, double j) const { //properties of one octave (changing each loop) double t = 0.0f; double _amplitude = 1; double freq = frequency; for(int k = 0; k < octaves; k++) { t += GetValue(j * freq + randomseed, i * freq + randomseed) * _amplitude; _amplitude *= persistence; freq *= 2; } return t; } double PerlinNoise::GetValue(double x, double y) const { int Xint = (int)x; int Yint = (int)y; double Xfrac = x - Xint; double Yfrac = y - Yint; //noise values double n01 = Noise(Xint-1, Yint-1); double n02 = Noise(Xint+1, Yint-1); double n03 = Noise(Xint-1, Yint+1); double n04 = Noise(Xint+1, Yint+1); double n05 = Noise(Xint-1, Yint); double n06 = Noise(Xint+1, Yint); double n07 = Noise(Xint, Yint-1); double n08 = Noise(Xint, Yint+1); double n09 = Noise(Xint, Yint); double n12 = Noise(Xint+2, Yint-1); double n14 = Noise(Xint+2, Yint+1); double n16 = Noise(Xint+2, Yint); double n23 = Noise(Xint-1, Yint+2); double n24 = Noise(Xint+1, Yint+2); double n28 = Noise(Xint, Yint+2); double n34 = Noise(Xint+2, Yint+2); //find the noise values of the four corners double x0y0 = 0.0625*(n01+n02+n03+n04) + 0.125*(n05+n06+n07+n08) + 0.25*(n09); double x1y0 = 0.0625*(n07+n12+n08+n14) + 0.125*(n09+n16+n02+n04) + 0.25*(n06); double x0y1 = 0.0625*(n05+n06+n23+n24) + 0.125*(n03+n04+n09+n28) + 0.25*(n08); double x1y1 = 0.0625*(n09+n16+n28+n34) + 0.125*(n08+n14+n06+n24) + 0.25*(n04); //interpolate between those values according to the x and y fractions double v1 = Interpolate(x0y0, x1y0, Xfrac); //interpolate in x direction (y) double v2 = Interpolate(x0y1, x1y1, Xfrac); //interpolate in x direction (y+1) double fin = Interpolate(v1, v2, Yfrac); //interpolate in y direction return fin; } double PerlinNoise::Interpolate(double x, double y, double a) const { double negA = 1.0 - a; double negASqr = negA * negA; double fac1 = 3.0 * (negASqr) - 2.0 * (negASqr * negA); double aSqr = a * a; double fac2 = 3.0 * aSqr - 2.0 * (aSqr * a); return x * fac1 + y * fac2; //add the weighted factors } double PerlinNoise::Noise(int x, int y) const { int n = x + y * 57; n = (n << 13) ^ n; int t = (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff; return 1.0 - double(t) * 0.931322574615478515625e-9;/// 1073741824.0); } [/cpp]
ActionScript 3, pretty much my first game ever. [QUOTE] if //scorer1 reaches 200 { //Go to scene 2 and play } } [/QUOTE] I want the game to go to scene 2 and play after [I]scorer1[/I] reaches 200. scorer1 is the instance name of the text box displaying the score. I know how to modify numeral values when they are a string [QUOTE]if blah blah { scorer1.text=(int(scorer1.text)+1).toString()[/QUOTE]but I don't know how to detect when a string has become a certain value. Learning AS3 at school as first programming language. I'll be moving onto harder stuff next year. Sorry my coding isn't as grand as that noise-simulator thingy made in Perl above :/
[QUOTE=quincy18;36211676]Yea, I figured that much, so I added it in and this was the error : [URL]http://dl.dropbox.com/u/28926055/juulbitch.png[/URL] But the vertex and fragment shader are both really simple, can't find anything that could cause this. - Edit - Managed to fix the error by removing the #version 150 but now it doesn't error and still just displays a white cube instead of a yellow one.[/QUOTE] Your shaders use very old deprecated OpenGL features, so GLSL 1.50 is definitely not suited for you. Using a [i]glGetError()[/i] I found that [i]glUseProgram[/i] was causing a [i]GL_INVALID_VALUE[/i] error. To see why this happens, let's have a look at shader creation: [cpp]shader = Shader("Shaders\\vertexshader.shader", "Shaders\\pixelshader.shader");[/cpp] What happens here is that a shader object is created and loads the shaders you specified. It is then assigned to the [i]shader[/i] variable and finally it destroys itself because it is no longer necessary. This destruction causes the shaders to be unloaded and they will no longer be usable by your program. To circumvent this, you need to implement your own assignment operator: [cpp]Shader& Shader::operator=( Shader& shader ) { shader_vp = shader.shader_vp; shader_fp = shader.shader_fp; shader_id = shader.shader_id; shader.shader_id = 0; return *this; }[/cpp] And tell the destructor to not do anything if no shader program is set: [cpp]Shader::~Shader(void) { if ( shader_id == 0 ) return;[/cpp] And of course initialise it to be 0: [cpp]Shader::Shader() { shader_id = 0; }[/cpp] This will result in a correctly drawn cylinder. [t]http://puu.sh/z6ay[/t] Really though, the OpenGL code used here is depressing. If you want to use glut, fair enough, but using fixed pipeline properties in shaders? Ugh. If you have some pride, either ditch shaders or switch to full programmable mode.
Is there any easier way than putting all my .lua files with main.lua on top in a .zip, change it to a .love and execute it everytime I make a small change? Lua + Love2D.
In unity I'm trying to figure out how to change a texture at runtime in C#. I have the file name of the texture in a string, but I dont know how to set the texture from a path.
[QUOTE=TM Gmod;36220901]In unity I'm trying to figure out how to change a texture at runtime in C#. I have the file name of the texture in a string, but I dont know how to set the texture from a path.[/QUOTE] here's one way at least [cpp] using System.IO; private Texture2D loadTexture(string name){ byte[] png = File.ReadAllBytes(name); //name is a full path Texture2D temp; //= new Texture2D(1,1); //i don't remember if you need to initialize it beforehand temp.LoadImage(png); temp.filterMode = FilterMode.Point; //pixelated by default (use whichever mode you'd like) temp.wrapMode = TextureWrapMode.Clamp; //don't repeat the texture return temp; }[/cpp]
[QUOTE=Asgard;36220670]Is there any easier way than putting all my .lua files with main.lua on top in a .zip, change it to a .love and execute it everytime I make a small change? Lua + Love2D.[/QUOTE] uh, yes. Just drag the directory over love.exe. It doesn't need to be a .zip.
Im trying to add water to my height map, ATM Im just creating a flat plane the same size as the terrain at the average terrain height and then in the shader adding the sin of the time to the waters height: [cpp] #version 120 uniform mat4 MVP; uniform mat4 Model; attribute vec3 Position; attribute vec3 Normals; varying vec3 pos; varying vec3 normals; uniform float delta; void main(){ normals = (Model * vec4(Normals , 0.0f) ).xyz; pos = vec3(Position.x, Position.y + ( sin(delta + Position.x) * 0.333f), Position.z); gl_Position = MVP * vec4(pos.xyz, 1.0f); } [/cpp] [IMG]http://i.imgur.com/BI3DQ.png[/IMG] The problem is that the normals are generated at the point that the plane is flat so when the water "moves" the normals still point upwards instead of the direction they should. Is there any way to fix this via the shader? Oh and I only have OGL 2.1 so only fragment and vertex shader, no geometry shader.
I'm having a hard time compiling an SFML project that uses C++11 on Windows. I've tried Visual Studio 2010 Express and Code::Blocks. The former didn't seem to have any options for C++11 and the latter still gets tripped up by [code]for (auto foo : bar)[/code] even when I set -std=c++11
[QUOTE=Richy19;36225167]Im trying to add water to my height map, ATM Im just creating a flat plane the same size as the terrain at the average terrain height and then in the shader adding the sin of the time to the waters height: [cpp] #version 120 uniform mat4 MVP; uniform mat4 Model; attribute vec3 Position; attribute vec3 Normals; varying vec3 pos; varying vec3 normals; uniform float delta; void main(){ normals = (Model * vec4(Normals , 0.0f) ).xyz; pos = vec3(Position.x, Position.y + ( sin(delta + Position.x) * 0.333f), Position.z); gl_Position = MVP * vec4(pos.xyz, 1.0f); } [/cpp] [IMG]http://i.imgur.com/BI3DQ.png[/IMG] The problem is that the normals are generated at the point that the plane is flat so when the water "moves" the normals still point upwards instead of the direction they should. Is there any way to fix this via the shader? Oh and I only have OGL 2.1 so only fragment and vertex shader, no geometry shader.[/QUOTE] Take the derivative of position with respect to U and V to get the tangent and bitangent vectors, then cross-product to get the normal. Should be something like (for the equation you give): tangent = normalize(vec3(1.0, cos(delta + Position.x) / 3.0f, 0.0)); bitangent = normalize(vec3(0.0, 0.0, 1.0)); normal = -cross(tangent, bitangent); That's the analytic method. If the formula for position becomes more complex, it may be easier to just calculate the positions for adjacent vertices and approximate the derivatives numerically.
[QUOTE=Larikang;36225360]I'm having a hard time compiling an SFML project that uses C++11 on Windows. I've tried Visual Studio 2010 Express and Code::Blocks. The former didn't seem to have any options for C++11 and the latter still gets tripped up by [code]for (auto foo : bar)[/code] even when I set -std=c++11[/QUOTE] I don't know if VS11 supports that.
[QUOTE=Larikang;36225360]I'm having a hard time compiling an SFML project that uses C++11 on Windows. I've tried Visual Studio 2010 Express and Code::Blocks. The former didn't seem to have any options for C++11 and the latter still gets tripped up by [code]for (auto foo : bar)[/code] even when I set -std=c++11[/QUOTE] Did you try -std=gnu++11
how do you calculate the half-vector in GLSL? i'm writing a per-pixel lighting shader and the tutorial i'm reading uses the old gl_LightSource[0].halfVector.xyz approach, but i'm using opengl3, and #core 330 for my shaders
[QUOTE=HeroicPillow;36222700]here's one way at least [cpp] using System.IO; private Texture2D loadTexture(string name){ byte[] png = File.ReadAllBytes(name); //name is a full path Texture2D temp; //= new Texture2D(1,1); //i don't remember if you need to initialize it beforehand temp.LoadImage(png); temp.filterMode = FilterMode.Point; //pixelated by default (use whichever mode you'd like) temp.wrapMode = TextureWrapMode.Clamp; //don't repeat the texture return temp; }[/cpp][/QUOTE] Thanks! :)
Im getting a few OGL errors: [cpp]glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuff);[/cpp] Gives: OpenGL: Invalid Operation and: [cpp] glEnableVertexAttribArray(NormalsID); glVertexAttribPointer( NormalsID, // attribute 0. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); glDisableVertexAttribArray(NormalsID);[/cpp] All give OpenGL Invalid Value. Even tho I am adquireing the NormalsID in the same way I do any other ID and those work fine. GLSL output: [IMG]http://i50.tinypic.com/hspert.png[/IMG] which refers to this code: [cpp] glEnableVertexAttribArray(NormalsID); glBindBuffer(GL_ARRAY_BUFFER, normalbuffer); glVertexAttribPointer( NormalsID, // attribute 0. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Index buffer glDrawArrays(GL_TRIANGLES, 0, PosList.size()); glDisableVertexAttribArray(NormalsID); glDisableVertexAttribArray(UVID);[/cpp]
[QUOTE=Kopimi;36227703]how do you calculate the half-vector in GLSL? i'm writing a per-pixel lighting shader and the tutorial i'm reading uses the old gl_LightSource[0].halfVector.xyz approach, but i'm using opengl3, and #core 330 for my shaders[/QUOTE] H = normalize(L + V); L is the vector from the fragment to the light V is the vector from the fragment to the viewer
[QUOTE=ROBO_DONUT;36228315]H = normalize(L + V); L is the vector from the fragment to the light V is the vector from the fragment to the viewer[/QUOTE] isnt the fragment the pixel? i don't know how to get these two vectors either help me ROBO DONUT i am terrible at shaders :(
[QUOTE=Kopimi;36228555]isnt the fragment the pixel? i don't know how to get these two vectors either help me ROBO DONUT i am terrible at shaders :([/QUOTE] If this is Specular lighting your talking about, I do what ROBO_DONUT said, but L is the position of the Camera and V is the vertex Position
[QUOTE=Richy19;36228626]If this is Specular lighting your talking about, I do what ROBO_DONUT said, but L is the position of the Camera and V is the vertex Position[/QUOTE] i'm guessing you have to send the camera position into the vertex shader via uniform, rather than calculating the camera position in the shader? [editline]7th June 2012[/editline] [img]http://i.imgur.com/Y2ZY0.png[/img] help [editline]7th June 2012[/editline] oof! [img]http://i.imgur.com/BOjOq.jpg[/img] thanks robo and richy, helped a ton!
[QUOTE=Richy19;36228626]If this is Specular lighting your talking about, I do what ROBO_DONUT said, but L is the position of the Camera and V is the vertex Position[/QUOTE] What? That won't get you the half-angle vector. I'm not sure what that gives you.
Sorry, you need to Log In to post a reply to this thread.