• Content count

  • Joined

  • Last visited

Community Reputation

140 Neutral

About TheFearlessHobbit

  • Rank

Personal Information

  • Location
    Central Auckland, New Zealand
  • Interests
  1. Fixed it, thank you all very much for your help. 
  2. I tried setting up an orthographic projection as you suggested like so: m_Projection = glm::ortho(PlayerXCoord - 800.0f / 2.0f, PlayerXCoord + 800.0f / 2.0f, PlayerYCoord - 600.0f / 2.0f, PlayerYCoord + 600.0f / 2.0f, -1.0f, 1.0f); It seems to be working but my scene is so far away from the camera I can hardly see it. It's a mere pixel.  
  3. Why of course I tried that :)   Ultimately, this is what I tried to do: extern float PlayerXCoord; extern float PlayerYCoord; float PlayerZCoord = -1.0f; glm::vec3 PlayerPosition(PlayerXCoord, PlayerYCoord, PlayerZCoord); CCamera::CCamera() : m_ViewDirection(0.0f, 0.0f, -1.0f), m_Position(0.0f, 0.0f, 0.0f) {} CCamera::~CCamera() {} glm::mat4 CCamera::GetViewToWorldMatrix() const { return glm::lookAt(m_Position, m_Position + PlayerPosition, glm::vec3(0.0f, 1.0f, 0.0f)); }
  4. Hey everybody, I recently just setup my camera scene: Camera Class class Camera { public: Camera(); ~Camera(); glm::mat4 GetViewToWorldMatrix() const; private: glm::vec3 m_Position; glm::vec3 m_ViewDirection; }; Definition: Camera::Camera() : m_ViewDirection(0.0f, 0.0f, -1.0f) // Always look in the negative z {} Camera::~Camera() {} glm::mat4 Camera::GetViewToWorldMatrix() const { return glm::lookAt(m_Position, m_Position + m_ViewDirection , glm::vec3(0.0f, 1.0f, 0.0f)); } Obviously by adding the position vector of the camera with the view direction vector, that will return the lookAt. After that I'm simply multiplying the projection matrix with the ViewToWorld matrix and it's working fine, I can see my whole scene. However, I'm trying to make it so that the camera only follows one object in my scene. How can I achieve this?     Thank you for your help.  :)
  5. Hello, why don't you try picking up a book instead  :) Here's a book I found very helpful when I started learning AI: Programming Game AI by Example (Click) It teaches you a lot of things including dijkstra's algorithm with A*. The author provides plenty of examples for you to follow as well.  If you're not looking to spend money on books, then you could try the articles on this site, some of them are really good even for beginners. :)  
  6. OpenGL

    Oh, what a silly mistake. Thank you for pointing that out I can see my texture now! I'll try to pay more attention to my arguments from this point on to make sure they are all consistent.  Thank you once again for your help. :)  
  7. Hey guys, back with another newbie question.  :(    I'm trying to create a simple 2D platform game in an attempt to learn and discover more things about OpenGL. Basically, I have created a quad that fits the entire window and now I would like to texture it so that it looks like a background. However, I can't seem to be able to get it to work as I keep getting an access violation error.    Here's some relevant parts of my code I hope you find useful:   Global variables GLuint g_texture = 0; int iWidth, iHeight;     Startup function: { // ... glewinit, shader creation, vertices and color creation etc...   GLfloat Texture[] = { 0.0f, 0.0f,  // Top Left 1.0f, 0.0f,  // Top Right 1.0f, 1.0f,  // Bottom Right 0.0f, 1.0f   // Bottom Left };   //... buffer generations etc...   glGenTextures(1, &g_texture); glBindTexture(GL_TEXTURE_2D, g_texture); glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0);   unsigned char* image = SOIL_load_image("adventure.png", &iWidth, &iHeight, 0, SOIL_LOAD_RGB); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iWidth, iHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   glGenerateMipmap(GL_TEXTURE_2D);   SOIL_free_image_data(image);   glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); }   Render function   void Render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);   glUseProgram(program); glBindTexture(GL_TEXTURE_2D, g_texture); glBindVertexArray(vao); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, 0);  glBindVertexArray(0);   glutSwapBuffers(); }   And lastly, here are my shaders:   Vertex Shader   #version 430 core   in layout (location = 0) vec3 VertexPos; in layout (location = 1) vec4 VertexColors; in layout (location = 2) vec2 TextureCoord;   out vec4 outputColors; out vec2 TexCoord;   void main() { gl_Position = vec4(VertexPos, 1.0f); outputColors = VertexColors; TexCoord = vec2(TextureCoord.x, TextureCoord.y); }   Fragment Shader   #version 430 core   // Inputs in vec4 outputColors; in vec2 TexCoord;   // Output Color out vec4 VertexColors;   uniform sampler2D Texture;   void main() { VertexColors = texture(Texture, TexCoord) * outputColors; //VertexColors = outputColors; }   I hope someone could point out where I'm going wrong with this.   Thank you very much for reading my thread. All help is greatly appreciated.  :)
  8. OpenGL

    Problem fixed. (Woo!) For whoever's interested, I simply created another VBO which contains the new color data and inside my fragment shader I created a timer to alternate between both outputs using if-else statements every 1 or 2 seconds. However, I sort of lost my glowing effect that way but at least I got my multi-colored vertices that change overtime. I'll work on getting some glowing effects going on.  Thank you to whoever read my post and tried to help me out.  :)
  9. Hello everyone, I am a new registered user.  I have just started learning OpenGL 2 weeks ago and I come from a WIN32 API background. To cut straight to the chase, I have a Hexagon drawn like this:  GLfloat vertices[] = { -0.25f, -0.5f, 0.0f,  1.0f, 0.0f, 0.0f,   // Red                        0.25f, -0.5f, 0.0f,  0.0f, 1.0f, 0.0f,   // Green                         0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f ,   // Blue                         0.25f, 0.5f, 0.0f,  1.0f, 0.0f, 1.0f,    // Purple                         -0.25f, 0.5f, 0.0f,  1.0f, 1.0f, 1.0f,   // White                         -0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f     // Yellow }; Here are my shaders:  Vertex Shader #version 430 core layout (location = 0) in vec3 position;  layout (location = 1) in vec3 color; layout (location = 2) in vec3 newColor; //Er... what to do?! uniform mat4 _resultantMatrix; out vec3 outputColor; void main()  {  vec4 currentPos = vec4(position, 1.0f); gl_Position = _resultantMatrix * currentPos; outputColor = color; }; Fragment Shader #version 430 core in vec3 outputColor; out vec4 Color; uniform float Timer; void main() {    vec3 tempColor = outputColor * abs(sin(Timer));    tempColor.x = (sin(Timer) / 2) + 0.5f; //   tempColor.y = (cos(Timer) / 2) + 0.5f; Not doing what I expect it to do.    Color = vec4(tempColor, 1.0f);  }; The result is a multi-colored hexagon. However, I want my hexagon's vertices to glow, that is essentially what I am going for. I have a uniform float Timer that fades in and out quite smoothly. Though, every time I execute my program, it looks like only 2 or 3 vertices change color, while the others stay the same. I think I know what the issue here is, it has something to do with the fact that I am storing all my colors in the same VBO.    glGenBuffers(1, &vao); glBindVertexArray(vao); glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);   glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));   // glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(21 * sizeof(GLfloat))); Stores the data in layout 2 but don't know what to do after! glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); // glEnableVertexAttribArray(2); So like in my fragment shader, when I go tempColor.x = blahblahblah; it's changing more than one vertex color. If anyone could help me out I'd greatly appreciate it as I have been stuck for 2 hours trying to figure this thing out. I want all my vertices to have different colors while the program is being executed, and so far only 3 vertices change while the other 3 stays the same.    Thank you very much!