Jump to content

  • Log In with Google      Sign In   
  • Create Account

povilaslt2

Member Since 14 Jul 2011
Offline Last Active Nov 22 2015 09:51 AM

Topics I've Started

Help to review my first harder game

19 September 2015 - 02:08 AM

Hello, so today I just finished my first harder game and I want to experienced programmers try to review my code and say what's wrong and try to advice me what to do better.

 

Here's the source and game.

https://github.com/Povilas-Jablonskis/SideScroller/

 

Controls:

w for jump, climb up.

s for crouch, climb down.

a for walk left, climb.

d for walk right, climb.

mouse1 to jump( mouse must be higher than player's sprite )

ESACAPE to PAUSE

 

Objective is to reach the end sign.

 

Thanks for advance.


Help to review my first harder game

18 September 2015 - 05:02 AM

Hello, so today I just finished my first harder game and I want to experienced programmers try to review my code and say what's wrong and try to advice me what to do better.

 

Here's the source and game.

https://github.com/Povilas-Jablonskis/SideScroller/

 

Controls:

w for jump, climb up.

s for crouch, climb down.

a for walk left, climb.

d for walk right, climb.

mouse1 to jump( mouse must be higher than player's sprite )

ESACAPE to PAUSE

 

Objective is to reach the end sign.

 

Thanks for advance.


VBO with shader not working

06 January 2015 - 04:27 AM

Hello, i'm having problem. I setup shaders and etc. like it have to be but when I render them nothing shows.

// transformation, rotation and scale shader
std::string vertSource =
"#version 330 core\n"
"in vec3 in_vertex;"
"uniform mat4 modelview;"
"uniform mat4 projection;"
    "void main()"
    "{"
    "   vec4 v = vec4( in_vertex, 1.0 );"
    "	gl_Position = projection * modelview * v;"
    "}";

    // basic fragment shader source
    std::string fragSource =
    "#version 330 core\n"
    "uniform vec4 color;"
    "void main()"
    "{"
    "       gl_FragColor = color;"
    "}";

Passing projection and modelview matrix to shader:

    GLfloat modelview[16];
    GLfloat projection[16];

    glGetFloatv(GL_MODELVIEW_MATRIX, modelview);
    glGetFloatv(GL_PROJECTION_MATRIX, projection);

    int offsetLocation10 = glGetUniformLocation(program, "modelview");
    int offsetLocation11 = glGetUniformLocation(program, "projection");

    glUniformMatrix4fv(offsetLocation10, 1, GL_FALSE, modelview);
    glUniformMatrix4fv(offsetLocation11, 1, GL_FALSE, projection);

Setting up view:

static void resize(int width, int height)
{
    //const float ar = (float) width / (float) height;

    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0, width, 0.0, height, -1, 1);
    glMatrixMode(GL_MODELVIEW);
}

One interesting thing is when I replace projection matrix with position it works but don't know if it's right.. ( I think not )


Scale, Translate object glsl

01 January 2015 - 12:18 PM

Hi all. How do I move and scale object. Can someone give an matrix example.

I have this peace of code:

// transformation, rotation and scale shader
std::string vertSource =
"#version 330 core\n"
"in vec4 position;"
"uniform vec2 animsc;"
"uniform vec2 position2;"
"uniform vec2 objsize;"
"uniform vec2 winsize;"
"uniform float timer = 0;"
"attribute vec4 texCoord;"
"varying vec2 texCoordV;"
"uniform vec2 curranim;"
"uniform mat4 modelview;"
"uniform mat4 projection;"
"void main()"
"{"
"   texCoordV = vec2(texCoord);"
"	texCoordV.x /= animsc.x;"
"	texCoordV.x += (curranim.x/animsc.x);"
"	texCoordV.y /= animsc.y;"
"	texCoordV.y += (curranim.y/animsc.y);"
"	gl_Position = position * projection * modelview;"
"}";

Everything I do all wrong, can't solve this problem. To find matrix to scale and move object.

When I try to scale object with this matrix:

"   mat4 scale = mat4("
"       vec4(   16/9, 0.0, 0.0, 0.0),"
"       vec4(   0.0, 1.0, 0.0, 0.0),"
"       vec4(   0.0, 0.0, 1.0, 0.0),"
"       vec4(   0.0, 0.0, 0.0, 1.0)"
"   );"

It rotates when It needs to scale.


Texture issue with different PC's

30 December 2014 - 02:20 PM

Hi all, so i'm having issue with texturing objects. When I texture object and run on my PC all is ok, but when I run same problem on other PC something weird happends. Can you help me? It's 100% problems with textures I think..

 

How it should be:

213rdzq.png

 

That's how game displays on other PC:

102ji12.png

 

I'm using shaders to render all objects and etc.


float triangle[18] =
{
    // Left bottom triangle
    -1.0, 1.0, 0.0,
    -1.0, -1.0, 0.0,
    1.0, -1.0, 0.0,
    // Right top triangle
    1.0, -1.0, 0.0,
    1.0, 1.0, 0.0,
    -1.0, 1.0, 0.0
};

float texture[12] =
{
    // Right top triangle
    0.0, 1.0,
    0.0, 0.0,
    1.0, 0.0,
    // Left bottom triangle,
    1.0, 0.0,
    1.0, 1.0,
    0.0, 1.0
};
// transformation, rotation and scale shader
std::string vertSource =
"#version 330 core\n"
"in vec2 position;"
"uniform vec2 animsc;"
"uniform vec2 position2;"
"uniform vec2 objsize;"
"uniform vec2 winsize;"
"uniform float timer = 0;"
"attribute vec4 texCoord;"
"varying vec2 texCoordV;"
"uniform vec2 curranim;"
"void main()"
"{"
"   texCoordV = vec2(texCoord);"
"	texCoordV.x /= animsc.x;"
"	texCoordV.x += (curranim.x/animsc.x);"
"	texCoordV.y /= animsc.y;"
"	texCoordV.y += (curranim.y/animsc.y);"
"   vec2 scale = ( objsize / winsize );"
"   vec2 trans3 = ( ( position2 * vec2( 2.0, 2.0 ) ) / winsize ) + vec2( -1.0, -1.0 );"
"   trans3 += ( objsize / winsize );"
"   vec4 test = vec4( ( position * scale ) + trans3, 0.0, 1.0 );"
//Rotation
"   test.xy *= "
"   mat2"
"   ("
"       vec2( cos( timer ),  -sin( timer )),"
"       vec2( sin( timer ),  cos( timer ))"
"   );"
"	gl_Position = test;"
"}";

// basic fragment shader source
std::string fragSource =
"#version 330 core\n"
"out vec4 out_color;"
"uniform sampler2D textureMap;"
"varying vec2 texCoordV;"
"uniform vec4 color = vec4(0.0,1.0,0.0,1.0);"
"uniform float text = 0;"
"void main()"
"{"
"   if( text == 1 )"
"       out_color = texture2D(textureMap, texCoordV);"
"   else"
"       out_color = color;"
"}";

PARTNERS