• 10
• 10
• 12
• 12
• 14
• ### Similar Content

• By racarate
Hey everybody!
I am trying to replicate all these cool on-screen debug visuals I see in all the SIGGRAPH and GDC talks, but I really don't know where to start.  The only resource I know of is almost 16 years old:
http://number-none.com/product/Interactive Profiling, Part 1/index.html
Does anybody have a more up-to-date reference?  Do people use minimal UI libraries like Dear ImgGui?  Also, If I am profiling OpenGL ES 3.0 (which doesn't have timer queries) is there really anything I can do to measure performance GPU-wise?  Or should I just chart CPU-side frame time?  I feel like this is something people re-invent for every game there has gotta be a tutorial out there... right?

• By Achivai
Hey, I am semi-new to 3d-programming and I've hit a snag. I have one object, let's call it Object A. This object has a long int array of 3d xyz-positions stored in it's vbo as an instanced attribute. I am using these numbers to instance object A a couple of thousand times. So far so good.
Now I've hit a point where I want to remove one of these instances of object A while the game is running, but I'm not quite sure how to go about it. At first my thought was to update the instanced attribute of Object A and change the positions to some dummy number that I could catch in the vertex shader and then decide there whether to draw the instance of Object A or not, but I think that would be expensive to do while the game is running, considering that it might have to be done several times every frame in some cases.
I'm not sure how to proceed, anyone have any tips?
• By fleissi
Hey guys!

I'm new here and I recently started developing my own rendering engine. It's open source, based on OpenGL/DirectX and C++.
The full source code is hosted on github:
https://github.com/fleissna/flyEngine

I would appreciate if people with experience in game development / engine desgin could take a look at my source code. I'm looking for honest, constructive criticism on how to improve the engine.
I'm currently writing my master's thesis in computer science and in the recent year I've gone through all the basics about graphics programming, learned DirectX and OpenGL, read some articles on Nvidia GPU Gems, read books and integrated some of this stuff step by step into the engine.

I know about the basics, but I feel like there is some missing link that I didn't get yet to merge all those little pieces together.

Features I have so far:
- Dynamic shader generation based on material properties
- Dynamic sorting of meshes to be renderd based on shader and material
- Rendering large amounts of static meshes
- Hierarchical culling (detail + view frustum)
- Limited support for dynamic (i.e. moving) meshes
- Normal, Parallax and Relief Mapping implementations
- Wind animations based on vertex displacement
- A very basic integration of the Bullet physics engine
- Procedural Grass generation
- Some post processing effects (Depth of Field, Light Volumes, Screen Space Reflections, God Rays)
- Caching mechanisms for textures, shaders, materials and meshes

Features I would like to have:
- Global illumination methods
- Scalable physics
- Occlusion culling
- A nice procedural terrain generator
- Scripting
- Level Editing
- Sound system
- Optimization techniques

Books I have so far:
- Real-Time Rendering Third Edition
- 3D Game Programming with DirectX 11
- Vulkan Cookbook (not started yet)

I hope you guys can take a look at my source code and if you're really motivated, feel free to contribute :-)
There are some videos on youtube that demonstrate some of the features:
Procedural grass on the GPU
Procedural Terrain Engine
Quadtree detail and view frustum culling

The long term goal is to turn this into a commercial game engine. I'm aware that this is a very ambitious goal, but I'm sure it's possible if you work hard for it.

Bye,

Phil
• By tj8146
I have attached my project in a .zip file if you wish to run it for yourself.
I am making a simple 2d top-down game and I am trying to run my code to see if my window creation is working and to see if my timer is also working with it. Every time I run it though I get errors. And when I fix those errors, more come, then the same errors keep appearing. I end up just going round in circles.  Is there anyone who could help with this?

Errors when I build my code:
1>Renderer.cpp 1>c:\users\documents\opengl\game\game\renderer.h(15): error C2039: 'string': is not a member of 'std' 1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\ucrt\stddef.h(18): note: see declaration of 'std' 1>c:\users\documents\opengl\game\game\renderer.h(15): error C2061: syntax error: identifier 'string' 1>c:\users\documents\opengl\game\game\renderer.cpp(28): error C2511: 'bool Game::Rendering::initialize(int,int,bool,std::string)': overloaded member function not found in 'Game::Rendering' 1>c:\users\documents\opengl\game\game\renderer.h(9): note: see declaration of 'Game::Rendering' 1>c:\users\documents\opengl\game\game\renderer.cpp(35): error C2597: illegal reference to non-static member 'Game::Rendering::window' 1>c:\users\documents\opengl\game\game\renderer.cpp(36): error C2597: illegal reference to non-static member 'Game::Rendering::window' 1>c:\users\documents\opengl\game\game\renderer.cpp(43): error C2597: illegal reference to non-static member 'Game::Rendering::window' 1>Done building project "Game.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Renderer.cpp
#include <GL/glew.h> #include <GLFW/glfw3.h> #include "Renderer.h" #include "Timer.h" #include <iostream> namespace Game { GLFWwindow* window; /* Initialize the library */ Rendering::Rendering() { mClock = new Clock; } Rendering::~Rendering() { shutdown(); } bool Rendering::initialize(uint width, uint height, bool fullscreen, std::string window_title) { if (!glfwInit()) { return -1; } /* Create a windowed mode window and its OpenGL context */ window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); if (!window) { glfwTerminate(); return -1; } /* Make the window's context current */ glfwMakeContextCurrent(window); glViewport(0, 0, (GLsizei)width, (GLsizei)height); glOrtho(0, (GLsizei)width, (GLsizei)height, 0, 1, -1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glfwSwapInterval(1); glEnable(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_TEXTURE_2D); glLoadIdentity(); return true; } bool Rendering::render() { /* Loop until the user closes the window */ if (!glfwWindowShouldClose(window)) return false; /* Render here */ mClock->reset(); glfwPollEvents(); if (mClock->step()) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glfwSwapBuffers(window); mClock->update(); } return true; } void Rendering::shutdown() { glfwDestroyWindow(window); glfwTerminate(); } GLFWwindow* Rendering::getCurrentWindow() { return window; } } Renderer.h
#pragma once namespace Game { class Clock; class Rendering { public: Rendering(); ~Rendering(); bool initialize(uint width, uint height, bool fullscreen, std::string window_title = "Rendering window"); void shutdown(); bool render(); GLFWwindow* getCurrentWindow(); private: GLFWwindow * window; Clock* mClock; }; } Timer.cpp
#include <GL/glew.h> #include <GLFW/glfw3.h> #include <time.h> #include "Timer.h" namespace Game { Clock::Clock() : mTicksPerSecond(50), mSkipTics(1000 / mTicksPerSecond), mMaxFrameSkip(10), mLoops(0) { mLastTick = tick(); } Clock::~Clock() { } bool Clock::step() { if (tick() > mLastTick && mLoops < mMaxFrameSkip) return true; return false; } void Clock::reset() { mLoops = 0; } void Clock::update() { mLastTick += mSkipTics; mLoops++; } clock_t Clock::tick() { return clock(); } } TImer.h
#pragma once #include "Common.h" namespace Game { class Clock { public: Clock(); ~Clock(); void update(); bool step(); void reset(); clock_t tick(); private: uint mTicksPerSecond; ufloat mSkipTics; uint mMaxFrameSkip; uint mLoops; uint mLastTick; }; } Common.h
#pragma once #include <cstdio> #include <cstdlib> #include <ctime> #include <cstring> #include <cmath> #include <iostream> namespace Game { typedef unsigned char uchar; typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long ulong; typedef float ufloat; }
Game.zip
• 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

# OpenGL GL vs. D3D Texture/Viewport/Scissors Coordinates

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

## Recommended Posts

I've been having this "liittle problem" for a while :

http://s7.postimg.org/k32r23lmz/Diff.png

Everything (except the ImGui Window is rendered to a texture and after that that texture gets rendered to the window).

The problem is the way APIs handle texture coordinates/Viewport/Scissors Rect. Knowing that OpenGL (0,0) tex-coord is at the left-bottom and glTexImage2D assumes that the image that is organized from bottom to the top it was really tempting to try to "force" OpenGL to deal with texture coordinates like D3D.

This works fine if we ignore the Frame Buffers.So In order to fake that I've flipped the projection matrices Y-cords, and I've inverted the Front Face Triangle Winding. In that case everything works fine, except for the moment when you actually draw to the window. Well the end result is flipped by Y.

One way to fix this is to reverse the flip when drawing to the default frame buffer(the screen).
With my custom API I know when a draw call is going to be submitted to the screen, the problem is that "in general" I don't know the name of the uniform that hold the projection matrix, In theory the projection matrix could be hardcoded into the shader code.

And basically I'm stuck here.. I could hardcode that case, but I really want find a solution to that problem?

...or maybe trying to make OpenGL look more D3D-ish is not the right solution?? What is you approach?

##### Share on other sites

the problem is that "in general" I don't know the name of the uniform that hold the projection matrix, In theory the projection matrix could be hardcoded into the shader code.

Besides texture data layout difference (stupid vertical flipping), OpenGL also uses a stupid range of Z values in post-projection space (-1 to 1, instead of 0 to 1)... so you already need to have a mechanism in your engine that will construct projection matrices differently depending on which API you're using.
In my engine, I've pretty much covered up all the differences between the APIs, except for this one leaky abstraction -- the right way to build a projection matrix  ... So this is simply left unsolved in my low-level renderer. Instead it unfortunately resides in a high level math library for building matrices...

And yeah, FWIW, I use D3D conventions everywhere as they're more common across my target platforms.

##### Share on other sites

Besides texture data layout difference (stupid vertical flipping), OpenGL also uses a stupid range of Z values in post-projection space (-1 to 1, instead of 0 to 1)

Doesn't glClipControl solve these problems?

##### Share on other sites

Besides texture data layout difference (stupid vertical flipping), OpenGL also uses a stupid range of Z values in post-projection space (-1 to 1, instead of 0 to 1)

Doesn't glClipControl solve these problems?

If GL4.4 is your min-spec, sure
Also assuming that the dodgey drivers that just silently ignored calls to that function have all been fixed by now

Note though that you still have to manually flip parameters to glViewport, glScissor, etc, as glClipControl has no effect on those functions.

##### Share on other sites

You don't like the way of inversing all automatically based on the define which says the actual render system to stay D3D conventions everywhere ?

##### Share on other sites

Besides texture data layout difference (stupid vertical flipping), OpenGL also uses a stupid range of Z values in post-projection space (-1 to 1, instead of 0 to 1)

Doesn't glClipControl solve these problems?

If GL4.4 is your min-spec, sure
Also assuming that the dodgey drivers that just silently ignored calls to that function have all been fixed by now

Note though that you still have to manually flip parameters to glViewport, glScissor, etc, as glClipControl has no effect on those functions.

Yep, it is easy to forget about the viewport and the scissors...

##### Share on other sites

Well for now this is what i did:

Since gltexImage2D thinks that I'm passing the data in "bottom-top" order I've decided to try make it "work" the D3D way.

1st: In order to match the dynamically rendered textures with the loaded onces. I've added a "flip-Y" version for my projection matrices. This however will change the winding of the front-facing triangles. This was easily solved in my solution because I have one big Structure that describes a single draw call, and I can easily swap "implicitly" my triangle winding.

2st: Flipping the Y component will make the things that are rendered directly to "framebuffer 0(or the 'screen')" flipped. So "flip y" logic shouldn't be applied on framebuffer 0. This is currently solved by hand, becase I'm my "DrawCall strcture" I really don't know where the uniform for projection matrix is located, so I leave this to the user.

So my solution looks like this:

	static SELF_TYPE GetPerspectiveFovRH(
const DATA_TYPE& fov,
const DATA_TYPE& aspect,
const DATA_TYPE& nearZ,
const DATA_TYPE& farZ,
const int GL_Flip_Y = 0) // Does absolutely nothing when rendering with D3D, for OpenGL it just adds the -1 scaling on the Y axis...

struct DrawCall //pseudo code...
{
Buffer* vbuffer;
Buffer* ibuffer;
Program* program;
Buffer** cbuffer;
//other stuff...
GLenum frontFace;
CullMode cullMode;
GLint framebuffer;
int framebufferHeight; // a cached value used for flipping the scissor/viewport rects.
bool GL_Flip_Y_Mode; // Does absolutely nothing under D3D. For the OpenGL case, this will flip the frontFace value, this will also be used for flipping the scissor/viewport rects.
}


And basically "GL_Flip_Y_Mode" is true when the framebuffer != 0 (this is done again by hand, in order not to lose control).

The things are a bit m?ore complicated because I'm trying to implement a "general purpose solution", however having an exact requirements could lead to a lot of simplifications.

?

##### Share on other sites

Well for now this is what i did:

Since gltexImage2D thinks that I'm passing the data in "bottom-top" order I've decided to try make it "work" the D3D way.

1st: In order to match the dynamically rendered textures with the loaded onces. I've added a "flip-Y" version for my projection matrices. This however will change the winding of the front-facing triangles. This was easily solved in my solution because I have one big Structure that describes a single draw call, and I can easily swap "implicitly" my triangle winding.

2st: Flipping the Y component will make the things that are rendered directly to "framebuffer 0(or the 'screen')" flipped. So "flip y" logic shouldn't be applied on framebuffer 0. This is currently solved by hand, becase I'm my "DrawCall strcture" I really don't know where the uniform for projection matrix is located, so I leave this to the user.

So my solution looks like this:

	static SELF_TYPE GetPerspectiveFovRH(
const DATA_TYPE& fov,
const DATA_TYPE& aspect,
const DATA_TYPE& nearZ,
const DATA_TYPE& farZ,
const int GL_Flip_Y = 0) // Does absolutely nothing when rendering with D3D, for OpenGL it just adds the -1 scaling on the Y axis...

struct DrawCall //pseudo code...
{
Buffer* vbuffer;
Buffer* ibuffer;
Program* program;
Buffer** cbuffer;
//other stuff...
GLenum frontFace;
CullMode cullMode;
GLint framebuffer;
int framebufferHeight; // a cached value used for flipping the scissor/viewport rects.
bool GL_Flip_Y_Mode; // Does absolutely nothing under D3D. For the OpenGL case, this will flip the frontFace value, this will also be used for flipping the scissor/viewport rects.
}


And basically "GL_Flip_Y_Mode" is true when the framebuffer != 0 (this is done again by hand, in order not to lose control).

The things are a bit m?ore complicated because I'm trying to implement a "general purpose solution", however having an exact requirements could lead to a lot of simplifications.

?

I've seen renderers designed this way, and they often lead to a lot of headache, especially when you start porting it to different platforms. At one point we had our post processing pipeline pointlessly flipping a rendertarget around 15 times, due to "if (isRenderTarget) flip();"

The (IMO) cleaner option is to at data build time flip all texture data to match the rendertarget orientation for the target platform. This may require the texcoords in your geometry to also be vertically flipped - which may or may not be needed anyway because different art packages may or may not follow any given texture orientation.

But, once you have that data pipeline there, its rather nice having everything consistent at runtime!

##### Share on other sites
But, once you have that data pipeline there, its rather nice having everything consistent at runtime!

Yes this was my pribary concern. The simplest(and the only example that comes to my mind) is a runtime generated quad for post processing, trying to use the native UVs on every platform is a bit tricy becase of that.

I could modify my solution to only need to flip the perspective matrix if under GL and rendering to framebuffer != 0.

Thanks a lot for the feed back, I will use my current set-up in order to see how it actually behaves in practice, and I will give feedback.

Other solutions are still very welcome!

##### Share on other sites

In my engine, I've pretty much covered up all the differences between the APIs, except for this one leaky abstraction -- the right way to build a projection matrix  ... So this is simply left unsolved in my low-level renderer. Instead it unfortunately resides in a high level math library for building matrices...

I solve this by having the math library support its own brand of projection matrix (which I believe is a left-handed Direct3D formula), which makes it complete as a library, but I simply don’t use it.
Any matrices that are graphics-specific are created by passing the matrix to the graphics module and having it create it for me.
CGfx::ProjectionMatrix( CMatrix4x4 &_mMat, LSFLOAT _fFoV, etc. )

No ugly leaks. If you are creating a projection matrix to be used for graphics, use the graphics library to construct it. Simple.

If you have tools that have access to the math library and not the graphics library, I would simply have the math library support both “ProjectionDX()” and “ProjectionGL()” and let the tools decide (likely at run-time rather than via macros).  Again, to keep from leaking graphics macros into the math library.

L. Spiro