• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Ricardo3Ddev
      Hi guys!
      This is a independent game being produced by me and my brother. We’ve been working on it for about 6 months and we’ve already done a good part of the game. We hope to finalize and make it available on Steam by the end of this year.
      We are using Blender 3D and Gimp software for production.
       
      About the Game: Dongo Adventure will be a 3D platform style game, where the main character (Dongo) is a mouse that ventures through various scenarios (sewers, culverts, streets, electric grid, etc.) and faces several enemies along the way (cockroaches, mosquitoes, spiders, toxic gases, electrical wires, etc.). He carries a basket / backpack with cheeses that he uses to throw and defend himself from enemies, as well as being able to push objects that helps him to overcome obstacles. The ultimate goal will be a surprise!
       
      Now we are developing new scenarios and enemies. We hope to publish news soon...
      Game page on Steam: http://store.steampowered.com/app/811450/Dongo_Adventure/ - (Teaser UPDATED)
      Dongo Adventure - Indie Game Project (First Teaser) https://www.youtube.com/watch?v=X2nmxtkE0xk
       
      Thanks for following the project!

    • By tj8146
      I am using immediate mode for OpenGL and I am creating a 2D top down car game. I am trying to configure my game loop in order to get my car-like physics working on a square shape. I have working code but it is not doing as I want it to. I am not sure as to whether it is my game loop that is incorrect or my code for the square is incorrect, or maybe both! Could someone help because I have been trying to work this out for over a day now
      I have attached my .cpp file if you wish to run it for yourself.. 
      WinMain code:
      /******************* WIN32 FUNCTIONS ***************************/ int WINAPI WinMain( HINSTANCE hInstance, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters int nCmdShow) // Window Show State { MSG msg; // Windows Message Structure bool done=false; // Bool Variable To Exit Loop Car car; car.x = 220; car.y = 140; car.dx = 0; car.dy = 0; car.ang = 0; AllocConsole(); FILE *stream; freopen_s(&stream, "CONOUT$", "w", stdout); // Create Our OpenGL Window if (!CreateGLWindow("OpenGL Win32 Example",screenWidth,screenHeight)) { return 0; // Quit If Window Was Not Created } while(!done) // Loop That Runs While done=FALSE { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting? { if (msg.message==WM_QUIT) // Have We Received A Quit Message? { done=true; // If So done=TRUE break; } else // If Not, Deal With Window Messages { TranslateMessage(&msg); // Translate The Message DispatchMessage(&msg); // Dispatch The Message } } else // If There Are No Messages { if(keys[VK_ESCAPE]) done = true; void processKeys(Car& car); //process keyboard while (game_is_running) { loops = 0; while (GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP) { update(car); // update variables next_game_tick += SKIP_TICKS; loops++; } display(car); // Draw The Scene SwapBuffers(hDC); // Swap Buffers (Double Buffering) } } } // Shutdown KillGLWindow(); // Kill The Window return (int)(msg.wParam); // Exit The Program } //WIN32 Processes function - useful for responding to user inputs or other events. LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window UINT uMsg, // Message For This Window WPARAM wParam, // Additional Message Information LPARAM lParam) // Additional Message Information { switch (uMsg) // Check For Windows Messages { case WM_CLOSE: // Did We Receive A Close Message? { PostQuitMessage(0); // Send A Quit Message return 0; // Jump Back } break; case WM_SIZE: // Resize The OpenGL Window { reshape(LOWORD(lParam),HIWORD(lParam)); // LoWord=Width, HiWord=Height return 0; // Jump Back } break; case WM_LBUTTONDOWN: { mouse_x = LOWORD(lParam); mouse_y = screenHeight - HIWORD(lParam); LeftPressed = true; } break; case WM_LBUTTONUP: { LeftPressed = false; } break; case WM_MOUSEMOVE: { mouse_x = LOWORD(lParam); mouse_y = screenHeight - HIWORD(lParam); } break; case WM_KEYDOWN: // Is A Key Being Held Down? { keys[wParam] = true; // If So, Mark It As TRUE return 0; // Jump Back } break; case WM_KEYUP: // Has A Key Been Released? { keys[wParam] = false; // If So, Mark It As FALSE return 0; // Jump Back } break; } // Pass All Unhandled Messages To DefWindowProc return DefWindowProc(hWnd,uMsg,wParam,lParam); }  
      C++ and OpenGL code:
      int mouse_x=0, mouse_y=0; bool LeftPressed = false; int screenWidth=1080, screenHeight=960; bool keys[256]; float radiansFromDegrees(float deg) { return deg * (M_PI / 180.0f); } float degreesFromRadians(float rad) { return rad / (M_PI / 180.0f); } bool game_is_running = true; const int TICKS_PER_SECOND = 50; const int SKIP_TICKS = 1000 / TICKS_PER_SECOND; const int MAX_FRAMESKIP = 10; DWORD next_game_tick = GetTickCount(); int loops; typedef struct { float x, y; float dx, dy; float ang; }Car; //OPENGL FUNCTION PROTOTYPES void display(const Car& car); //called in winmain to draw everything to the screen void reshape(int width, int height); //called when the window is resized void init(); //called in winmain when the program starts. void processKeys(Car& car); //called in winmain to process keyboard input void update(Car& car); //called in winmain to update variables /************* START OF OPENGL FUNCTIONS ****************/ void display(const Car& car) { const float w = 50.0f; const float h = 50.0f; glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glTranslatef(100, 100, 0); glBegin(GL_POLYGON); glVertex2f(car.x, car.y); glVertex2f(car.x + w, car.y); glVertex2f(car.x + w, car.y + h); glVertex2f(car.x, car.y + h); glEnd(); glFlush(); } void reshape(int width, int height) // Resize the OpenGL window { screenWidth = width; screenHeight = height; // to ensure the mouse coordinates match // we will use these values to set the coordinate system glViewport(0, 0, width, height); // Reset the current viewport glMatrixMode(GL_PROJECTION); // select the projection matrix stack glLoadIdentity(); // reset the top of the projection matrix to an identity matrix gluOrtho2D(0, screenWidth, 0, screenHeight); // set the coordinate system for the window glMatrixMode(GL_MODELVIEW); // Select the modelview matrix stack glLoadIdentity(); // Reset the top of the modelview matrix to an identity matrix } void init() { glClearColor(1.0, 1.0, 0.0, 0.0); //sets the clear colour to yellow //glClear(GL_COLOR_BUFFER_BIT) in the display function //will clear the buffer to this colour. } void processKeys(Car& car) { if (keys[VK_UP]) { float cdx = sinf(radiansFromDegrees(car.ang)); float cdy = -cosf(radiansFromDegrees(car.ang)); car.dx += cdx; car.dy += cdy; } if (keys[VK_DOWN]) { float cdx = sinf(radiansFromDegrees(car.ang)); float cdy = -cosf(radiansFromDegrees(car.ang)); car.dx += -cdx; car.dy += -cdy; } if (keys[VK_LEFT]) { car.ang -= 2; } if (keys[VK_RIGHT]) { car.ang += 2; } } void update(Car& car) { car.x += car.dx*next_game_tick; }  
      game.cpp
    • By tj8146
      I am using immediate mode for OpenGL and I am creating a 2D top down car game. I am trying to configure my game loop in order to get my car-like physics working on a square shape. I have working code but it is not doing as I want it to. I am not sure as to whether it is my game loop that is incorrect or my code for the square is incorrect, or maybe both! Could someone help because I have been trying to work this out for over a day now
      I have attached my .cpp file if you wish to run it for yourself.. 
       
      This is my C++ and OpenGL code:
      int mouse_x=0, mouse_y=0; bool LeftPressed = false; int screenWidth=1080, screenHeight=960; bool keys[256]; float radiansFromDegrees(float deg) { return deg * (M_PI / 180.0f); } float degreesFromRadians(float rad) { return rad / (M_PI / 180.0f); } bool game_is_running = true; const int TICKS_PER_SECOND = 50; const int SKIP_TICKS = 1000 / TICKS_PER_SECOND; const int MAX_FRAMESKIP = 10; DWORD next_game_tick = GetTickCount(); int loops; typedef struct { float x, y; float dx, dy; float ang; }Car; //OPENGL FUNCTION PROTOTYPES void display(const Car& car); //called in winmain to draw everything to the screen void reshape(int width, int height); //called when the window is resized void init(); //called in winmain when the program starts. void processKeys(Car& car); //called in winmain to process keyboard input void update(Car& car); //called in winmain to update variables /************* START OF OPENGL FUNCTIONS ****************/ void display(const Car& car) { const float w = 50.0f; const float h = 50.0f; glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glTranslatef(100, 100, 0); glBegin(GL_POLYGON); glVertex2f(car.x, car.y); glVertex2f(car.x + w, car.y); glVertex2f(car.x + w, car.y + h); glVertex2f(car.x, car.y + h); glEnd(); glFlush(); } void reshape(int width, int height) // Resize the OpenGL window { screenWidth = width; screenHeight = height; // to ensure the mouse coordinates match // we will use these values to set the coordinate system glViewport(0, 0, width, height); // Reset the current viewport glMatrixMode(GL_PROJECTION); // select the projection matrix stack glLoadIdentity(); // reset the top of the projection matrix to an identity matrix gluOrtho2D(0, screenWidth, 0, screenHeight); // set the coordinate system for the window glMatrixMode(GL_MODELVIEW); // Select the modelview matrix stack glLoadIdentity(); // Reset the top of the modelview matrix to an identity matrix } void init() { glClearColor(1.0, 1.0, 0.0, 0.0); //sets the clear colour to yellow //glClear(GL_COLOR_BUFFER_BIT) in the display function //will clear the buffer to this colour. } void processKeys(Car& car) { if (keys[VK_UP]) { float cdx = sinf(radiansFromDegrees(car.ang)); float cdy = -cosf(radiansFromDegrees(car.ang)); car.dx += cdx; car.dy += cdy; } if (keys[VK_DOWN]) { float cdx = sinf(radiansFromDegrees(car.ang)); float cdy = -cosf(radiansFromDegrees(car.ang)); car.dx += -cdx; car.dy += -cdy; } if (keys[VK_LEFT]) { car.ang -= 2; } if (keys[VK_RIGHT]) { car.ang += 2; } } void update(Car& car) { car.x += car.dx*next_game_tick; } My WinMain code:
      /******************* WIN32 FUNCTIONS ***************************/ int WINAPI WinMain( HINSTANCE hInstance, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters int nCmdShow) // Window Show State { MSG msg; // Windows Message Structure bool done=false; // Bool Variable To Exit Loop Car car; car.x = 220; car.y = 140; car.dx = 0; car.dy = 0; car.ang = 0; AllocConsole(); FILE *stream; freopen_s(&stream, "CONOUT$", "w", stdout); // Create Our OpenGL Window if (!CreateGLWindow("OpenGL Win32 Example",screenWidth,screenHeight)) { return 0; // Quit If Window Was Not Created } while(!done) // Loop That Runs While done=FALSE { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting? { if (msg.message==WM_QUIT) // Have We Received A Quit Message? { done=true; // If So done=TRUE break; } else // If Not, Deal With Window Messages { TranslateMessage(&msg); // Translate The Message DispatchMessage(&msg); // Dispatch The Message } } else // If There Are No Messages { if(keys[VK_ESCAPE]) done = true; void processKeys(Car& car); //process keyboard while (game_is_running) { loops = 0; while (GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP) { update(car); // update variables next_game_tick += SKIP_TICKS; loops++; } display(car); // Draw The Scene SwapBuffers(hDC); // Swap Buffers (Double Buffering) } } } // Shutdown KillGLWindow(); // Kill The Window return (int)(msg.wParam); // Exit The Program } //WIN32 Processes function - useful for responding to user inputs or other events. LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window UINT uMsg, // Message For This Window WPARAM wParam, // Additional Message Information LPARAM lParam) // Additional Message Information { switch (uMsg) // Check For Windows Messages { case WM_CLOSE: // Did We Receive A Close Message? { PostQuitMessage(0); // Send A Quit Message return 0; // Jump Back } break; case WM_SIZE: // Resize The OpenGL Window { reshape(LOWORD(lParam),HIWORD(lParam)); // LoWord=Width, HiWord=Height return 0; // Jump Back } break; case WM_LBUTTONDOWN: { mouse_x = LOWORD(lParam); mouse_y = screenHeight - HIWORD(lParam); LeftPressed = true; } break; case WM_LBUTTONUP: { LeftPressed = false; } break; case WM_MOUSEMOVE: { mouse_x = LOWORD(lParam); mouse_y = screenHeight - HIWORD(lParam); } break; case WM_KEYDOWN: // Is A Key Being Held Down? { keys[wParam] = true; // If So, Mark It As TRUE return 0; // Jump Back } break; case WM_KEYUP: // Has A Key Been Released? { keys[wParam] = false; // If So, Mark It As FALSE return 0; // Jump Back } break; } // Pass All Unhandled Messages To DefWindowProc return DefWindowProc(hWnd,uMsg,wParam,lParam); }  
      game.cpp
    • By Epicghost 505
      Hello,
      We are looking for people to be apart of a team, to help create a horror game we are looking for 3d modelers, coders, artist, animators, fx artist, level designers, and audio design, there will be a payment plan once release of game                                                                                                                                                                                                                                                                                              if your interested come join our discord                                                                                                                                                                                                                                                                         We hope to see you there
      https://discord.gg/6rcc6xr
      -Epicghost505
    • By lxjk
      Hi guys,
      There are many ways to do light culling in tile-based shading. I've been playing with this idea for a while, and just want to throw it out there.
      Because tile frustums are general small compared to light radius, I tried using cone test to reduce false positives introduced by commonly used sphere-frustum test.
      On top of that, I use distance to camera rather than depth for near/far test (aka. sliced by spheres).
      This method can be naturally extended to clustered light culling as well.
      The following image shows the general ideas

       
      Performance-wise I get around 15% improvement over sphere-frustum test. You can also see how a single light performs as the following: from left to right (1) standard rendering of a point light; then tiles passed the test of (2) sphere-frustum test; (3) cone test; (4) spherical-sliced cone test
       

       
      I put the details in my blog post (https://lxjk.github.io/2018/03/25/Improve-Tile-based-Light-Culling-with-Spherical-sliced-Cone.html), GLSL source code included!
       
      Eric
  • Advertisement
  • Advertisement

3D Billboarding between two points

Recommended Posts

Some time ago I implemented a particle system using billboarding techniques to ensure that the particles are always facing the viewer.  These billboards are always centered on one 3d coordinate.

I would like to build on this and use billboarding as the basis for things like laser bolts and gunshots.  Here the difference is that instead of a single point particle I now have to draw a billboard between two points - the start and end of the laser bolt for example.  I appreciate that having two end points places limits on how much the billboard can be rotated to face the viewer, but I'm looking to code a best effort solution.  For the moment I am struggling to work out how to do this or find any tutorials / code examples that explain how to draw a billboard between two points ... can anyone help?

Thanks.

Share this post


Link to post
Share on other sites
Advertisement

why don't you pass in a single vert and give it a height and direction in as a uniform or in an instance buffer? in fact you'd only need a direction, and the height would be encoded as the magnitude of the direction. when your making your billboard, just add the direction to the vert position. you can cross the direction vector and the vert pos-to-camera vector to get the direction the other two verts need to go

EDIT: I assumed the geometry shader was being used already

Share this post


Link to post
Share on other sites
3 hours ago, missionctrl said:

OpenGL has built in functionality to draw points and lines as "billboards". Use glDrawElements with the GL_POINTS and GL_LINES mode

Until now I have been using GL_LINES with a thicker line width and a one dimensional texture.  Works well, but I want to move to a 2D texture so I can have glow along the edges of the laser bolts for example.  Not sure I can achieve this with GL_LINES and as a result have headed down the direction of using billboards. 

Share this post


Link to post
Share on other sites

If you send a line primitive, then you can expand it into a segment in the geometry shader. I have some geometry shader code to do that.

#version 330 compatibility

// 2 points are expanded into a quad (2 triangles = 4 vertices)
layout(lines) in;
layout(triangle_strip, max_vertices = 4) out;

in VertexShaderOutput
{
    vec4 positionViewSpace;
    vec4 color;
} vertexShaderOutput[];

uniform mat4 projectionMatrix;
uniform float lineWidth;

out GeometryShaderOutput
{
    vec4 color;
} geometryShaderOutput;

void main()
{   
    // We compute the side vector. it is used to know in what direction we need to translate quad vertices for this line.
    vec3 sourceToDestVectorViewSpace = normalize(vertexShaderOutput[1].positionViewSpace - vertexShaderOutput[0].positionViewSpace).xyz;
    vec3 sourceToCameraVectorViewSpace = normalize(-1.0f * vertexShaderOutput[0].positionViewSpace.xyz);    
    
    vec4 sideVectorViewSpace = lineWidth * 0.5f * vec4(normalize(cross(sourceToDestVectorViewSpace, sourceToCameraVectorViewSpace)), 0.0f);    
    
    // Output line quad
    gl_Position = projectionMatrix * (vertexShaderOutput[1].positionViewSpace + sideVectorViewSpace);
    geometryShaderOutput.color = vertexShaderOutput[1].color;
    EmitVertex();
        
    gl_Position = projectionMatrix * (vertexShaderOutput[1].positionViewSpace - sideVectorViewSpace);
    geometryShaderOutput.color = vertexShaderOutput[1].color;
    EmitVertex();
            
    gl_Position = projectionMatrix * (vertexShaderOutput[0].positionViewSpace + sideVectorViewSpace);
    geometryShaderOutput.color = vertexShaderOutput[0].color;
    EmitVertex();
            
    gl_Position = projectionMatrix * (vertexShaderOutput[0].positionViewSpace - sideVectorViewSpace);
    geometryShaderOutput.color = vertexShaderOutput[0].color;
    EmitVertex();
}

Hope this helps!

Share this post


Link to post
Share on other sites

Would like to draw a billboard between two points, and what these points even define? you are aware that to draw a billboard you are anyway using 4 verts (without any special gcard extensions like in example GL_POINT_SPRITE_ARB)

 

Either way you compose world*viewmat and extract screen direction vectors, then you build up a billboard 

 

something like this (thisis for ogl)


vec3 BillboardX;
vec3 BillboardY;
void GetTranslationMatrix(mat4 ModelViewMatrix)
{
	mat4 mvm = ModelViewMatrix;
	mvm.Transpose();

BillboardX.x = mvm.m[0];
BillboardX.y = mvm.m[4];
BillboardX.z = mvm.m[8];

BillboardY.x =	mvm.m[1];
BillboardY.y =	mvm.m[5];
BillboardY.z =	mvm.m[9];

translation_facenormal = Normalize(vectorcross(BillboardX * 1000.0, BillboardY * 1000.0));


translation_facedist = -dot(translation_facenormal, translation_pos);

}

int i;
for (i=0; i < particlenum; i++) {





verts[i*4].v.x = particles[i].pos.x-BillboardX.x*particles[i].size+BillboardY.x*particles[i].size;
verts[i*4].v.y = particles[i].pos.y-BillboardX.y*particles[i].size+BillboardY.y*particles[i].size;
verts[i*4].v.z = particles[i].pos.z-BillboardX.z*particles[i].size+BillboardY.z*particles[i].size;


verts[i*4+1].v.x = particles[i].pos.x+BillboardX.x*particles[i].size+BillboardY.x*particles[i].size;
verts[i*4+1].v.y = particles[i].pos.y+BillboardX.y*particles[i].size+BillboardY.y*particles[i].size;
verts[i*4+1].v.z = particles[i].pos.z+BillboardX.z*particles[i].size+BillboardY.z*particles[i].size;


verts[i*4+2].v.x = particles[i].pos.x+BillboardX.x*particles[i].size-BillboardY.x*particles[i].size;
verts[i*4+2].v.y = particles[i].pos.y+BillboardX.y*particles[i].size-BillboardY.y*particles[i].size;
verts[i*4+2].v.z = particles[i].pos.z+BillboardX.z*particles[i].size-BillboardY.z*particles[i].size;


verts[i*4+3].v.x = particles[i].pos.x-BillboardX.x*particles[i].size-BillboardY.x*particles[i].size;
verts[i*4+3].v.y = particles[i].pos.y-BillboardX.y*particles[i].size-BillboardY.y*particles[i].size;
verts[i*4+3].v.z = particles[i].pos.z-BillboardX.z*particles[i].size-BillboardY.z*particles[i].size;


                                }

 

 

Since you have defined 4 points what do you want to do with these two points?

Share this post


Link to post
Share on other sites
On 6/27/2017 at 3:34 PM, nbertoa said:

If you send a line primitive, then you can expand it into a segment in the geometry shader. I have some geometry shader code to do that.

...

Hope this helps!

I think this is the sort of thing I'm after - I'll work on integrating something along these lines into my code and let you know how I get on.  Thanks.

 

20 hours ago, WiredCat said:

Would like to draw a billboard between two points, and what these points even define? you are aware that to draw a  you are anyway using 4 verts (without any special gcard extensions like in example GL_POINT_SPRITE_ARB)

Either way you compose world*viewmat and extract screen direction vectors, then you build up a billboard 

something like this (thisis for ogl)

...

Since you have defined 4 points what do you want to do with these two points?

I probably wasn't very clear - I 'm already billboarding with 4 verts and using the viewing matrix to work out the 4 points (as in you example).  The problem I'm now facing is that I am moving from a billboard drawn around one 3D point (a particle) to a situation where I am moving up from a line drawn between two points (the start and end point of the laser bolt for example) to ideally drawing a textured quad that is (as much as possible) rotated to face the viewer.  Having to maintain the start and end points mean I cannot simply use the viewing matrix to position the quad - I need to retain the two points as the centre line of the quad and rotate as much as possible around these.  Hope that makes a bit more sense?

Share this post


Link to post
Share on other sites

are you using the geometry shader?

so, if you look up to my previous post, you can cross the vector between those two points, with the vector between the camera and the first point. this will give you a right vector, which you will be able to use to create the billboard vertices so that the primitives face the camera. does that make sense? i could give an example if you need (you don't have to be using a geometry shader to do this, but geometry shader can make billboarding a lot easier)

Share this post


Link to post
Share on other sites

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


  • Advertisement