Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


povilaslt2

Member Since 14 Jul 2011
Online Last Active Today, 01:03 PM

Topics I've Started

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;"
"}";

Bad texture mapping

13 December 2014 - 06:09 AM

Hello, i'm having an issue. I'm trying to render this texture, but when I did my texture was shown incorrectly.

 

FPwmk.png

 

Result:
20r3hxh.png

As you see my other sprites are shown correctly but not this one, where the problem?

 

Vert shader:

std::string vertSource =
"#version 330 core\n"
"in vec2 position;"
"uniform vec2 trans = vec2(1.0,1.0);"
"uniform vec2 trans2 = vec2(0.0,0.0);"
"uniform vec2 objsize;"
"uniform vec2 winsize;"
"uniform float timer = 0;"
"attribute vec4 texCoord;"
"varying vec2 texCoordV;"
"void main()"
"{"
"   texCoordV = vec2(texCoord);"
//"	texCoordV.x /= 3;"
//"	texCoordV.x += (1.0f/3);"
//"	texCoordV.x *= 2;"
"   vec2 trans3 = ( ( trans2 * vec2( 2.0, 2.0 ) ) / winsize ) + vec2( -1.0, -1.0 );"
"   trans3 += ( objsize / winsize );"
"   vec4 test = vec4( ( position * trans ) + trans3, 0.0, 1.0 );"
"   test.xy *= "
"   mat2"
"   ("
"       vec2( cos( timer ),  -sin( timer )),"
"       vec2( sin( timer ),  cos( timer ))"
"   );"
"	gl_Position = test;"
"}";

Frag shader:

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


Render part of texture with shader

30 November 2014 - 03:16 AM

Hello, how do I render just part of texture using shaders. In example I have texture:

 

28s6n43.png

 

 

And I want to render just 1 sprite from spritesheet.

 

Here's my shaders:

Vertex:
 

std::string vertSource =
"#version 330 core\n"
"in vec2 position;"
"uniform vec2 trans = vec2(1.0,1.0);"
"uniform vec2 trans2 = vec2(0.0,0.0);"
"uniform vec2 objsize;"
"uniform vec2 winsize;"
"uniform float timer = 0;"
"in vec2 texCoord;"
"out vec2 texCoordV;"
"void main()"
"{"
"   texCoordV = texCoord;"
"   vec2 trans3 = ( ( trans2 * vec2( 2.0, 2.0 ) ) / winsize ) + vec2( -1.0, -1.0 );"
"   trans3 += ( objsize / winsize );"
"   vec4 test = vec4( ( position * trans ) + trans3, 0.0, 1.0 );"
"   test.xy *= "
"   mat2"
"   ("
"       vec2( cos( timer ),  -sin( timer )),"
"       vec2( sin( timer ),  cos( timer ))"
"   );"
"	gl_Position = test;"
"}";

Fragment:
 

std::string fragSource =
"#version 330 core\n"
"out vec4 out_color;"
"uniform sampler2D textureMap;"
"in vec2 texCoordV;"
"uniform float text = 0;"
"void main()"
"{"
"   if( text == 1 )"
"   {"
"       vec2 a = texCoordV;"
"       a.x = 0.335;"
//"       float time = mod(0.5, 9.0f);"
//"       a.x += (1.0f*floor(time)/9);"
"       out_color = texture2D(textureMap, texCoordV);"
"   }"
"   else"
"       out_color = vec4(0.0,1.0,0.0,1.0);"
"}";

PARTNERS