• Create Account

# FantasyVII

Member Since 13 Jul 2012
Offline Last Active Yesterday, 06:24 AM

### casting double* to float*

17 March 2016 - 03:09 PM

Hi,

So i have this function that looks like this:-

```glfwGetCursorPos(_IN_ GLFWwindow *window, _OUT_ double *x, _OUT_ double *y);

```

what it basically does is spit out the mouse position from the x and y arguments.

so if you do something like this, it works fine.

```double x = 0.0f, y = 0.0f;
glfwGetCursorPos(window, &x, &y);

std::cout << x << " " << y << std::endl;
```

However if I try this, I get a value of zero. I don't know why.

```float x = 0.0f, y = 0.0f;
glfwGetCursorPos(window, (double*)&x, (double*)&y);

std::cout << x << " " << y << std::endl;
```

### My cube is deformed. Did I mess up my perspective matrix?

02 March 2016 - 06:14 PM

Hello,

I implemented my own math library so I can understand computer graphics math better. But I think I didn't implement my perspective matrix correctly. I think my white cube is deformed.

My view matrix which is my camera, only translate everything by Vector3(0.0f, 0.0f, -2.0f). My red cube is at Vector3(0.0f, 0.0f, 0.0f). My white cub is translated by Vector3(2.0f, 0.0f, 0.0f).

Here is my perspective matrix implementation.

```Matrix4 Matrix4::Perspective(const float FieldOfView, const float AspectRatio, const float Near, const float Far)
{
Matrix4 PerspectiveMatrix = Matrix4::Identity();

float t = 1.f / tan(ToRadians(FieldOfView / 2));

//MATRIX_SIZE = 4
PerspectiveMatrix.Elements[0 + 0 * MATRIX_SIZE] = t / AspectRatio;
PerspectiveMatrix.Elements[1 + 1 * MATRIX_SIZE] = t;
PerspectiveMatrix.Elements[2 + 2 * MATRIX_SIZE] = (Near + Far) / (Near - Far);
PerspectiveMatrix.Elements[3 + 2 * MATRIX_SIZE] = -1.f;
PerspectiveMatrix.Elements[2 + 3 * MATRIX_SIZE] = (2.f * Near * Far) / (Near - Far);

return PerspectiveMatrix;
}
```

### Black screen when trying to implement ibo

23 February 2016 - 08:43 PM

Hello,

I'm trying to learn OpenGL 4.5 and so far it's going great. I drew a cube with a simple vertex buffer and it worked. Now I'm trying to implement index object buffer but it's not working. I see nothing on the screen and for the life of me I can't figure out why.

Here is my code.

```#include "Renderer.h"

namespace blk
{

{
}

Renderer::~Renderer()
{
}

void Renderer::Initialize()
{
glClearColor(0, 0, 0, 0);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);

const GLfloat VertexBufferData[] =
{
-1.000000f, -1.000000f,  1.000000f,
-1.000000f,  1.000000f,  1.000000f,
-1.000000f, -1.000000f, -1.000000f,
-1.000000f,  1.000000f, -1.000000f,
1.000000f, -1.000000f,  1.000000f,
1.000000f,  1.000000f,  1.000000f,
1.000000f, -1.000000f, -1.000000f,
1.000000f,  1.000000f, -1.000000f
};

const GLfloat IndexBufferData[] =
{
3, 2, 0,
7, 6, 2,
5, 4, 6,
1, 0, 4,
2, 6, 4,
7, 3, 1,
1, 3, 0,
3, 7, 2,
7, 5, 6,
5, 1, 4,
0, 2, 4,
5, 7, 1
};

glCreateBuffers(1, &VertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(VertexBufferData), VertexBufferData, GL_STATIC_DRAW);

glCreateBuffers(1, &IndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(IndexBufferData), IndexBufferData, GL_STATIC_DRAW);

ModelMatrix = blk::Math::Matrix4::Translation(blk::Math::Vector3(0.f, 0, -2.0f));
ProjectionMatrix = blk::Math::Matrix4::Perspective(90.f, 800.f / 600.f, 1.f, 100.f);
}

{
}

void Renderer::Update()
{
angle = time.GetTotalTime() * 32;
}

void Renderer::Draw()
{
glUseProgram(ProgramID);

shader.SetUniformMatrix4(ProgramID, "ModelMatrix", blk::Math::Matrix4::Rotation(angle, blk::Math::Vector3(0, 1, 0)) * ModelMatrix);

glEnableVertexAttribArray(0);

glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBuffer);
glDrawElements(GL_TRIANGLES, 12 * 3, GL_UNSIGNED_INT, (void*)0);

glDisableVertexAttribArray(0);
}

void Renderer::Clear()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
}
```

```#version 450 core
layout(location = 0) in vec3 inPosition;
//layout(location = 1) in vec3 vertexColor;

out vec4 fragmentColor;

uniform mat4 ModelMatrix;
uniform mat4 ProjectionMatrix;

void main()
{
gl_Position = ProjectionMatrix * ModelMatrix * vec4(inPosition, 1);
fragmentColor = vec4(1.0, 0, 0, 1.0);
}
```

```#version 450 core

in vec4 fragmentColor;
out vec4 OutputColor;

void main()
{
OutputColor = fragmentColor;
}
```

### glGen.* vs glCreate.*

19 February 2016 - 11:18 AM

Hello,

So I'm learning OpenGL 4.5 for the first time. Can someone please explain what is the difference between glGen.* and glCreate.* and when should I use one rather than the other?

for example:-

glGenBuffers vs glCreateBuffers

or

glGenVertexArrays vs glCreateVertexArrays

thanks.

### Find all paths in a single iteration?

14 January 2016 - 04:50 PM

Hello everyone,

So I'm making a randomly generate dungeon game, and I'm using A* to find the shortest path between rooms so every room is connected by a corridor.

So lets say I have 500 rooms. All 500 rooms need to be connected to each other. That means I need to find the shortest path between all rooms and connect them by a corridor. So what I do is I run A* algorithm 500 times to find a path for each room. lets say the time it takes for A* to find a path is 100ms. so that's 500 * 100ms = 50,000 ms or 50 seconds. Now in my engine I have A* multi-threaded. So I can run multiple threads to find the paths at the sometime. Lets say I make 6 threads. So now the math will be something like this. (500 rooms * 100ms ) / 6 threads = 8,333ms or ~8 seconds. That is a long time. I'm aiming for max of 5 seconds. On my machine I can get it to find all paths in ~2 seconds or even less. But i'm running a 6 core 3930k clocked at 5GHz, On a low end machine like a 2 core cpu that will take forever.

So what I'm wondering, is there an algorithm where I only run it once and it scans the entire grid and find a path for each room?

Thanks !

PARTNERS