Sign in to follow this  

OpenGL homemade engine issues

This topic is 4240 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi! this is my first post here, though i have been looking around and gleaming info for a while now (much thanks there!). :) so, the reason i have been floating around here trying to glean info is because i would like to build a 3d engine using opengl and have had some issues. well, my friend and i finally got to the point where we can move around using wasd and looking around with a mouse. however, we have run into two issues that concern us. 1. when moving with the keyboard alone everything looks find. when looking around with the mouse alone everything looks fine. however, when we move (left and right are the most pronounced, though surely forward and backward do it too but aren't as visible) and rotate the view with the mouse, normal mouse look like in an fps is the goal, we have an issue where the objects appear to be oscilating from one spot to another. i'm not sure how to describe this, but it is like the computer is rapidly flipping a childs flipbook and the pictures drawn aren't lining up so it seems to vibrate. originally we thought this was due to having a PostRedisplay call for the keyboard call back and the passive mouse motion call back. so to remedy that we looked around online and saw that different places were using the timer call back and doing the redisplay in there. so we are now doing that too, however we are still experiencing the same issue. also, online we noticed that most people suggest moving the world around the camera in the opposite direction that the input states (so to move left move the world right, etc etc). however, we started and still are doing it so that the actual eye position is the one moving and not the rest of the world. my questions on this are -- has anyone ever experienced this before, and if so how did you solve the issue? also, is it vital to move the world around the eye as opposed to the eye through the world? 2. my second major issue with the engine (that i know of :) ) is that when i press down on the keyboard to move there is a stutter before the movement starts. so, for example, if the eye is stationary (no translation or rotation occuring) and then i push 'w' to move forward, there is a slight move forward and a pause and then continuous movement until the key is released. this occurrs for all four directions (forward, backward, right, and left) but not for mouse look. my question is pretty much the same as before -- has anyone ever experienced anything like this before and if so, how did you solve the issue? i know i haven't posted any code here, but that is because the faq said not to be a "fix this for me" kind of person. :) i have done lots of searching online and tried to find a tutorial or paper or anything on how to effectively create a mouse look system, but haven't been very successful, only tutorials on how to get the mouse location. about the most useful mouse info i have found is how to warp the pointer around the screen (which is allowing us to have continuous movement as opposed to being locked at the edges). however, having said that, i would be glad to post any code that you might think helpful in diagnosing the issues. bonus question -- does anyone know where i can find out what is actually going on in glutMainLoop()? i have checked the man pages and what not, but i really would like to see the code in there or a list of what is happening and in what order. thanks! and, i would like to say thank you for all the help ya'll have provided so far (unwittingly ;)) and any that is to come.

Share this post


Link to post
Share on other sites
I'm not sure about the movement problems you're having; it sounds like that could be a problem in your code or perhaps related to using glut. As for moving the world or moving the camera, that's purely a conceptual distinction; it's all the same to OpenGL.

Share this post


Link to post
Share on other sites
Number one is probably an issue with applying the transformations and rotations, possibly in the wrong order. I haven't touched 3d code in some months so am not too sure about it. Your description is difficult to comprehend :) but from what you say it might be something else. Any chance of a screenshot?

Number two is most likely an issue with your keyboard polling / processing code. Think of how you press a key in a text editor. First one letter appears, then a pause, then others follow if the key is still down. Therefore, if you only move once for each keydown, you will get this initial stutter (I think). So you want to start moving on the first keydown and ignore subsequent keydowns of the same key until a keyup for that key is detected. (I might be digging my grave here tho :D)

Edit: answer to your bonus question

Edit2: You might wanna ditch GLUT :) I suppose it only brings some startup code and main loop code to the table, and that stuff is a write-and-forget non-issue. Write it once, your way, and you can keep using it. Portability is usually not an issue unless you are aiming at the small devices market or the console market or really want to impress linux users.

Share this post


Link to post
Share on other sites
Quote:
Your description is difficult to comprehend :) but from what you say it might be something else. Any chance of a screenshot?


yeah, i know, like i said, it is kinda hard to explain. i tried to grab a screen shot that demonstrated the issue i am seeing and i can't seem to do it. apparently the issue is then that the view is being drawn incorrectly like every other frame. this then raises a question of when the input is taken in. when using glut (which i really would like to get away from myself however my friend is dead set on it, i suggested we use the gl commands ourself write wrappers for what we need and let allegro do keyboard and mouse input if that is possible ... is it?) i don't know if keyboard and mouse are taken in at alternating times. my friend explains it as whenever the windows interupt is registered glut then deals with the respective call back. i'm not sure if that is how it is, but it doesn't explain why they can't be registered in the same loop and then have the transforms applied and then have the PostRedisplay called. that is what would make sense to me -- mess with stuff and then display it. if any of that made sense, can some one please comment on it?

Quote:
Number two is most likely an issue with your keyboard polling / processing code. Think of how you press a key in a text editor. First one letter appears, then a pause, then others follow if the key is still down. Therefore, if you only move once for each keydown, you will get this initial stutter (I think). So you want to start moving on the first keydown and ignore subsequent keydowns of the same key until a keyup for that key is detected. (I might be digging my grave here tho :D)


on this topic i did some research for what glut does with keyboard polling. [url=http://www.lighthouse3d.com/opengl/glut/index.php?7]this is what i came up with.[/url] at first i was really excited because it seemed to be what i wanted. however, it turns out that glutSetKeyRepeat() actually doesn't work in win32 and to do something similar you have to do glutIgnoreKeyRepeat(). in that case when you set it to ignore key repeats and use the glutMainLoop (man, this thing keeps popping up and i dislike it more and more ever time ...) you have to repress the key for it to reregister. now i freely admit that i really didn't know what to do after setting glutIgnoreKeyRepeat() to ignore. my guess is that there is a way to make it so that there is no need to keep repressing whatever key, but i don't know it. so any help there would be good.

Quote:
Edit: answer to your bonus question


thanks!

Quote:
Edit2: You might wanna ditch GLUT :) I suppose it only brings some startup code and main loop code to the table, and that stuff is a write-and-forget non-issue. Write it once, your way, and you can keep using it. Portability is usually not an issue unless you are aiming at the small devices market or the console market or really want to impress linux users.


yeah, that is what i'm thinking more and more. like i mentioned earlier in this post, i was contemplating dropping glut, writing my own main and wrappers that i know are working and how, and letting allegro get the keyboard and mouse data (because i don't know how opengl does it, but i am familiar with allegro). any suggestions there? think that will work?

again, thanks for the help so far! and remember, if you want to see any particular code i'm more than happy to post it if it means generating insight that i can use. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by supercat1
my guess is that there is a way to make it so that there is no need to keep repressing whatever key, but i don't know it. so any help there would be good.

What your probably could do is to store the key states in a table. You can use the callbacks described at the bottom of that page to reset the key's state in your table. Then every frame you check if the key is down according to your table, and if it is, commence movement. This should give smooth results.

Quote:
Original post by supercat1
yeah, that is what i'm thinking more and more. like i mentioned earlier in this post, i was contemplating dropping glut, writing my own main and wrappers that i know are working and how, and letting allegro get the keyboard and mouse data (because i don't know how opengl does it, but i am familiar with allegro). any suggestions there? think that will work?

OpenGL is a graphics library. Unlike DirectX, it does not provide for any input methods. Therefore, you really have to use another library (if moving away from GLUT). Apart from Allegro, there's also SDL input, and DirectX input. Someone in an old thread also suggested GL Framework (GLFW), although it seems to do a lot more than just input.

[Edited by - lightbringer on June 7, 2006 6:16:21 PM]

Share this post


Link to post
Share on other sites
Hi,

Are you developing on XP/2000? If so, try looking up WM_INPUT on the msdn site. I use that and it works fine, I have a big if/else statement for the keyboard processing.

As for your objects being skewed, Sounds like you may have either
a) a problem with your FOV setup
or most likely
b) a problem with your camera code.

Are you using a vector system for you camera? If not, I would recomend using that.

Hope this helps somewhat.
( i need a new keyboard, so if there are any r's missing, that's my excuse )

Share this post


Link to post
Share on other sites
I was reading an article just now and something came up that sounded kind of like what you described. clicky. see the part about "shake" rendering problems with star systems. I'm assuming that your scene is not that big, but maybe you inadvertently used large numbers?

Share this post


Link to post
Share on other sites
thanks for the suggestions so far (and the article)! when i get back to my pc, i'm on my college's campus right now, i'll look into those issues and read the article over again.

Share this post


Link to post
Share on other sites
The first issue is almost definitely a problem with the order that transformation are being applied. I had the same kind of problem until I fixed some bugs with matrix orders and stuff, then it worked - that was a good day.

The second issue is due to the keyboard repeat delay. Even at its fastest it is not quick enough. A better way is to poll the keyboard status in your main loop. If you're using Windows for example, call GetKeyboardState to find out which keys are currently depressed.

Share this post


Link to post
Share on other sites
For smooth keyboard input you can try:

#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

Instead of checking the array or whatever you are storing key states in just use one of these in its place. You won't have any of the waiting when you use the default Windows keyboard stuff.

Also, its not that hard to create a real WinMain() and WndProc().

Share this post


Link to post
Share on other sites
thanks for all the suggestions so far.

however, i'm still unable to find anything that is wrong. or more accurately, i'm not seeing it, cause there is definitely something wrong. furthermore, this is the third day in which i have been essentially alone in trying to figure this out. my friend who did much of the original coding has been anything but helpful in determining the problem and i'm getting very frustrated.

to that end, i'm contemplating just redoing the whole thing myself. however, if anyone would be willing to look at our code and could help me figure out the image thing (i can live with the key delay for now, that is definitely an easier fix) i would be extremely thankful, even if said help was just "start over, it's easier that way".

anyways, thanks for the help so far!

Share this post


Link to post
Share on other sites
sorry for the double post, but i wanted to make sure that those who were helping me before saw this as a new post. to you all, i am very thankful.

now, i have essentially gone through what was the engine before now (as my friend had mostly written it) and forced it to fornicate with nehe's lesson 10 code. what it spawned was this:


// 6/7/06
// Andrew Monshizadeh
// OpenGL 3d engine using glut

#include <GL/glut.h>
#include <cmath>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;

// window global variables
int WINDOW_WIDTH = 800;
int WINDOW_HEIGHT = 600;
int windowids[1]; // can be used to store multiple window ids in case there are multiple windows
char title[13] = "test engine";

// call back functions to be used
void initializecallbacks();
void displaycallback();
void keyboardcallback(unsigned char key, int x, int y);
void passivemotioncallback(int x, int y);
void reshapecallback(int w, int h);
void timercallback(int time);

// setup visual requirments
void initializevisuals();

// variables used for movement
const float piover180 = 0.0174532925f; // pi / 180, for degree to radian transform
float heading; // direction character is facing
float xpos; // x-axis position of the player
float zpos; // z-axis position of the player
float ypos = 0.5; // y-axis position of the player
GLfloat yrot; // y-axis rotation
GLfloat lookupdown = 0.0f; // value to look up or down
GLfloat z=0.0f; // Depth Into The Screen
int mousebasex = WINDOW_WIDTH/2;
int mousebasey = WINDOW_HEIGHT/2;

int main(int argc, char* argv[])
{
glutInit(&argc, argv);
initializevisuals();
initializecallbacks();

glutMainLoop();

return 0;
}

//----------------------------------------------------------------------------//
// call back section //
//----------------------------------------------------------------------------//
void initializecallbacks()
{
// setting up the call back functions
glutDisplayFunc(displaycallback); // display call back
glutKeyboardFunc(keyboardcallback); // keyboard call back
glutPassiveMotionFunc(passivemotioncallback); // passive mouse motion call back
glutReshapeFunc(reshapecallback); // screen reshape call back
glutTimerFunc(15, timercallback, 0); // timer call back
}

void keyboardcallback(unsigned char key, int x, int y)
{
switch (key)
{
// miscellaneous input
case 27: // 'esc'
exit(0); // end the program
break;

// movement input
case 'a':
xpos -= (float)sin(heading*piover180 + 90.0f*piover180) * 0.05f;
zpos -= (float)cos(heading*piover180 + 90.0f*piover180) * 0.05f;
break;
case 'd':
xpos += (float)sin(heading*piover180 + 90.0f*piover180) * 0.05f;
zpos += (float)cos(heading*piover180 + 90.0f*piover180) * 0.05f;
break;
case 'w':
xpos -= (float)sin(heading*piover180) * 0.05f;
zpos -= (float)cos(heading*piover180) * 0.05f;
break;
case 's':
xpos += (float)sin(heading*piover180) * 0.05f;
zpos += (float)cos(heading*piover180) * 0.05f;
}

int dims[4];
glGetIntegerv(GL_VIEWPORT, dims);

int dx = x - mousebasex;
int dy = y - mousebasey;
mousebasex = x;
mousebasey = y;

// if (x < 20)
// {
// glutWarpPointer(dims[2]/2, y);
// mousebasex = dims[2]/2;
// }
// if (x > (dims[2]/2 - 20))
// {
// glutWarpPointer(dims[2]/2, y);
// mousebasex = dims[2]/2;
// }

lookupdown += dy * 0.5f;
heading -= dx * 0.5f;
if(heading < 0.0f)
heading = heading + 360.0f;
else if(heading > 360.0f)
heading = heading - 360.0f;
yrot = heading;
}

void passivemotioncallback(int x, int y)
{
int dims[4];
glGetIntegerv(GL_VIEWPORT, dims);

int dx = x - mousebasex;
int dy = y - mousebasey;
mousebasex = x;
mousebasey = y;

if (x < 20)
{
glutWarpPointer(dims[2]/2, y);
mousebasex = dims[2]/2;
}
if (x > (dims[2] - 20))
{
glutWarpPointer(dims[2]/2, y);
mousebasex = dims[2]/2;
}

lookupdown += dy * 0.5f;
heading -= dx * 0.5f;
if(heading < 0.0f)
heading = heading + 360.0f;
else if (heading > 360.0f)
heading = heading - 360.0f;
yrot = heading;
}

void reshapecallback(int w, int h)
{
glViewport(0, 0, w, h);

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}

void timercallback(int time)
{
glutPostRedisplay();
glutTimerFunc(10, timercallback, 0);
}

void displaycallback()
{
int dims[4];
glGetIntegerv(GL_VIEWPORT, dims);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); // Reset The View

GLfloat xtrans = -xpos;
GLfloat ztrans = -zpos;
GLfloat ytrans = 0; // -walkbias-0.25f;
GLfloat sceneroty = 360.0f - yrot;

glRotatef(lookupdown,1.0f,0,0);
glRotatef(sceneroty,0,1.0f,0);
glTranslatef(xtrans, ytrans, ztrans);

glBegin(GL_QUADS);
glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green
glVertex3f( 0.5f, 0.5f,-0.5f); // Top Right Of The Quad (Top)
glVertex3f(-0.5f, 0.5f,-0.5f); // Top Left Of The Quad (Top)
glVertex3f(-0.5f, 0.5f, 0.5f); // Bottom Left Of The Quad (Top)
glVertex3f( 0.5f, 0.5f, 0.5f); // Bottom Right Of The Quad (Top)

glColor3f(1.0f,0.5f,0.0f); // Set The Color To Orange
glVertex3f( 0.5f,-0.5f, 0.5f); // Top Right Of The Quad (Bottom)
glVertex3f(-0.5f,-0.5f, 0.5f); // Top Left Of The Quad (Bottom)
glVertex3f(-0.5f,-0.5f,-0.5f); // Bottom Left Of The Quad (Bottom)
glVertex3f( 0.5f,-0.5f,-0.5f); // Bottom Right Of The Quad (Bottom)

glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
glVertex3f( 0.5f, 0.5f, 0.5f); // Top Right Of The Quad (Front)
glVertex3f(-0.5f, 0.5f, 0.5f); // Top Left Of The Quad (Front)
glVertex3f(-0.5f,-0.5f, 0.5f); // Bottom Left Of The Quad (Front)
glVertex3f( 0.5f,-0.5f, 0.5f); // Bottom Right Of The Quad (Front)

glColor3f(1.0f,1.0f,0.0f); // Set The Color To Yellow
glVertex3f( 0.5f,-0.5f,-0.5f); // Bottom Left Of The Quad (Back)
glVertex3f(-0.5f,-0.5f,-0.5f); // Bottom Right Of The Quad (Back)
glVertex3f(-0.5f, 0.5f,-0.5f); // Top Right Of The Quad (Back)
glVertex3f( 0.5f, 0.5f,-0.5f); // Top Left Of The Quad (Back)

glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
glVertex3f(-0.5f, 0.5f, 0.5f); // Top Right Of The Quad (Left)
glVertex3f(-0.5f, 0.5f,-0.5f); // Top Left Of The Quad (Left)
glVertex3f(-0.5f,-0.5f,-0.5f); // Bottom Left Of The Quad (Left)
glVertex3f(-0.5f,-0.5f, 0.5f); // Bottom Right Of The Quad (Left)

glColor3f(1.0f,0.0f,1.0f); // Set The Color To Violet
glVertex3f( 0.5f, 0.5f,-0.5f); // Top Right Of The Quad (Right)
glVertex3f( 0.5f, 0.5f, 0.5f); // Top Left Of The Quad (Right)
glVertex3f( 0.5f,-0.5f, 0.5f); // Bottom Left Of The Quad (Right)
glVertex3f( 0.5f,-0.5f,-0.5f); // Bottom Right Of The Quad (Right)
glEnd(); // Done Drawing The Quad

glFlush();
glutSwapBuffers();
}


void initializevisuals()
{
// creating the window and drawing buffers
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); // create double buffer and z-depth buffer
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); // create window using predetermined window sizes
glutInitWindowPosition(0,0);
windowids[0]=glutCreateWindow(title);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background color to white
glClearDepth(1.0); // enables clearing of the depth buffer
glEnable(GL_DEPTH_TEST); // enable depth testing
glDepthFunc(GL_LESS); // the type of depth test to do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // really nice perspective calculations, got from NeHe tutorial 10

int dims[4];
glGetIntegerv(GL_VIEWPORT, dims);

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)dims[2]/(GLfloat)dims[3],0.1f,100.0f);

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}



any comments y'all have would be much appreciated. the jittery effect i was talking about before is still kinda present here, but not as bad. the key delay is here, but we have definitely discussed that into the ground. :)

any suggestions on how to further eliminate the jitteryness would be greatly appreciated.

[Edited by - supercat1 on June 8, 2006 12:43:23 AM]

Share this post


Link to post
Share on other sites
anyone? please? i would really like to learn what is causing this (the jumpyness) and how to get rid of it.

thanks!

Share this post


Link to post
Share on other sites
quadruple post ftw!

but this is a good triple post -- i got the issue fixed! turns out that what was causing the jumpy visuals was the fact that glut was poling the keyboard for key presses every time through glutMainLoop(). so after putting in a version of delay-less input (similar to what y'all suggested, but having to go through glut's messy call backs since i'm not building it only for win32). but anyways, i got the delay-less input coded, compiled, ran, and started to freak out. :) i was pretty happy to finally not have nausea inducing vibrating objects on the screen.

i can't say thank you enough to the people on this board that helped with the correction of this/these issues! my hat's off to y'all!

Share this post


Link to post
Share on other sites

This topic is 4240 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By xhcao
      Does sync be needed to read texture content after access texture image in compute shader?
      My simple code is as below,
      glUseProgram(program.get());
      glBindImageTexture(0, texture[0], 0, GL_FALSE, 3, GL_READ_ONLY, GL_R32UI);
      glBindImageTexture(1, texture[1], 0, GL_FALSE, 4, GL_WRITE_ONLY, GL_R32UI);
      glDispatchCompute(1, 1, 1);
      // Does sync be needed here?
      glUseProgram(0);
      glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
      glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                     GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, texture[1], 0);
      glReadPixels(0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT, outputValues);
       
      Compute shader is very simple, imageLoad content from texture[0], and imageStore content to texture[1]. Does need to sync after dispatchCompute?
    • By Jonathan2006
      My question: is it possible to transform multiple angular velocities so that they can be reinserted as one? My research is below:
      // This works quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); quat quaternion2 = GEMultiplyQuaternions(quaternion1, GEQuaternionFromAngleRadians(angleRadiansVector2)); quat quaternion3 = GEMultiplyQuaternions(quaternion2, GEQuaternionFromAngleRadians(angleRadiansVector3)); glMultMatrixf(GEMat4FromQuaternion(quaternion3).array); // The first two work fine but not the third. Why? quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); vec3 vector1 = GETransformQuaternionAndVector(quaternion1, angularVelocity1); quat quaternion2 = GEQuaternionFromAngleRadians(angleRadiansVector2); vec3 vector2 = GETransformQuaternionAndVector(quaternion2, angularVelocity2); // This doesn't work //quat quaternion3 = GEQuaternionFromAngleRadians(angleRadiansVector3); //vec3 vector3 = GETransformQuaternionAndVector(quaternion3, angularVelocity3); vec3 angleVelocity = GEAddVectors(vector1, vector2); // Does not work: vec3 angleVelocity = GEAddVectors(vector1, GEAddVectors(vector2, vector3)); static vec3 angleRadiansVector; vec3 angularAcceleration = GESetVector(0.0, 0.0, 0.0); // Sending it through one angular velocity later in my motion engine angleVelocity = GEAddVectors(angleVelocity, GEMultiplyVectorAndScalar(angularAcceleration, timeStep)); angleRadiansVector = GEAddVectors(angleRadiansVector, GEMultiplyVectorAndScalar(angleVelocity, timeStep)); glMultMatrixf(GEMat4FromEulerAngle(angleRadiansVector).array); Also how do I combine multiple angularAcceleration variables? Is there an easier way to transform the angular values?
    • By dpadam450
      I have this code below in both my vertex and fragment shader, however when I request glGetUniformLocation("Lights[0].diffuse") or "Lights[0].attenuation", it returns -1. It will only give me a valid uniform location if I actually use the diffuse/attenuation variables in the VERTEX shader. Because I use position in the vertex shader, it always returns a valid uniform location. I've read that I can share uniforms across both vertex and fragment, but I'm confused what this is even compiling to if this is the case.
       
      #define NUM_LIGHTS 2
      struct Light
      {
          vec3 position;
          vec3 diffuse;
          float attenuation;
      };
      uniform Light Lights[NUM_LIGHTS];
       
       
    • By pr033r
      Hello,
      I have a Bachelor project on topic "Implenet 3D Boid's algorithm in OpenGL". All OpenGL issues works fine for me, all rendering etc. But when I started implement the boid's algorithm it was getting worse and worse. I read article (http://natureofcode.com/book/chapter-6-autonomous-agents/) inspirate from another code (here: https://github.com/jyanar/Boids/tree/master/src) but it still doesn't work like in tutorials and videos. For example the main problem: when I apply Cohesion (one of three main laws of boids) it makes some "cycling knot". Second, when some flock touch to another it scary change the coordination or respawn in origin (x: 0, y:0. z:0). Just some streng things. 
      I followed many tutorials, change a try everything but it isn't so smooth, without lags like in another videos. I really need your help. 
      My code (optimalizing branch): https://github.com/pr033r/BachelorProject/tree/Optimalizing
      Exe file (if you want to look) and models folder (for those who will download the sources):
      http://leteckaposta.cz/367190436
      Thanks for any help...

    • By Andrija
      I am currently trying to implement shadow mapping into my project , but although i can render my depth map to the screen and it looks okay , when i sample it with shadowCoords there is no shadow.
      Here is my light space matrix calculation
      mat4x4 lightViewMatrix; vec3 sun_pos = {SUN_OFFSET * the_sun->direction[0], SUN_OFFSET * the_sun->direction[1], SUN_OFFSET * the_sun->direction[2]}; mat4x4_look_at(lightViewMatrix,sun_pos,player->pos,up); mat4x4_mul(lightSpaceMatrix,lightProjMatrix,lightViewMatrix); I will tweak the values for the size and frustum of the shadow map, but for now i just want to draw shadows around the player position
      the_sun->direction is a normalized vector so i multiply it by a constant to get the position.
      player->pos is the camera position in world space
      the light projection matrix is calculated like this:
      mat4x4_ortho(lightProjMatrix,-SHADOW_FAR,SHADOW_FAR,-SHADOW_FAR,SHADOW_FAR,NEAR,SHADOW_FAR); Shadow vertex shader:
      uniform mat4 light_space_matrix; void main() { gl_Position = light_space_matrix * transfMatrix * vec4(position, 1.0f); } Shadow fragment shader:
      out float fragDepth; void main() { fragDepth = gl_FragCoord.z; } I am using deferred rendering so i have all my world positions in the g_positions buffer
      My shadow calculation in the deferred fragment shader:
      float get_shadow_fac(vec4 light_space_pos) { vec3 shadow_coords = light_space_pos.xyz / light_space_pos.w; shadow_coords = shadow_coords * 0.5 + 0.5; float closest_depth = texture(shadow_map, shadow_coords.xy).r; float current_depth = shadow_coords.z; float shadow_fac = 1.0; if(closest_depth < current_depth) shadow_fac = 0.5; return shadow_fac; } I call the function like this:
      get_shadow_fac(light_space_matrix * vec4(position,1.0)); Where position is the value i got from sampling the g_position buffer
      Here is my depth texture (i know it will produce low quality shadows but i just want to get it working for now):
      sorry because of the compression , the black smudges are trees ... https://i.stack.imgur.com/T43aK.jpg
      EDIT: Depth texture attachment:
      glTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT24,fbo->width,fbo->height,0,GL_DEPTH_COMPONENT,GL_FLOAT,NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, fbo->depthTexture, 0);
  • Popular Now