Slushy

Members
  • Content count

    17
  • Joined

  • Last visited

Community Reputation

168 Neutral

About Slushy

  • Rank
    Member
  1. Diffuse Lighting, GLSL.

    I solved it, it's kinda embarassing. I had the offset wrong in my interleaved vbo. It gathered the wrong normals and that messed it up.
  2. Diffuse Lighting, GLSL.

    Hello, im back again with another question. So I've been working on diffuse lighting for a couple of days now and I can't seem to get it working properly. I get the feeling that there is something messed up with my direction/position Vector of the light. But I can't seem to figure out what. Either way, here are my shaders: VertexShader.glsl #version 330 uniform mat4 perspectiveMatrix; uniform mat4 viewMatrix; uniform mat4 modelMatrix; layout(location = 0) in vec3 in_Position; layout(location = 1) in vec2 in_TextureCoord; layout(location = 2) in vec3 in_Normal; out vec2 frag_TextureCoord; out vec3 normal; void main(void){ gl_Position = perspectiveMatrix * viewMatrix * modelMatrix * vec4(in_Position, 1.0); normal = mat3(modelMatrix) * in_Normal; normal = normalize(normal); frag_TextureCoord = in_TextureCoord; } FragmentShader.glsl #version 330 uniform sampler2D texture_diffuse; uniform vec3 lightPosition; uniform vec3 lightColor; uniform float lightPower; in vec2 frag_TextureCoord; in vec3 normal; out vec3 out_Color; void main(void){ float lightIntensity; vec3 lightDir; lightDir = -lightPosition; lightIntensity = clamp(dot(normal, lightDir), 0.0f, 1.0f); out_Color = clamp((lightColor * lightIntensity), 0.0f, 1.0f); out_Color = out_Color * texture(texture_diffuse, frag_TextureCoord).rgb; } My position/direction vector that I send to my fragment shader in the uniform is: 0, -1, 0 and what I get is this:
  3. XMVECTOR and XMMATRIX in header?

    This helped me alot! I bet there is a more correct way, or even more efficient. But I simpy solved it with #define _XM_NO_INNTRINSICS_ Seemed to be alot easier for me, anything that would make this way of doing things more complicated or even wrong? Seemed to have solved my problem for now though.
  4. Hello! So I've been struggling with getting XMVECTOR and XMMATRIX working when defined in my header file. If I do: XMMATRIX World; XMVECTOR camPosition; in the header file for example, and then do: camPosition = XMVectorSet( 0.0f, 0.0f, -0.5f, 0.0f ); in my .cpp file, for example. It gives me an "access violation" error. I read that this is because of some kind of alignment thingy? Is there no way to get the XMVECTOR or XMMATRIX defined in the header file and then use it in the .cpp file?   If not, what should I do instead? Because defining them in the .cpp file works, but that looks so bad? Any other solutions, what do you guys do?
  5. OpenGL Camera Up Problem.

    I'll use  this as a bump post and hope that somebody answers me again. My problem didn't get solved.. I posted my earlier post to fast. My problem still exists unfortunately..   Here is my Camera class. http://pastebin.com/UmRvTrQN (NOTE: This is modified to be moving "correct", pressing D makes me go right and pressing A goes left etc. Though it shouldn't.. really..?)   Hope somebody can solve this for me.. Feels like I've tried everything. Ofcourse I could just move the camera in the opposite direction that it's supposed to be moved. But I want it to be correct.
  6. OpenGL Camera Up Problem.

    Well, stupid me. I had just set the View Matrix to Identity and thought that'd take care of it. Obviously that was not correct, I used this to setup a View Matrix and now it works like a charm!   Thanks!
  7. OpenGL Camera Up Problem.

    Hello! So I recently went from OpenGL 2.X (using now deprecated functions like, glTranslate etc.) to using OpenGL 3.2. This also meant implementing matrices manually for all of my transformation. While this is extremely fun and very enjoyable, it's hard.   My problem is that when I move my Camera (Viewmatrix) in the +Y direction, my OBJ that I loaded into my game is moving upwards (hence im moving the camera "downwards" relative to the object). This also affects moving in +/- X. + Goes left, - Goes right.   Why is it that I have this problem? I've checked my Projectionmatrix and it seems to be correct, according to http://ogldev.atspace.co.uk/www/tutorial12/12_11.png   Projectionmatrix perspectiveMatrix.setIdentity(); float aspectRatio = WIDTH / HEIGHT; float zRange = zNear - zFar; perspectiveMatrix.m00 = (float) (1.0f / (aspectRatio * Math.tan(degreesToRadians(fieldOfView / 2.0f)))); perspectiveMatrix.m11 = (float) (1.0f / (Math.tan(degreesToRadians(fieldOfView / 2.0f)))); perspectiveMatrix.m22 = (-zNear - zFar) / zRange; perspectiveMatrix.m23 = 1; perspectiveMatrix.m32 = (2 * zFar * zNear) / zRange;     Modelmatrix is Identity.   Viewmatrix is changed when I move: if(moveUp) Matrices.viewMatrix.translate(new Vector3f(0, 1.0f * moveSpeed, 0)); if(moveLeft) Matrices.viewMatrix.translate(new Vector3f(-1.0f * moveSpeed, 0, 0)); if(moveDown) Matrices.viewMatrix.translate(new Vector3f(0, -1.0f * moveSpeed, 0)); if(moveRight) Matrices.viewMatrix.translate(new Vector3f(1.0f * moveSpeed, 0, 0));     Vertex Shader: #version 330 uniform mat4 perspectiveMatrix; uniform mat4 viewMatrix; uniform mat4 modelMatrix; layout(location = 0) in vec3 position; out vec4 color; void main(){ gl_Position = perspectiveMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); color = vec4(position, 1.0); }     All sources: http://pastebin.com/yZExLWpp - Window.java http://pastebin.com/yBRcdnRK - Matrices.java http://pastebin.com/mJa1j5ri - Camera.java http://pastebin.com/UM7BQdrR - Cube.java   Tell me if you need more. I don't believe you should though.   Thanks!, Slushy.  
  8. What objects do I use matrices for?

    [quote name='Khatharr' timestamp='1352577261' post='4999709'] The three transforms: .... [/quote] Wow, yet again. That is extremely helpful! I can't believe the help im getting out of this forum, greatly appreciated. Thanks again! [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]
  9. What objects do I use matrices for?

    That is really helpful, thanks alot! I'll have to read up on some further stuff regarding world/local/image coordinates but thanks again!
  10. So, I've been looking alot into matrices lately. I understand all the "math-parts" regarding multiplying, adding them together and all that stuff. What I can't seem to get a grasp of is when do I use them correctly? I know that they are very effective when it comes to camera's. But do I also use them for models? So that I have a position vector and a rotation vector, load them into a Float buffer and do glLoadMatrix('floafbuffer'); for every model/object that I want to render aswell? Or do I not need to use matrices for theese stuff? If so, what do I use them for? Only cameras? Im using Java with OpenGL btw. (LWJGL) EDIT: I accidentaly posted this in Math and Physics, I meant to post it in "For Beginners". So if any moderator sees this, could you please move it? Thanks!
  11. different way of learning

    [quote name='burnt_casadilla' timestamp='1351629847' post='4995567'] oh crap. im completely hopeless when it comes to creating classes. I know how they work and how to call methods from in them but the bulk of the code confuses me [/quote] Then I'd recommend doing alot of testing and trying different approaches. Simply messing around with classes, [b]before[/b] you go and start making games. Classes are an essential part of games/programming overall. No point in rushing making games when you have to learn the basics first, I know it sucks. But sometimes life does.[img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
  12. different way of learning

    [quote name='burnt_casadilla' timestamp='1351617301' post='4995487'] the only thing i could think of is creating an array for storing bullets, lets say there can be 10 on the screen at a time. and whenever spacebar is pressed, create a bullet at shipPos.X and shipPos.Y, and send the bullet straight up by subracting its y value. i guess my problem is that i really only know one side to doing things. I have a hard time thinking of different ways to program if my first option doesnt work because I get stuck in a loop trying to fix something that might not even work at all [/quote] That'll work just fine. Just keep checking it for collisions and when it goes outside of the playing area (screen) remove it from the array (This could be done using null). Making it possible to shoot another bullet.
  13. First person camera

    [quote name='Faelenor' timestamp='1351617215' post='4995486'] Yes, you have to reset the matrix to identity before applying a new transformation, otherwise, you're applying the same operation over and over. [/quote] But I get the feeling that this isnt the most effective way of doing it? Since glLoadIdentity(); moves it back to the origin again. I have to move it back to the position I want it in every single frame. Shouldn't there be a way to only move the camera when I tell it to do so, with my WASD keys?
  14. First person camera

    Hello! Im trying to create a first person camera, and I've been successful in understanding how to do so thus far. I've read up on alot of vector math and matrix stuff and I know the basics. Although I got a few problems when I try to implement it into my code. I have 3 main vectors, which are position, direction and up. I am trying to use [CODE] glTranslatef(x, y, z); [/CODE] to update my camera-position, but Im not a 100% sure on what values I want to update it with. If I keep updating with my position vector, like so: [CODE] glTranslatef(position.x, position.y, position.z); [/CODE] I will keep moving in one direction, even if im not pressing any buttons. (Moving in the direction that the results of all three values in the position vector will be.) I've been able to work around this by using [CODE] glLoadIdentity(); [/CODE] In the main loop, before I do all the translating. Is this the correct way of doing it? Or do I add another vector and translate with that one? Im a bit of a perfectionst, and I want to do it correctly the first time. So I don't have to relearn! Thanks! I hope im clear enough on what my problem is, I'll be happy to post my sourcecode if you really need it, I felt like it was a bit unnecessary though.
  15. Hello! First of all im writing this from my phone, so im sorry for any big grammar mistakes. My name is Simon and im 17 years old (18 in august). Im from Sweden aswell, but since we're on the forums I prefer typing english. To not upset anyone anyhow, I just started game programming in C++, but ive been programming in java for a while. Now im looking into creating a voxel rendering engine. For learnig purposes. Using raytracing probably or i might try converting them to polygons and render them that way aswell. My point is, that I could use someone to ask if Im not a 100% sure what to read up on. Btw talking/chatting in skype is not a problem at all. Happy holidays!