[QUOTE=Richy19;36382999]The problem is, before i was just checking if the key is down, but at 200fps it just kept swapping(as in the console display kept swapping as I cant remove my finger fast enought) so im trying to tell if the key has been pressed just once or if the key is held, to have things like text input or toggle stuff[/QUOTE]
If you keep two lists of keys, you can update one each frame and set the other to that one when the frame is done:
[code]
while(open)
{
kbstate_old = kbstate; //copy last state to 'old' state var
kbstate = getKBstate(); //update current state to current keys
//check for key presses here:
//to see if a key is down, check kbstate.
//to see if a key has just been pressed, check if it's pressed in kbstate but not in kbstate_old.
//to see if a key's just been released, check it's pressed in kbstate_old but not in kbstate.
}
[/code]
Best way to learn C# and XNA for videogames (2D sidescroller) for someone who's only experience in coding is Pascal?
[QUOTE=flayne;36382808]When creating a model for OpenGL what coordinate range should I use? Should I make all of my vertices coordinates be in the -1, 1 range or should I use higher floats? This is assuming I typically want to use matrices without having to have scale right of the bat.[/QUOTE]
It entirely depends on your preference. Just use units that make sense for your game environment.
-snip-
Holy shit, I mistook this thread with waywo, sorry
Dr. Luke made me mistake this for waywo as well haha
[QUOTE=Richy19;36382999]
Does anyone know what source file lua defines the print function in? I want to re-write it to output it to the in-game console[/QUOTE]
It's defined in [URL="http://www.lua.org/source/5.1/lbaselib.c.html#luaB_print"]lbaselib.c[/URL], but I thought you could simply redefine it like this:
[code]
int NewPrint(lua_State* L)
{
std::cout << luaL_checkstring(L,1);
return 0;
}
Lua::Lua()
{
L = luaL_newstate();
luaL_openlibs(L);
static const luaL_Reg NewPrintFunction[] =
{
{"print",NewPrint},
{NULL,NULL}
};
lua_getglobal(L,"_G");
luaL_register(L,NULL,NewPrintFunction);
}[/code]
I'm not sure though, try it out and tell me if it works. :u
-snip-
I'm a moron :V
[QUOTE=DrLuke;36382934]So today I've learnt the importance of a rich dataset. I can't expect a learning algorithm to learn something with a set of inputs which always have the same output, it'll just always assume the solution to be 1.0, even if the image actually is wrong. But it was always correct for the training set.
So now I need to add some images to my training set which isn't the character the cell is looking for.[/QUOTE]
While taking an AI course in college, I read an article about a project where the military tried to train a neural network to recognize camouflaged tanks. They trained it with pictures of real tanks camouflaged in their surroundings, and pictures of similar places without tanks. It worked fine for the training set, but the results were all wrong when they moved to pictures outside the training set.
After investigation, it turned out that all the pictures of tanks had been taken on a cloudy day, and all the pictures of non-tanks had been taken on a sunny day, and the system had actually learned to recognize overcast skies.
While I was messing around with classes, I tried to call a method which should've decreased a private int by one. I tried calling the method again and it seemed to reset the variable to the initial value and subtract by one. Although, if I used a pointer instead, it'd work as intended. Why is that?
[QUOTE=Chessnut;36392711]While I was messing around with classes, I tried to call a method which should've decreased a private int by one. I tried calling the method again and it seemed to reset the variable to the initial value and subtract by one. Although, if I used a pointer instead, it'd work as intended. Why is that?[/QUOTE]
Scope.
[QUOTE=Chessnut;36392711]While I was messing around with classes, I tried to call a method which should've decreased a private int by one. I tried calling the method again and it seemed to reset the variable to the initial value and subtract by one. Although, if I used a pointer instead, it'd work as intended. Why is that?[/QUOTE]
post code.
what is the best way to reproduce the view space position of a fragment (GLSL) given a linearized depth value?
i'm tearing my hair out trying to get this done and i just cannot figure it out.
How come that the following bumpmap shaders work just fine in Shader Maker:
[thumb]http://puu.sh/C637[/thumb]
but in OpenGL I get some sort of strange mix between the two, constantly flickering when I look around or move my camera.
[thumb]http://puu.sh/C65w[/thumb]
Vertex shader:
[code]
varying vec3 normal,lightDir,halfVector;
void main( )
{
normal = normalize( gl_NormalMatrix * gl_Normal );
lightDir = normalize( vec3( gl_LightSource[0].position ) );
halfVector = normalize( gl_LightSource[0].halfVector.xyz );
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform( );
}
[/code]
Fragment shader:
[code]
varying vec3 normal,lightDir,halfVector;
uniform sampler2D colorMap;
uniform sampler2D normalMap;
void main ( )
{
float distSqr = dot( lightDir, lightDir );
float att = clamp( sqrt( distSqr ), 0.0, 1.0 );
vec3 lVec = lightDir * inversesqrt( distSqr );
vec4 base = texture2D( colorMap, gl_TexCoord[0].xy );
vec3 bump = normalize( texture2D( normalMap, gl_TexCoord[0].xy ).xyz * 2.0 - 1.0 );
vec4 vAmbient = gl_LightSource[0].ambient * gl_FrontMaterial.ambient;
float diffuse = max( dot( lVec, bump ), 0.0 );
vec4 vDiffuse = gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse *
diffuse;
float specular = pow( clamp( dot( reflect( -lVec, bump ), normal ), 0.0, 1.0 ),
gl_FrontMaterial.shininess );
vec4 vSpecular = gl_LightSource[0].specular * gl_FrontMaterial.specular *
specular;
float NdotL,NdotHV;
vec4 color = vAmbient;
NdotL = max( dot( normal,lightDir ),0.0 );
if ( NdotL > 0.0 )
{
color += diffuse * NdotL;
vec3 halfV = normalize( halfVector );
NdotHV = max( dot( normal,halfV ), 0.0 );
color += vSpecular * pow( NdotHV, gl_FrontMaterial.shininess );
}
gl_FragColor = ( vAmbient*base +
vDiffuse*base +
vSpecular ) * att * color;
}
[/code]
I know the basics of C++. Classes, Ifs, loops, variables, headers, etc. from a programming class I took. Now I think the best way for me to improve it to get into making games, but I don't know where to start. My goal for the end of the summer is to be able to create a Pokemon clone(not finish, but have the knowledge to).
[QUOTE=ManningQB18;36399630]I know the basics of C++. Classes, Ifs, loops, variables, headers, etc. from a programming class I took. Now I think the best way for me to improve it to get into making games, but I don't know where to start. My goal for the end of the summer is to be able to create a Pokemon clone(not finish, but have the knowledge to).[/QUOTE]
There are two important things you need to do.
1. Learn basic archetecture, I recommend the book Game Engine Archetecture (which you can rent a virtual copy of for cheap at barnes and noble).
2. You need to either familiarize yourself with a 3D graphics API like OpenGL or DirectX or you need to familiarize yourself with tools like SDL/SFML.
[editline]19th June 2012[/editline]
[QUOTE=xThaWolfx;36399260]How come that the following bumpmap shaders work just fine in Shader Maker:
[thumb]http://puu.sh/C637[/thumb]
but in OpenGL I get some sort of strange mix between the two, constantly flickering when I look around or move my camera.
[thumb]http://puu.sh/C65w[/thumb]
Vertex shader:
[code]
varying vec3 normal,lightDir,halfVector;
void main( )
{
normal = normalize( gl_NormalMatrix * gl_Normal );
lightDir = normalize( vec3( gl_LightSource[0].position ) );
halfVector = normalize( gl_LightSource[0].halfVector.xyz );
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform( );
}
[/code]
Fragment shader:
[code]
varying vec3 normal,lightDir,halfVector;
uniform sampler2D colorMap;
uniform sampler2D normalMap;
void main ( )
{
float distSqr = dot( lightDir, lightDir );
float att = clamp( sqrt( distSqr ), 0.0, 1.0 );
vec3 lVec = lightDir * inversesqrt( distSqr );
vec4 base = texture2D( colorMap, gl_TexCoord[0].xy );
vec3 bump = normalize( texture2D( normalMap, gl_TexCoord[0].xy ).xyz * 2.0 - 1.0 );
vec4 vAmbient = gl_LightSource[0].ambient * gl_FrontMaterial.ambient;
float diffuse = max( dot( lVec, bump ), 0.0 );
vec4 vDiffuse = gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse *
diffuse;
float specular = pow( clamp( dot( reflect( -lVec, bump ), normal ), 0.0, 1.0 ),
gl_FrontMaterial.shininess );
vec4 vSpecular = gl_LightSource[0].specular * gl_FrontMaterial.specular *
specular;
float NdotL,NdotHV;
vec4 color = vAmbient;
NdotL = max( dot( normal,lightDir ),0.0 );
if ( NdotL > 0.0 )
{
color += diffuse * NdotL;
vec3 halfV = normalize( halfVector );
NdotHV = max( dot( normal,halfV ), 0.0 );
color += vSpecular * pow( NdotHV, gl_FrontMaterial.shininess );
}
gl_FragColor = ( vAmbient*base +
vDiffuse*base +
vSpecular ) * att * color;
}
[/code][/QUOTE]
It might have something to do with the way your program inputs data into the shader. Try and check that code and make sure it matches with whatever shader maker does. Also did you forget the #version or just leave it off because that could be the problem too.
[QUOTE=flayne;36399696]There are two important things you need to do.
1. Learn basic archetecture, I recommend the book Game Engine Archetecture (which you can rent a virtual copy of for cheap at barnes and noble).
2. You need to either familiarize yourself with a 3D graphics API like OpenGL or DirectX or you need to familiarize yourself with tools like SDL/SFML.
[/QUOTE]
Any suggestions on learning SDL and SFML? I plan on starting with 2D games and saving 3D for a later date when I have some idea of what I'm doing.
[QUOTE=ManningQB18;36400095]Any suggestions on learning SDL and SFML? I plan on starting with 2D games and saving 3D for a later date when I have some idea of what I'm doing.[/QUOTE]
Personally I've never had experience for either. But they are popular topics in this forum and are supposed to be very well documented. There should be good jumping off points on the respective sites.
[QUOTE=flayne;36400216]Personally I've never had experience for either. But they are popular topics in this forum and are supposed to be very well documented. There should be good jumping off points on the respective sites.[/QUOTE]
Alrighty then, thanks.
[QUOTE=xThaWolfx;36399260]How come that the following bumpmap shaders work just fine in Shader Maker:
[thumb]http://puu.sh/C637[/thumb]
but in OpenGL I get some sort of strange mix between the two, constantly flickering when I look around or move my camera.
[thumb]http://puu.sh/C65w[/thumb]
Vertex shader:
[code]
varying vec3 normal,lightDir,halfVector;
void main( )
{
normal = normalize( gl_NormalMatrix * gl_Normal );
lightDir = normalize( vec3( gl_LightSource[0].position ) );
halfVector = normalize( gl_LightSource[0].halfVector.xyz );
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform( );
}
[/code]
Fragment shader:
[code]
varying vec3 normal,lightDir,halfVector;
uniform sampler2D colorMap;
uniform sampler2D normalMap;
void main ( )
{
float distSqr = dot( lightDir, lightDir );
float att = clamp( sqrt( distSqr ), 0.0, 1.0 );
vec3 lVec = lightDir * inversesqrt( distSqr );
vec4 base = texture2D( colorMap, gl_TexCoord[0].xy );
vec3 bump = normalize( texture2D( normalMap, gl_TexCoord[0].xy ).xyz * 2.0 - 1.0 );
vec4 vAmbient = gl_LightSource[0].ambient * gl_FrontMaterial.ambient;
float diffuse = max( dot( lVec, bump ), 0.0 );
vec4 vDiffuse = gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse *
diffuse;
float specular = pow( clamp( dot( reflect( -lVec, bump ), normal ), 0.0, 1.0 ),
gl_FrontMaterial.shininess );
vec4 vSpecular = gl_LightSource[0].specular * gl_FrontMaterial.specular *
specular;
float NdotL,NdotHV;
vec4 color = vAmbient;
NdotL = max( dot( normal,lightDir ),0.0 );
if ( NdotL > 0.0 )
{
color += diffuse * NdotL;
vec3 halfV = normalize( halfVector );
NdotHV = max( dot( normal,halfV ), 0.0 );
color += vSpecular * pow( NdotHV, gl_FrontMaterial.shininess );
}
gl_FragColor = ( vAmbient*base +
vDiffuse*base +
vSpecular ) * att * color;
}
[/code][/QUOTE]
Make sure on the client side that you set the sampler uniforms values to the texture slot you load the color/normal maps to.
e.g. if you set up your textures like this:
[csharp]
GL.BindTexture(TextureTarget.Texture2D, colorMapId);
GL.ActiveTexture(TextureUnit.Texture1);
GL.BindTexture(TextureTarget.Texture2D, normalMapId);
[/csharp]
Then you need to get the location of uniform "colorMap" and set the value to 0, and "normalMap" to 1. I abstracted it away a while ago, but from memory it'll look something like this:
[csharp]GL.Uniform1(GL.GetUniformLocation(progId, "colorMap"), 0);
GL.Uniform1(GL.GetUniformLocation(progId, "normalMap"), 1);[/csharp]
I'm trying to call glDrawArrays in my program (working on Windows). I've got a working context and pixel format all set up and I can call most OpenGL functions. However when I get to the call to glDrawArrays I get access violations. Based on the error it seems as if glDrawArrays is not loading from OpenGL32.dll correctly and is being interpreted as a NULL function pointer, how can I fix this? (Yes I'm sure drawArrays comes from OpenGL32.dll and doesn't need to be loaded with wglGetProcAddress).
[QUOTE=robmaister12;36400374]Make sure on the client side that you set the sampler uniforms values to the texture slot you load the color/normal maps to.
e.g. if you set up your textures like this:
[csharp]
GL.BindTexture(TextureTarget.Texture2D, colorMapId);
GL.ActiveTexture(TextureUnit.Texture1);
GL.BindTexture(TextureTarget.Texture2D, normalMapId);
[/csharp]
Then you need to get the location of uniform "colorMap" and set the value to 0, and "normalMap" to 1. I abstracted it away a while ago, but from memory it'll look something like this:
[csharp]GL.Uniform1(GL.GetUniformLocation(progId, "colorMap"), 0);
GL.Uniform1(GL.GetUniformLocation(progId, "normalMap"), 1);[/csharp][/QUOTE]
I'm using the following function to do so:
[csharp]
public static void BindTexture( ref int textureId, TextureUnit textureUnit, string UniformName )
{
GL.ActiveTexture( textureUnit );
GL.BindTexture( TextureTarget.Texture2D, textureId );
GL.Uniform1( GL.GetUniformLocation( progId, UniformName ), textureUnit - TextureUnit.Texture0 );
}
[/csharp]
This is correct, right?
[QUOTE=xThaWolfx;36400700]I'm using the following function to do so:
[csharp]
public static void BindTexture( ref int textureId, TextureUnit textureUnit, string UniformName )
{
GL.ActiveTexture( textureUnit );
GL.BindTexture( TextureTarget.Texture2D, textureId );
GL.Uniform1( GL.GetUniformLocation( progId, UniformName ), textureUnit - TextureUnit.Texture0 );
}
[/csharp]
This is correct, right?[/QUOTE]
as long as UniformName is correct, yes.
[QUOTE=robmaister12;36401356]as long as UniformName is correct, yes.[/QUOTE]
It is. Have you got an idea besides that?
I'll provide you with the code I'm using to render my stuff, even though you already know most of it :v:
It's worth a shot, though:
[csharp]
//you can do all your texture binding stuff here
Graphics.BindTexture( ref this.MaterialData.TextureMap_Ambient, TextureUnit.Texture0, "colorMap" );
Graphics.BindTexture( ref this.MaterialData.TextureMap_BumpMap, TextureUnit.Texture1, "normalMap" );
GL.Material( MaterialFace.Front, MaterialParameter.Ambient, this.MaterialData.Color_Ambient );
GL.Material( MaterialFace.Front, MaterialParameter.Specular, this.MaterialData.Color_Specular );
GL.Material( MaterialFace.Front, MaterialParameter.Diffuse, this.MaterialData.Color_Diffuse );
GL.Material( MaterialFace.Front, MaterialParameter.Shininess, ( float ) this.MaterialData.Constant_Specular );
GL.BindBuffer( BufferTarget.ArrayBuffer, vbo );
//the last two parameters for these methods are stride and offset. Stride is the distance from the beginning of one vertex to the beginning of the next.
//In this case it's always the size of the Vertex struct in bytes (32). The offset is the distance to the first vertex. So for texcoords it would only be the the size of the position vector,
//but for normals, it's the size of the position vector plus the size of the texture coordinate vector. All lengths are in bytes.
GL.VertexPointer( 3, VertexPointerType.Float, 32, 0 );
GL.TexCoordPointer( 2, TexCoordPointerType.Float, 32, 12 );
GL.NormalPointer( NormalPointerType.Float, 32, 20 );
GL.DrawArrays( BeginMode.Triangles, 0, verticesCount );
GL.BindBuffer( BufferTarget.ArrayBuffer, 0 );
[/csharp]
Trying to set up SFML on VS C++ 2010. I'm supposed to use the VC++ Directories page in the options of VS, but it just says it's deprecated instead of giving me what 2008 would have. Then it says to do it from a 'User property sheet' and to click the '?' for more information. The '?' leads to an absolutely useless page that explains how to use the now nonexistent function instead of providing an alternative.
[QUOTE=ManningQB18;36407435]Trying to set up SFML on VS C++ 2010. I'm supposed to use the VC++ Directories page in the options of VS, but it just says it's deprecated instead of giving me what 2008 would have. Then it says to do it from a 'User property sheet' and to click the '?' for more information. The '?' leads to an absolutely useless page that explains how to use the now nonexistent function instead of providing an alternative.[/QUOTE]
You have to set these things per project now. In 2008 you set them for all projects.
So I've had this problem with C++0x in gcc:
It had let me assign an initialization list to an array, like so
[code]
double[5] vals;
vals = {-10, 0, 5, 10};[/code]
I had come to rely on this way of assigning values to an array because it's neat to write and I can do it at any time (not just during declaration/initialization).
But now I've updated gcc it's telling me that it's illegal. I.e.
[code]
error: assigning to an array from an initializer list.
[/code]
I has sads now. What should I do?
[QUOTE=Nikita;36409038]So I've had this problem with C++0x in gcc:
It had let me assign an initialization list to an array, like so
[code]
double[5] vals;
vals = {-10, 0, 5, 10};[/code]
I had come to rely on this way of assigning values to an array because it's neat to write and I can do it at any time (not just during declaration/initialization).
But now I've updated gcc it's telling me that it's illegal. I.e.
[code]
error: assigning to an array from an initializer list.
[/code]
I has sads now. What should I do?[/QUOTE]
[code]glm::vec4 vars(-10,0,5,10);
std::vector<double> vars(-10,0,5,10);[/code]
?
[editline]asdf[/editline]
And I'm pretty sure
[code]double vars[] = { -10,0,5,10};[/code]
is legal as well.
That's a declaration though.
Gcc currently says "sorry, unimplemented" when I try to do that when declaring an array inside a class. I would prefer to just use ordinary arrays instead of vectors (since they're fixed length and I use a lot of them). Being able to = {1,2,3} after the array has already been used for some time (not just when declaring) was nice too.
[QUOTE=Nikita;36409532]That's a declaration though.
Gcc currently says "sorry, unimplemented" when I try to do that when declaring an array inside a class. I would prefer to just use ordinary arrays instead of vectors (since they're fixed length and I use a lot of them). Being able to = {1,2,3} after the array has already been used for some time (not just when declaring) was nice too.[/QUOTE]
What you've been doing must have been some unofficial extension then, because even the C++0x standard only allows this with std::vector.
[cpp]std::vector<int> array = { 1, 3, 34, 5, 6 };
array = { 34, 2, 4, 5, 6 };[/cpp]
Posted this in the webdev forum but applies to general programming aswel. Would like you to give your opinion on certificates.
[url]http://facepunch.com/showthread.php?t=1191951[/url]
Sorry, you need to Log In to post a reply to this thread.