I get GL INVALID VALUE after calling glTexSubImage2D I am trying to figure out why my texture allocation does not work. Here is the code glTexStorage2D(GL TEXTURE 2D, 2, GL RGBA8, 2048, 2048) glTexSubImage2D(GL TEXTURE 2D, 0, 0, 0, 2048, 2048, GL RGB, GL UNSIGNED SHORT 5 6 5 REV, amp BitMap 0 ) glTexSubImage2D returns GL INVALID VALUE but the maximum texture allowed is 16384x16384 on my card. The source of the image is 16bit (Red 5, Green 6, Blue 5).


How to make OpenGL rendering resolution independent from its window context resolution? Can the rendering resolution of OpenGL and the window size (at least for the Windows OS) be separated? For example, I may only want to render at 400x300 resolution, but I want my window size to be 800x600. If so, how is this done?


Blending vs Texture Sampling Lets say I want to blend two textures together A texture containing the result of the SSAO calculation. A texture containing the rendered scene. I could do it in two ways Use a shader that samples both the SSAO and scene textures, blends them together and outputs the final color to a render target. Render to the texture containing the scene and use a blending mode to blend the SSAO texture on top of it. Only the SSAO texture will be sampled inside the shader. Is it possible to give a general answer about which version is faster, or is it highly hardware dependent?


GLSL multiplying fragment output color by normal after calling texture function displays wrong texture So I'm quite new to OpenGL GLSL. I'm trying to make multitexturing and simple normal lighting work. Here is a Vertex shader version 130 uniform mat4 transform in vec3 vertPos in vec2 texUV in vec3 vertNorm in uint thisLayer out vec2 fragTexCoord out vec3 fragNorm out float fragLayer void main() gl Position transform vec4(vertPos, 1.0f) fragTexCoord texUV fragLayer float(thisLayer) fragNorm vertNorm ... and here is Fragment shader version 130 uniform sampler2DArray texArray uniform uint texCount uniform float rTime in vec2 fragTexCoord in vec3 fragNorm in float fragLayer out vec4 color void main() float actual layer max(0, min(texCount uint(1), floor(fragLayer 0.5))) Getting texture layer vec3 texCoord vec3(fragTexCoord, actual layer) color texture(texArray, texCoord) And it works fine Multiplying color.rbg by any constant works as expected color texture(texArray, texCoord) color.rgb vec3(0.5, 0.5, 0.5) But if I try to multiply color.rgb by a normal, like this vec3 finalNorm (normalize(fragNorm) vec3(1,1,1)) vec3(2,2,2) color texture(texArray, texCoord) color.rgb finalNorm The wall texture changes to the last texture in the array (the one on the top) I have no idea why this happens. I normalize vertex normals and map their values into 0, 1 range, so colors will stay in 0, 1 range after multiplication as well. It is supposed to simply shift the colors intensity, like it did while multiplying by a constant, not change the texture itself, right? I am aware of the fact that this is not how you perform normal lighting, however, this is not the correct behavior as well, and I'm ripping my hair off as to why. Any help is appreciated. I will provide more info if needed. EDIT OS is Windows 10. GPU's Intel HD 4600 Nvidia GTX 860M (happens on both of them). OpenGL version 4.3.0 build 20.19.15.4624. Some additional info I use SOIL library to load data from PNG files. I use glTexImage3D(GL TEXTURE 2D ARRAY, 0, GL RGBA, img width, img height, layer count 2, 0, GL RGBA, GL UNSIGNED BYTE, 0) to create a container for texture array, and use glTexSubImage3D(GL TEXTURE 2D ARRAY, 0, 0, 0, i, img width, img height, layer count, GL RGBA, GL UNSIGNED BYTE, data) to load data into it. One issue I have with this is that glTexImage3D takes layer count (the number of textures) multiplied by 2, and I have no idea why as well! Maybe this is somehow related to the issue I'm having above?


How to free the GPU from a long task? I'm developing an application that uses the GPU. Some tasks might be rather long (like a fragment shader with a loop). I have the impression that I can make the entire OS visually freeze by asking the GPU to perform a job that doesn't end. Of course, I'm not doing this on purpose, but when that accidentally happens, I have to force power off my machine and this is very difficult to debug. Some questions Is this behaviour normal? Or could this be a bug in the hardware or driver? Is there a technique to recover from this without force stopping my machine? Since the OS is still functioning (only not rendering), I could try to ssh into my machine and kill the process. Would that free the GPU from its job? Update I tried to ssh into my machine and sudo kill 9 pid , but didn't work. I would like to know if there is an OS independent answer for this. If there isn't, my setup is macOS, with OpenGL (running on Intel HD Graphics 3000).


shadow mapping and linear depth I'm implementing ominidirectional shadow mapping for point lights. I want to use a linear depth which will be stored in the color textures (cube map). A program will contain two filtering techniques software pcf (because hardware pcf works only with depth textures) and variance shadow mapping. I found two ways of storing linear depth const float linearDepthConstant 1.0 (zFar zNear) first float moment1 viewSpace.z linearDepthConstant float moment2 moment1 moment1 outColor vec2(moment1, moment2) second float moment1 length(viewSpace) linearDepthConstant float moment2 moment1 moment1 outColor vec2(moment1, moment2) What are differences between them ? Are both ways correct ? For the standard shadow mapping with software pcf a shadow test will depend on the linear depth format. What about variance shadow mapping ? I implemented omnidirectional shadow mapping for points light using a non linear depth and hardware pcf. In that case a shadow test looks like this vec3 lightToPixel worldSpacePos worldSpaceLightPos vec3 aPos abs(lightToPixel) float fZ max(aPos.x, max(aPos.y, aPos.z)) vec4 clip pLightProjection vec4(0.0, 0.0, fZ, 1.0) float depth (clip.z clip.w) 0.5 0.5 float shadow texture(ShadowMapCube, vec4(normalize(lightToPixel), depth)) I also implemented standard shadow mapping without pcf which using second format of linear depth (Edit 1 i.e. distance to the light some offset to fix shadow acne) vec3 lightToPixel worldSpacePos worldSpaceLightPos const float linearDepthConstant 1.0 (zFar zNear) float fZ length(lightToPixel) linearDepthConstant float depth texture(ShadowMapCube, normalize(lightToPixel)).x if(depth lt fZ) shadow 0.0 else shadow 1.0 but I have no idea how to do that for the first format of linear depth. Is it possible ? Edit 2 For non linear depth I used glPolygonOffset to fix shadow acne. For linear depth and distance to the light some offset should be add in the shader. I'm trying to implement standard shadow mapping without pcf using a linear depth ( viewSpace.z linearDepthConstant offset) but following shadow test doesn't produce correct results vec3 lightToPixel worldSpacePos worldSpaceLightPos vec3 aPos abs(lightToPixel) float fZ max(aPos.x, max(aPos.y, aPos.z)) vec4 clip pLightProjection vec4(0.0, 0.0, fZ, 1.0) float fDepth (clip.z clip.w) 0.5 0.5 float depth texture(ShadowMapCube, normalize(lightToPixel)).x if(depth lt fDepth) shadow 0.0 else shadow 1.0 How to fix that ?


How can I simulate a limited (256) color palette in OpenGL? On Twitter, I found this screenshot of a game in development The image on top seems to be without any color limitation. But the two other pictures at the bottom have a 256 color palette. I want to achieve a similar effect in my game (I am using OpenGL). How can I do so?


GLM Euler Angles to Quaternion I hope you know GL Mathematics (GLM) because I've got a problem, I can not break I have a set of Euler Angles and I need to perform smooth interpolation between them. The best way is converting them to Quaternions and applying SLERP alrogirthm. The issue I have is how to initialize glm quaternion with Euler Angles, please? I read GLM Documentation over and over, but I can not find appropriate Quaternion constructor signature, that would take three Euler Angles. The closest one I found is angleAxis() function, taking angle value and an axis for that angle. Note, please, what I am looking for si a way, how to parse RotX, RotY, RotZ. For your information, this is the above metnioned angleAxis() function signature detail tquat lt valType gt angleAxis (valType const amp angle, valType const amp x, valType const amp y, valType const amp z)


What is the best method to update shader uniforms? What is the most accepted way for keeping a shader's matrices up to date, and why? For example, at the moment I have a Shader class that stores the handles to the GLSL shader program amp uniforms. Every time I move the camera I then have to pass the new view matrix to the shader, then every different world object I must pass it's model matrix to the shader. This severely limits me as I can't do anything without having access to that shader object. I thought of creating a singleton ShaderManager class that is responsible for holding all active shaders. I can then access that from anywhere and a world object wouldn't have to know about what shaders are active just that it needs to let the ShaderManager know the desired matrices but I'm not sure this is the best way and there's probably some issues that will arise from taking this approach.


Opengl lighting not working I have rendered a spinning model in LWJGL. I have calculated normals and enabled lighting. Now I make a light float lightpos 0, 0, 0, 0 FloatBuffer lightposb BufferUtils.createFloatBuffer(8) lightposb.put(lightpos) glLight(GL LIGHT0, GL POSITION, lightposb) float light 10, 10, 10, 1 FloatBuffer lightb BufferUtils.createFloatBuffer(8) lightb.put(light) glLight(GL LIGHT0, GL SPECULAR, lightb) glLight(GL LIGHT0, GL DIFFUSE, lightb) glLight(GL LIGHT0, GL AMBIENT, lightb) The model, instead of being lit up, is a dark gray. Also, no color appears on the model, even though I set its color to cyan float color 0,1,1,1 FloatBuffer colorb BufferUtils.createFloatBuffer(8) colorb.put(color) glMaterial(GL FRONT, GL AMBIENT, colorb) UPDATE Even though I have calculated normals and set them with glNormal3f, the model still appears to be shaded flat. UPDATE I HAVE done glEnable(GL LIGHTING) and glEnable(GL LIGHT0) that is NOT the problem. UPDATE I reversed the order of the light code and the model code and now the model flashes white, then goes dark grey and stays there.


Animate some tiles of tile map I have a game where each "tile" of the terrain is a triangle (Settlers 2). Those are placed next to each other and in way creating an infinite world (right bottom jumps back to left top). There is a 3D component (each triangle point has a height) but that gets translated into an Y position offset, so everything can be considered 2D. Everything (texture coords, screen coords, color (white lt black, FoW)) is put into VBOs already and usually does not change (FoW may disappear which updates the color VBO, but rarely) When drawing I iterate over the visible tiles (currently in view) and collect "runs" of tiles with the same texture. After that I do Bind current texture Draw current run (offset into VBOs num of same textured tiles) Repeat until all runs are drawn To reduce the number of texture switches I wanted to create a texture atlas. But the problem Some textures are animated (texture animation so all tiles use the same frame of the animation at any given time) and those animations may be different. To give some numbers 30 textures, pretty small ( 30 60px each) 8 are animated, rest static animation length is 4 8 frames animation frame time is constant How would I best go with those animations? Put all static textures into 1 texture, animated ones into separate ones? Unroll animations so I have 8 textures (possibly 24 if I have 8 frame and 6 frame animations) where each texture is 1 frame (so static textures are copied into those unmodified) Repeat all textures into 1 texture and do some U coordinate shifting in a shader (not used ATM, but will add soon) again possible waste Some shader magic? Using OpenGL 2.1, C . Visualization of 3 textures Triangles cut out from squares in any position (in fact only 6 are possible Top to bottom, top to middle, top to middle rotated by 135 and their mirrored counterparts). Shown is 1 of 2 triangles per square, the other one is mirrored horizontally. All tiles may have different sizes


Can I change the order of these OpenGL Win32 calls? I've been adapting the NeHe OpenGL Win32 code to be more object oriented and I don't like the way some of the calls are structured. The example has the following pseudo structure Register window class Change display settings with a DEVMODE Adjust window rect Create window Get DC Find closest matching pixel format Set the pixel format to closest match Create rendering context Make that context current Show the window Set it to foreground Set it to having focus Resize the GL scene Init GL The points in bold are what I want to move into a rendering class (the rest are what I see being pure Win32 calls) but I'm not sure if I can call them after the Win32 calls. Essentially what I'm aiming for is to encapsulate the Win32 calls into a Platform Initiate() type method and the rest into a sort of Renderer Initiate() method. So my question essentially boils down to quot Would OpenGL allow these methods to be called in this order? quot Register window class Adjust window rect Create window Get DC Show the window Set it to foreground Set it to having focus Change display settings with a DEVMODE Find closest matching pixel format Set the pixel format to closest match Create rendering context Make that context current Resize the GL scene Init GL (obviously passing through the appropriate window handles and device contexts) Thanks in advance.


Event Based Render Update Loop I'm working on a few game dev tools which use OpenGL or DirectX to render 3D models (viewing). Consider your favorite 3D modeling software package (Softimage, Maya, 3DS Max, modo, etc.). Note that the 3D viewport does not sit in a constant render loop pegged at max FPS. It remains idle (0 FPS) until some action is taking place in the viewport such as moving the viewport camera from side to side using the mouse or pressing play for animation. If the viewport is idle, there is no drain on the CPU GPU. I'd like to use this technique in a couple of tools I'm working on and possibly within the game. Is there a generally accepted programming technique with OpenGL and or DirectX (via C ) that will achieve this? One solution would be to do a standard render loop and check for input 1000s of times per second, but that seems inefficient and hard to manage as you add more and more quot events quot which would trigger a updated render. Please let me know if the question is unclear. If I knew how to describe it perfectly I could probably just search google.


OpenGL How to map point inside frustrum to normal device coordinates (NDC)? I read this article http www.songho.ca opengl gl projectionmatrix.html. It's explain how calculate projection matrix coefficients. But I completely can't understand how author perform mapping from frustrum to NDC. Why x n perpendicular to x p? I can't imagine it. Maybe someone can explain it? Or share useful source.


Geometry design and buffers I'm making some tests with rendering stuff and I'm wondering how to design my Geometry class. For the moment, here is how I do Init Stock array with positions, array with colors, array with normals, has attributes. Just before rendering, if my geometry have changed, I update his vertex buffer and index buffer. To do that, I compute interleaved array here and send it to my vertex buffer. I've made some tests with particles (10000 on iPad), the heaviest function is "Geometry computeInterleavedArray. How can I avoid this part? Is it better to stock geometry's data inside a single array with all data already interleaved?


libgdx glClearColor not setting right color? i just new to libgdx and trying to understand the example code, the following code sets the bg color Gdx.gl.glClear(GL10.GL COLOR BUFFER BIT) Gdx.gl.glClearColor(60,181,00,0f) my expected color is green, R 60 Green 181 B 0, but the about code show me yellow color in my android app, anything i'm doing wrong? http rapid tools.net online color picker


OpenglGL Render two scenes with one draw call I need to draw a normal vector scene and default scene. I could achieve this my having two programs with different fragment shader to produce the following images. It will require me to draw twice. somethinglike useProgram(normal vector rendering program) render bunny() useProgram(just default scene program) render bunny() However when I am rendering the default scene, I am already passing normal vector information to achieve the lighting. So it got me curious, can I produce two different scenes with one program(a program that has two color buffer attaches) and one draw call somehow? I think if such is possible then I am saving lots of computer resource by not having to draw multiple times for different images.


Translating Viewmatrix is inverted, why? So I've defined a Projectionmatrix, Viewmatrix and a Modelmatrix using OpenGL (LWJGL). But when I translate my Viewmatrix to X it moves my object to the right (hence my camera is moving to the left), and when I move it to X the object moves to the left (camera moving to the right). Same goes for Y movement, Z works as it should though. My matrices are as follows Projectionmatrix perspectiveMatrix new Matrix4f() perspectiveMatrix.setIdentity() float aspectRatio WIDTH HEIGHT float zRange zNear zFar COLUMN ROW perspectiveMatrix.m00 (float) (1.0f (aspectRatio Math.tan(degreesToRadians(fieldOfView 2.0f)))) perspectiveMatrix.m11 (float) (1.0f (Math.tan(degreesToRadians(fieldOfView 2.0f)))) perspectiveMatrix.m22 ( zNear zFar) zRange perspectiveMatrix.m23 1 perspectiveMatrix.m32 (2 zFar zNear) zRange Viewmatrix Matrices.viewMatrix new Matrix4f() Matrix4f.setIdentity(Matrices.viewMatrix) Initialize all vectors this.xAxis new Vector3f() this.yAxis new Vector3f() this.zAxis new Vector3f() this.newPos new Vector3f() this.currPos new Vector3f() position.xyz 0, 2, 7 target.xyz 0, 0, 1 up.xyz 0, 1, 0 Set all values to the Camera class values position.negate(this.currPos) target.normalise(this.zAxis) up.normalise(this.yAxis) Vector3f.cross(target, up, xAxis) Vector3f.cross(xAxis, target, yAxis) Recalulate yAxis to make it valid coordinate system. This defines the View Matrix. This is calculated and explained here http ogldev.atspace.co.uk www tutorial13 tutorial13.html m(Column)(Row) Matrices.viewMatrix.m00 xAxis.x Matrices.viewMatrix.m10 xAxis.y Matrices.viewMatrix.m20 xAxis.z Matrices.viewMatrix.m01 yAxis.x Matrices.viewMatrix.m11 yAxis.y Matrices.viewMatrix.m21 yAxis.z Matrices.viewMatrix.m02 zAxis.x Matrices.viewMatrix.m12 zAxis.y Matrices.viewMatrix.m22 zAxis.z Matrices.viewMatrix.m33 1 Matrices.viewMatrix.translate(this.currPos) Modelmatrix Identity


GLSL Multiple Uniform Structs I'm developing a lighting system for my voxel game, and I have to send multiple (alot, say up to 200) lights to my shader program. Those lights contain the following data Position (vec3) Color (vec3) Radius (float) Strength (float) What is the most efficient way to send alof of those light structs to my shaders? I would like it to work with lower versions of OpenGL, like 2.1.


How to rotate a direction I'm working a spotlight for my deferred renderer and I'm having trouble with matching the mesh to the visual representation of the light. Right now my mesh is a cone, the apex of the cone is at (0,0,0), it has a height of 1 and a radius of 1. The direction of this cone is (0, 1,0) when the rotation is (0,0,0). The relevant GLSL code float spot alpha dot( l,normalize(vec3(0, 1,0) )) lt float inner alpha cos(light.falloff) float outer alpha cos(light.radius) float spot clamp((spot alpha outer alpha) (inner alpha outer alpha),0.,1.) As you can see, the GLSL code uses a direction to define the area to be lit, so I could get this direction as a uniform, but I would need to find a rotation from that for the mesh to follow, or I can get the rotation and find a direction, but I don't know how to do either of these things. Can I rotate a direction? How do I do it? If I can't, is there another solution for this problem?


How do multipass shaders work in OpenGL? In Direct3D, multipass shaders are simple to use because you can literally define passes within a program. In OpenGL, it seems a bit more complex because it is possible to give a shader program as many vertex, geometry, and fragment shaders as you want. A popular example of a multipass shader is a toon shader. One pass does the actual cel shading effect and the other creates the outline. If I have two vertex shaders, "cel.vert" and "outline.vert", and two fragment shaders, "cel.frag" and "outline.frag" (similar to the way you do it in HLSL), how can I combine them to create the full toon shader? I don't want you saying that a geometry shader can be used for this because I just want to know the theory behind multipass GLSL shaders )


Methods to 'cull check' polys in OpenGL A quick search through the web suggests there's quite a few methods of potentially detecting back culled faces on the CPU. The purpose of the check is to evaluate whether to performing other operations such as tessellations is reasonable by dynamically altering the LOD of visible polys based on the number of polys on the screen. What would your suggestions be for implementing this? Speed isn't necessarily the greatest concern for this prototype mathematical simplicity is more important. Code snippets welcome ) Edit It seems obvious to me to calculate the dot product based on the camera's viewing vector in world space against the surface normal vector but I'm asking this question because I'm intrigued as to why everyone and their (programming genius) dog seems to have an alternative method of handling this.


How to store renderer vertex index data in scene graph objects? I have a SceneNode class which contains a Mesh instance. The Mesh class stores client side information such as vertex and index arrays (before they're uploaded to the GPU). I also have an abstracted Renderer class, for GL and D3D, which render the SceneNodes. However, I'm not sure where I should store the API specific variables, e.g. GLuint via glGenBuffers for GL, and an ID3D11Buffer for D3D. The few options I've considered are Create a derived Mesh class for each API, e.g. GLMesh D3DMesh Create a derived MeshData class for each API, which is stored in the main Mesh class Store a map of Mesh to API variables in each renderer, e.g. perform a lookup of Mesh to GLuint ID3D11Buffer for each object that is rendered (variables would have to be generated after the scene had been updated, but before rendering). Separate the logic of rendering from scenes, by visiting the SceneGraph after update, and generating a RenderGraph of all renderable nodes in the scene. What's the recommended way of doing this?


Best strategy on VAO and texture coordinates for voxel rendering? I'm working on a game that has to render a large amount of cubes (voxels) with OpenGL. All cubes have the same geometry (so I can re use the vertex position VBO) and a single sprite sheet texture is used for all of them. This means the texture coordinates will have to vary for the cubes, depending on which sprite to use. All six sides of a cube will use the same sprite (in other words, the same texture coordinates). Now, what is the best strategy to approach this with a modern OpenGL renderer? I came up with two possibilities Create as many VAOs as there are cube sprites in the sprite sheet. Bind the same vertex position VBO to all of them, but a different texture coordinate VBO (according to what sprite part of the texture to show). In my specific case, this would make for about 600 different texture coordinate VBOs and therefore 600 VAOs. Create only one VAO. Set up the texture coordinate VBO in a generic way (e.g. 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0). In the rendering loop, send the actual texture coordinates (only 4 values) as uniform variable to the shaders. In the shader, the generic texture coordinates can be used to figure out which two of the four values from the uniform should be used. Are there other possibilities that I'm missing? What is best regarding performance?


OpenGL Reconstructing Position from Depth I know this has been asked a lot of time before but none of those answers fixed my problem. I try to implement deferred shading and to do so I need to reconstruct the world space position from the depth. (Having a position texture in the gbuffer would be a waste of data) The calculation works fine for rotationing the camera ( moving the mouse) but as soon as I move the camera ( pressing wasd) they get weird. GLSL vec4 screenSpacePosition vec4(pass Texture 2.0 1.0, texture(gbuffer texture 2 , pass Texture).r, 1) vec4 worldSpacePosition invertedViewProjection screenSpacePosition vec3 finalPosition worldSpacePosition.xyz worldSpacePosition.w gbuffer texture 2 is the depth attachment of OpenGL. invertedViewProjection is the matrix I used to render the scene inverted on the CPU.


Why am I having trouble, combining color attachments to implement bloom? I'm trying to implement bloom in the same manner as this tutorial, but I am having difficulties. I have the blur buffer blurring correctly, but I can't seem to combine the two images. Below, you will find my code. The commented out lines just render one or the other buffer to the screen, so I know these are correct. For now, I am just trying to combine them together not fix them with HDR. I just add together both textures, but no matter how I change things around, all I get is the one on the left. blurShader.use() glUniform1i(glGetUniformLocation(blurShader.program, "horizontal"), true) glBindFramebuffer(GL FRAMEBUFFER, pingpongFBO 1 ) long blurCount 5 for(long i 0 i lt blurCount i ) glClear(GL COLOR BUFFER BIT GL DEPTH BUFFER BIT) glActiveTexture(GL TEXTURE0) bind texture of other framebuffer (or scene if first iteration) glBindTexture(GL TEXTURE 2D, pingpongColorbuffers i 2 ) RenderQuad() glBindFramebuffer(GL FRAMEBUFFER, pingpongFBO i 2 ) glUniform1i(glGetUniformLocation(blurShader.program, "horizontal"), false) for(long i 0 i lt blurCount i ) glClear(GL COLOR BUFFER BIT GL DEPTH BUFFER BIT) glActiveTexture(GL TEXTURE0) bind texture of other framebuffer (or scene if first iteration) glBindTexture(GL TEXTURE 2D, pingpongColorbuffers (i 1) 2 ) RenderQuad() glBindFramebuffer(GL FRAMEBUFFER, pingpongFBO (i 1) 2 ) glBindFramebuffer(GL FRAMEBUFFER, 0) renderScreenQuad(colorBuffers 0 ) renderScreenQuad(pingpongColorbuffers 1 ) 2. Now render floating point color buffer to 2D quad and tonemap HDR colors to default framebuffer's (clamped) color range glClear(GL COLOR BUFFER BIT GL DEPTH BUFFER BIT) bloomShader.use() glActiveTexture(GL TEXTURE0) glBindTexture(GL TEXTURE 2D, colorBuffers 0 ) glActiveTexture(GL TEXTURE1) glBindTexture(GL TEXTURE 2D, pingpongColorbuffers 1 ) glUniform1i(glGetUniformLocation(bloomShader.program, "bloom"), bloom) glUniform1f(glGetUniformLocation(bloomShader.program, "exposure"), exposure) RenderQuad() version 330 core out vec4 FragColor in vec2 TexCoords uniform sampler2D colorTexture uniform sampler2D bloomTexture uniform bool bloom uniform float exposure void main() vec3 firstColor texture(colorTexture, TexCoords).rgb vec3 secondColor texture(bloomTexture, TexCoords).rgb FragColor vec4(firstColor secondColor, 1.0f) version 330 core layout (location 0) in vec3 position layout (location 1) in vec2 texCoords out vec2 TexCoords void main() gl Position vec4(position, 1.0f) TexCoords texCoords Basically, what happens is that the first image bound goes through, and is accessible. Then, the second is the same as the first! If I change the order in which I bind the images, then the other image becomes the one sent in. glClear(GL COLOR BUFFER BIT GL DEPTH BUFFER BIT) glActiveTexture(GL TEXTURE0) glBindTexture(GL TEXTURE 2D, pingpongColorbuffers 0 ) glActiveTexture(GL TEXTURE1) glBindTexture(GL TEXTURE 2D, pingpongColorbuffers 1 ) glUniform1i(glGetUniformLocation(bloomShader.program, "bloom"), bloom) glUniform1f(glGetUniformLocation(bloomShader.program, "exposure"), exposure) RenderQuad() The above code is the section I'm talking about. Each of the pingpongcolorbuffers is attached to its own FBO. I am trying to send those in. Is there some reason that would limit me to sending in only one? Here is the combined result, before HDR


Can DDS be used in OpenGL in Linux without license patent issue? Is there a 'standard' for OpenGL game creation intended for both Windows and Linux? I understand DDS is the DirectX standard (or, at least, it appears to be). Is there one that does not have potential patent license issue or does it really not matter? I am asking as I would like to avoid focusing on DDS as the format to use, only to have that kick me in the teeth later when some license patent ??? issue requires me to remove and replace DDS with texture format here . This is not about what is better or an opinion post, but what is (relatively) safe from the constraints mentioned earlier?


My sweep and prune is giving false positives My code is just giving false positives. Every frame it reports an imaginary collision. Here is my code Sweep And Prune public static void updateObjects() List lt BoundingBox gt activeList new LinkedList lt gt () boolean adding true for (BoundingBox box axisList) box.getOverlappingPairs().clear() if(adding) activeList.add(box) adding false else for(BoundingBox e activeList) if(box.collides(e)) box.setOverlappingPairs(e) System.out.println("COLLISION " box " " e) else activeList.remove(box) Edit My AABB boxes are colliding with themselves. I have debugged my classes and have narrowed it down to the sweep and prune class. I would appreciate if someone would help me.


rotate opengl mesh relative to camera I have a cube in opengl. It's position is determined by multiplying it's specific model matrix, the view matrix, and the projection matrix and then passing that to the shader as per this tutorial (http www.opengl tutorial.org beginners tutorials tutorial 3 matrices ). I want to rotate it relative to the camera. The only way I can think of getting the correct axis is by multiplying the inverse of the model matrix (because that's where all the previous rotations and tranforms are stored) times the view matrix times the axis of rotation (x or y). I feel like there's got to be a better way to do this like use something other than model, view and projection matrices, or maybe I'm doing something wrong. That's what all the tutorials I've seen use. PS I'm also trying to keep with opengl 4 core stuff. edit If quaternions would fix my problems, could someone point me to a good tutorial example for switching from 4x4 matrices to quaternions. I'm a little daunted by the task.


How would you implement chromatic aberration? How would you implement the effect of chromatic aberration with shaders? Would rendering of the world with different focus distances for each color solve the problem (maybe with the usage of only one depth rendering pass)?


Shadowmap first phase and shaders I am using OpenGL 3.3 and am tryin to implement shadow mapping using cube maps. I have a framebuffer with a depth attachment and a cube map texture. My question is how to design the shaders for the first pass, when creating the shadowmap. This is my vertex shader in vec3 position uniform mat4 lightWVP void main() gl Position lightWVP vec4(position, 1.0) Now, do I even need a fragment shader in this shader pass? from what I understand after reading http www.opengl.org wiki Fragment Shader, by default gl FragCoord.z is written to the currently attached depth component (to which my cubemap texture is bound to). Thus I shouldnt even need a fragment shader for this pass and from what I understand, there is no other work to do in the fragment shader other than writing this value. Is this correct?


How to put triangle information into a glsl shader for dynamic shadows? I am experimenting with how much I can push the GPU with clever optimizations and correct use of hardware, so I know this may lag my computer a lot, that's not the issue. Currently my goal is as follows Define a variable size structure (i.e an array) that contains floats, every 3 floats define a position vector, every 9 define a triangle. I need to create an array of these structures (the array of all shadow casting objects currently loaded) and pass the array to the GPU (the glsl shader). If I follow a couple of conventions when putting my data into this format I can use hashing to get an amortized constant search time for the shadow casting triangles, The issue is to get the data into the format that I need. If this was C the format would be an array of vectors and we're done, but GLSL is not as good at managing memory, does somebody know a way to pass the information in the fashion I described, or am I trying to do something that can't be done?


Slick2D crashes on Image.getGraphics() on some machines On some machines, creating a new Image and calling getGraphics() on it causes lwjgl to enter into some kind of faulty state that crashes when swapping buffers. Any idea what causes this and how to make Slick clean up after itself properly? Reproduction code package crashrepro import org.newdawn.slick. public class CrashRepro extends BasicGame public static void main(String args) throws Exception CrashRepro cr new CrashRepro("CrashRepro") Crash only happens in fullscreen mode. AppGameContainer agc new AppGameContainer(cr, 800, 600, true) agc.start() public CrashRepro(String title) super(title) Override public void init(GameContainer gc) throws SlickException Override public void update(GameContainer gc, int i) throws SlickException Override public void render(GameContainer gc, Graphics grphcs) throws SlickException Image img new Image(128, 128) img.getGraphics() This crashes the game. Stack trace Java frames (J compiled Java code, j interpreted, Vv VM code) j org.lwjgl.opengl.WindowsContextImplementation.nSwapBuffers(Ljava nio ByteBuffer )V 0 j org.lwjgl.opengl.WindowsContextImplementation.swapBuffers()V 35 j org.lwjgl.opengl.ContextGL.swapBuffers()V 3 j org.lwjgl.opengl.DrawableGL.swapBuffers()V 0 j org.lwjgl.opengl.Display.swapBuffers()V 39 j org.lwjgl.opengl.Display.update(Z)V 44 j org.lwjgl.opengl.Display.update()V 1 j org.newdawn.slick.AppGameContainer.gameLoop()V 78 j org.newdawn.slick.AppGameContainer.start()V 17 j crashrepro.CrashRepro.main( Ljava lang String )V 27 v StubRoutines call stub


Confused About My Code Suggesting The Normal Matrix Is Equivalent To The ModelView Matrix I'm learning environment mapping in OpenGL by following this page. In his vertex shader, the author calculates the vertex normal in eye space with the following code nEye vec3(viewMatrix modelMatrix vec4(vertexNormal, 0.0)) This works, but I've fooled around and made modifications to the shader code, so that it calculates the vertex normal with this code nEye vec3(normalMatrix vec4(vertexNormal, 0.0)) Where normalMatrix is a uniform 4x4 matrix I calculated outside the shader objectNormalMatrix viewMatrix modelMatrix objectNormalMatrix.invert() objectNormalMatrix.transpose() (I read from this question that the above is how you are supposed to calculate the normal matrix). For either method of calculating the vertex normal I use, I get the same (working) graphical result, and this is what is confusing me. My question is, why is(viewMatrix modelMatrix) apparently equivalent normalMatrix? In calculating the normal matrix, I invert and transpose, but I do none of that when just multiplying by (viewMatrix modelMatrix). Here is some extra info that might be relevant The matrix library I use in my application is column major order (same as OpenGL). When I pass my matrices to GLSL with glUniformMatrix, I have transpose as false. The view matrix and model matrix in GLSL are uniforms from the application, and they are the exact same view matrix and model matrix matrices I use in my calculation of the normal matrix.


How do I draw a point sprite using OpenGL ES on Android? Edit I'm using the GL enum, which is incorrect since it's not part of OpenGL ES (see my answer). I should have used GL10, GL11 or GL20 instead. Here's a few snippets of what I have so far... void create() renderer new ImmediateModeRenderer() tiles Gdx.graphics.newTexture( Gdx.files.getFileHandle("res tiles2.png", FileType.Internal), TextureFilter.MipMap, TextureFilter.Linear, TextureWrap.ClampToEdge, TextureWrap.ClampToEdge) void render() Gdx.gl.glClear(GL10.GL COLOR BUFFER BIT GL10.GL DEPTH BUFFER BIT) Gdx.gl.glClearColor(0.6f, 0.7f, 0.9f, 1) void renderSprite() int handle tiles.getTextureObjectHandle() Gdx.gl.glBindTexture(GL.GL TEXTURE 2D, handle) Gdx.gl.glEnable(GL.GL POINT SPRITE) Gdx.gl11.glTexEnvi(GL.GL POINT SPRITE, GL.GL COORD REPLACE, GL.GL TRUE) renderer.begin(GL.GL POINTS) renderer.vertex(pos.x, pos.y, pos.z) renderer.end() create() is called once when the program starts, and renderSprites() is called for each sprite (so, pos is unique to each sprite) where the sprites are arranged in a sort of 3D cube. Unfortunately though, this just renders a few white dots... I suppose that the texture isn't being bound which is why I'm getting white dots. Also, when I draw my sprites on anything other than 0 z axis, they do not appear I read that I need to crease my zfar and znear, but I have no idea how to do this using libgdx (perhaps it's because I'm using ortho projection? What do I use instead?). I know that the texture is usable, since I was able to render it using a SpriteBatch, but I guess I'm not using it properly with OpenGL.


Hardware Fragment Sorting? I'm writing a rendering engine in OpenGL. I Want to do order independent transparency. I had heard somewhere that some GPUs have support for actually sorting the fragments of all the objects in the scene based on depth and then drawing them. I then realized that this feature is likely very important to many people. Does OpenGL have a built in fragment sorting algorithm, or access to this hardware?


Enabling multisampling in Irrlicht? I'm working on a little game that uses Irrlicht. I'm pretty new to Irrlicht and I was wondering how I could enable multisampling. The device driver is EDT OPENGL initiated as such IrrlichtDevice device createDevice(video EDT OPENGL, core dimension2d lt u32 gt (800, 700), 16, NO) How do I enable multisampling?


Nothing gets rendered in SceneKit I have this code in OpenGL Vuforia Matrix44F modelViewProjection VuforiaApplicationUtils translatePoseMatrix(0.0f, 0.0f, self.scale, amp Vuforia modelViewMatrix.data 0 ) VuforiaApplicationUtils scalePoseMatrix(self.scale, self.scale, self.scale, amp Vuforia modelViewMatrix.data 0 ) VuforiaApplicationUtils multiplyMatrix( amp projectionMatrix.data 0 , amp Vuforia modelViewMatrix.data 0 , amp modelViewProjection.data 0 ) And the modelViewProjection gets used like this glUniformMatrix4fv(mvpMatrixHandle, 1, GL FALSE, (const GLfloat ) amp modelViewProjection.data 0 ) With mvpMatrixHandle being a piece of code in the shader mvpMatrixHandle glGetUniformLocation(shaderProgramID, "modelViewProjectionMatrix") And in the shader itself gl Position modelViewProjectionMatrix vertexPosition Now I try to convert this to SceneKit code (never used it before, so I might miss a big part of my SceneKit code) Setup let plane SCNNode(mdlObject MDLAsset(url Bundle.main.url(forResource "Bubble", withExtension "obj")!).object(at 0)) scene.rootNode.addChildNode(plane) let camera SCNCamera() plane.camera camera Each frame modelViewMatrix SCNMatrix4Translate(modelViewMatrix, 0, 0, scale) modelViewMatrix SCNMatrix4Scale(modelViewMatrix, scale, scale, scale) let modelViewProjection SCNMatrix4Mult(arrayToMatrix(pose projectionMatrix), modelViewMatrix) camera.projectionTransform modelViewProjection scene.rootNode.childNodes 0 .transform modelViewProjection As you can see, I have also tried to set this as the projectionTransform of the camera, but that did not work either. My result is the most annoying to debug nothing gets rendered using the SceneKit code, while the OpenGL code works.


OpenGL strange rendering problem when buffers have different sizes I have encountered a very odd error in my program, "odd" in the sense that everything the API says suggests that the error should not occur. I have a bunch of 2D un indexed vertex data, and I want to render it as lines. So far, so good. Then, I wanted to make each vertex have its own (RGB) color, so I generate a color for each vertex. For simplicity, I chose red. Works fine, except now only 2 3 of the points are being rendered! The problem arises from the fact that each vertex's position data consists of only 2 numbers, whereas the color data consists of 3 numbers. So, the "position" buffer has 2 elements per vertex while the "color" one has 3 elements per vertex. I thought that using glVertexAttribPointer to tell this information to OpenGL would be enough, but turns out it's not. In fact, if I say that the color data has only 2 elements per vertex, using glVertexAttribPointer(vertexColorID2,2,GL DOUBLE,GL FALSE,0,(void )0) (as opposed to 3), it renders all the points except now I can only specify two numbers for the RGB color, so I can't get the right color. The full code of the issue is below glUseProgram(programID2) draw the graph graph data graphData() std vector lt double gt graphcolordata(graph data.size() 2 3) for (int i 0 i lt graph data.size() i 3) graphcolordata i 1 glEnableVertexAttribArray(vertexPosition modelspaceID2) glBindBuffer(GL ARRAY BUFFER, graphbuffer) glBufferData(GL ARRAY BUFFER, graph data.size() sizeof(GLdouble), amp graph data 0 , GL STREAM DRAW) glVertexAttribPointer(vertexPosition modelspaceID2,2,GL DOUBLE,GL FALSE,0,(void )0) glEnableVertexAttribArray(vertexColorID2) glBindBuffer(GL ARRAY BUFFER, colorbuffer2) glBufferData(GL ARRAY BUFFER, graphcolordata.size() sizeof(GLdouble), amp graphcolordata 0 , GL STREAM DRAW) glVertexAttribPointer(vertexColorID2,3,GL DOUBLE,GL FALSE,0,(void )0) glDrawArrays(GL LINES, 0, graph data.size() 2) glDisableVertexAttribArray(vertexPosition modelspaceID2) glDisableVertexAttribArray(vertexColorID2) Note programID2 is my basic shader program, and the following variable definitions were previously used GLuint vertexPosition modelspaceID2 glGetAttribLocation(programID2, "vertexPosition modelspace") GLuint vertexColorID2 glGetAttribLocation(programID2, "vertexColor") Edit Incredibly stupid error, figured it out immediately after posting when it had previously stumped me for half an hour. std vector lt double gt graphcolordata(graph data.size() 2 3) for (int i 0 i lt graph data.size() i 3) graphcolordata i 1 should be std vector graphcolordata(graph data.size() 2 3) for (int i 0 i lt graphcolordata.size() i 3) graphcolordata i 1 When this initialization is fixed, it works fine. I would delete this, but I do not see how.


OpenGL Orthographic projection questions I'm studying now about projections with OpenGL and I've some questions Is there importance for the viewer's location? I know if I move forward backward it won't mind, but what if I move upward with 30 degrees for e.g. Does the viewer is located in the 0,0,0 axis? or he can be in another place after defining glOrtho's properties. Are there only 6 projections? (I'm asking this because of the properties of the box, and defining the glOrtho near, far, left, right, up, bottom) Can I hide objects with ortho proj? I think it's obvious that yes, but I'm still curious maybe I'm wrong. Do objects that are closer to me seem bigger, meaning that other objects may be hidden? I believe that not. the objects don't seem bigger. they stay the same size.


Using a programmable pipeline in a game engine As a learning experience, I'm developing my own 3D game engine using OpenGL. I'm a little confused as to how to implement my rendering engine such that it uses a programmable pipeline while still being responsible for projecting and displaying vertices correctly. Let's say my engine has a simple vertex shader that uses projection and modelview matrices to project a vertex in 3D space. How do I use the engine's vertex shader while still allowing the programmer to provide his her own vertex shader for other calculations in their game? What is the normal approach here?


How can I make a transparent hole with shaperenderer using stencil masking in libgdx? I'm making a 2d game, where I need a resizeable, moveable rectangle outline. I'm trying to use stencil masking to do it by cutting a hole in a solid rectangle, and I thought this would help How can I add a transparent overlay to a UI in libGDX? But all I get is a solid box. Here's my code Gdx.gl.glClear(GL STENCIL BUFFER BIT) Gdx.gl.glColorMask(false, false, false, false) Gdx.gl.glDepthMask(false) Gdx.gl.glEnable(GL20.GL STENCIL TEST) Gdx.gl.glStencilFunc(GL20.GL ALWAYS, 0x1, 0xffffffff) Gdx.gl.glStencilOp(GL REPLACE, GL REPLACE, GL REPLACE) shapeRenderer.begin(ShapeRenderer.ShapeType.Filled) shapeRenderer.box(cubby.xpos 5 , cubby.ypos 5, 0, cubby.size 10, cubby.size 10, 0) shapeRenderer.end() shapeRenderer.begin(ShapeRenderer.ShapeType.Filled) Gdx.gl.glColorMask(true, true, true, true) Gdx.gl.glDepthMask(true) Gdx.gl.glStencilFunc(GL NOTEQUAL, 0x1, 0xffffffff) Gdx.gl.glStencilOp(GL KEEP, GL KEEP, GL KEEP) shapeRenderer.box(cubby.xpos, cubby.ypos,0,cubby.size, cubby.size, 0) shapeRenderer.end() Gdx.gl.glDisable(GL20.GL STENCIL TEST)


Rendering only a part of the screen in high detail If graphics are rendered for a large viewing angle (e.g. a very large TV or a VR headset), the viewer can't actually focus on the entire image, just a part of it. (Actually, this is the case for regular sized screens as well.) Combined with a way to track the viewer's eyes (which is mostly viable in VR I guess), you could theoretically exploit this and render the graphics away from the viewer's focus with progressively less details and resolution, gaining performance, without losing perceived quality. Are there any techniques for this available or under development today?


How to load large arrays to gpu and render with OpenGL? I am trying to make a volumetric rendering of a cloud. I have been defining the cloud density functions on the glsl shaders and performing ray marching methods successfully. But now I would like to render a 3D grid (100x100x100) representing the density of a cloud that I calculated using the cpu. The idea that I was trying was to make use of the storage buffer objects, but when I access the array to get the density value and render it, it doesn't work. This is at the beginning of the glsl fragment version 440 core layout(std430, binding 3) buffer layoutName float data SSBO 100 100 100 And the density function definition is float density(vec3 position, float t) const float dx 1. 100., dy 1. 100., dz 1. 100. int i, j, k if( (position.x gt 0.) amp amp (position.y gt 0.) amp amp (position.z gt 0.) amp amp (position.x lt 1.) amp amp (position.y lt 1.) amp amp (position.z lt 1.)) i int(position.x dx) j int(position.y dy) k int(position.z dz) return data SSBO i 100 100 j 100 k else return 0. And in the c code there are the buffer creation, bindings, etc glGenBuffers(1, amp ssbo) glBindBuffer(GL SHADER STORAGE BUFFER, ssbo) glBufferData(GL SHADER STORAGE BUFFER, 100 100 100 sizeof(float), grid, GL STATIC DRAW) glBufferSubData(GL ARRAY BUFFER, 0, 100 100 100 sizeof(float), grid) and in the rendering function there is glClearColor(1.f, 1.f, 0.f, 1.0f) glClear(GL COLOR BUFFER BIT GL DEPTH BUFFER BIT) glBindBuffer(GL ARRAY BUFFER, VBO) glBindBuffer(GL SHADER STORAGE BUFFER, ssbo) glBindBufferBase(GL SHADER STORAGE BUFFER, 3, ssbo) glBufferSubData(GL ARRAY BUFFER, 0, 3 2 2 sizeof(float), buffer) glVertexAttribPointer(0, 2, GL FLOAT, GL FALSE, 2 sizeof(float), (void )0) coordenadas glEnableVertexAttribArray(0) glUseProgram(shaderProgram) I believe the problem has to do with the binding, I have been trying different combinations, like binding after and before glUseProgram, etc. I literally have no idea what is wrong, I see this is really confusing.


Framerate limited by lack of mouse movement? Using Torque, it appears that the program is running at around 25fps when the mouse is still, but as long as I keep the mouse moving, the framerate can hit well over 300fps. What in the world would cause the framerate to be tied to mouse movement?


What is the difference between OpenGL ES and OpenGL? Android uses OpenGL ES, what is the difference between it and OpenGL?


C 11 Efficient Networking ClientServer"Zone(s)" I am building both an engine and a networked game at once because I'm completely insane. The original design plan was to use internal Unix sockets for each "zone" for server lt zone communication, with UDP for server lt client(s) communication. My conundrum is this It seems like there are a variety of ways to handle getting packets from a client to the intended "zone", not none of them seem particularly efficient. Simply move data from a singular queue to the intended zone server, via data objects within code. (Pro Simple Con Potentially slow as molasses in a Canadian winter.) (Somehow) Allow Server and Zones to communicate via Unix sockets, with a networking class wrapper to pass packets into a "pool" for redistribution to Zones. (Pro Unix sockets, from my reading, tend to be fairly quick. Con Need to re evaluate how I am currently handling packets and the redistribution of packets makes it too similar to 1 for my liking.) Use the underlying messages system on Linux. Ref (Pro Crazy fast for large objects. Con No idea how to implement at the moment.) Additionally, if there is a specific text, document, or book(s) that I should be hitting instead of harassing everyone here, PLEASE let me know! Not at all afraid to spend a week tearing through a 200 page tome. Thank You!


OpenGL Blending GUI Textures I'm currently creating a menu for my project and I'm trying to get the textures to blend so I'm only left with the actual Image on the texture and not the background. The problem is the whole texture is somewhat transparent, it's not just removing the background. My RGBA texture looks like And the black background needs to be removed from the image. I was using GL SRC ALPHA, GL ONE MINUS SRC, ALPHA for my blend function but it wasn't blending anything. I changed to GL ONE, GL ONE and now I'm at where I am now. You can see the text is there but its also transparent, but the background has been removed which is good. This is how i'm drawing my button. The world behind it is drawn after (i've tried switching order didnt change anything) and it's drawn using VBO's whereas the Buttons are drawn in immediate mode. glEnable(GL BLEND) glBlendFunc(GL ONE, GL ONE) left get button pos Point3 lt float gt pos button gt getPos() get button dimensions int width button gt getWidth() int height button gt getHeight() bind button texture and draw quad glActiveTexture(GL TEXTURE0) glBindTexture(GL TEXTURE 2D, button gt getState() ? button gt getDownTex() gt getTextureID() button gt getUpTex() gt getTextureID()) glBegin(GL QUADS) glTexCoord2i(0, 1) glVertex3f(pos.x, pos.y, 0.0f) glTexCoord2i(1, 1) glVertex3f(pos.x width, pos.y, 0.0f) glTexCoord2i(1, 0) glVertex3f(pos.x width, pos.y height, 0.0f) glTexCoord2i(0, 0) glVertex3f(pos.x, pos.y height, 0.0f) glEnd() I'm using sdl to load the texture SDL Surface image IMG Load(textureName) data.m w image gt w data.m h image gt h data.m bitsPerPixel image gt format gt BitsPerPixel data.m alpha image gt format gt alpha int colourMode image gt format gt BytesPerPixel if (colourMode 4) internalFormat GL RGBA if (colourMode 3) internalFormat GL RGB if (colourMode 1) internalFormat GL LUMINANCE if (SDL BYTEORDER SDL LIL ENDIAN) if (colourMode 4) format GL BGRA else format GL BGR else if (colourMode 4) format GL RGBA else format GL RGB GLuint texture 1 create texture handle glGenTextures(1, amp texture) gen texture bindTexture(GL TEXTURE 2D, texture) glTexParameterf( GL TEXTURE 2D, GL TEXTURE WRAP S, GL REPEAT) glTexParameterf( GL TEXTURE 2D, GL TEXTURE WRAP T, GL REPEAT) glTexParameterf( GL TEXTURE 2D, GL TEXTURE MIN FILTER, GL LINEAR ) glTexParameterf( GL TEXTURE 2D, GL TEXTURE MAG FILTER, GL LINEAR ) glTexImage2D(GL TEXTURE 2D, 0, internalFormat, image gt w, image gt h, 0, format, GL UNSIGNED BYTE, image gt pixels) normal texture


instancing and GPU skinning I'm trying to render a large number of identical rigged entities with independent animation. Compared to standard skeletal animation, I can't compute the pose of each entities and send it to the GPU for each frame. This would demand too much work for the CPU and saturate the VRAM very quickly. Let's say I have 5000 entities with 20 bones, I would have to compute and send 5000 20 (size of matrix quaternion translation dual quaternion) poses to the GPU, each frame. I recently found this article paper https developer.nvidia.com gpugems GPUGems3 gpugems3 ch02.html Their idea is to load animations to the GPU in order to access them independently with each instance. Correct me if I'm wrong but I think this is equivalent to move the interpolation part to the GPU. I pre computed all the bone transformation in local space for each frame for each animation and packed it into texture buffers. It works as expected. However, I experience strange results with my animated models... In fact the interpolation is necessarily wrong ! I am trying to interpolate between poses in local space, not in bone space like with standard CPU interpolation. There is no problem with translations, but with rotations. (the axis is shifted to the local space origin). I imagine I could send the bone space transformations AND the bone hierarchy. But that would impose to parse the hierarchy for each vertex (in vertex shader), in order to re compute the interpolated bone transformations. One other idea I had is to upsample the animations in order to have smaller interpolation intervals, but again, it will use more VRAM. To be honest I'm not sure I understood well the paper (especially in the interpolation part)... Any suggestion ? EDIT 1 It's maybe unclear by "local space" I mean entity space, so it is more like "global space"... EDIT 2 To provide more details about my implementation In the CPU (c ) pre process part, I pre compute all the bone transformations in local space for each frame (natively, I get bone space transformations using Assimp library so I have to do a bit of work here). Then, I send this information as an array to the GPU (array of numFrames numBones numAnims dual quaternions). In the vertex shader, I get information about the current instance using gl instanceID. I get world position, current animation and time in current animation. Then I compute the interpolated pose of the bones influencing the current vertex. I do that by finding the bounding frames using the instance's time. I interpolate my pairs of transformations (pairs of dual quaternions) for each concerned bone. (I know there is a mistake because the interpolation must be performed in bone space). Once they are interpolated, I blend linearly the transformations into one using the bone weights attached to my vertex (and I normalize my final dual quaternion). It worked when i was doing interpolation in bone space in CPU, I'm just trying to move the interpolation part on the GPU.


How do I implement my old OpenGL based gfx render triangle list using DX11? I am working at a game that has lots of procedural content. I had built a game engine using OpenGL that handles everything needed for creating a basic 2D game, sprites, primitives, blending, polygons etc. At a particular moment I decided to implement target textures to obtain interesting effects and problems started to arise Sometimes the engine did not initialize OpenGL and GLEW properly and could not isolate the exception. Finally I abandoned the idea of using OpenGL because of similar issues (SOMETIMES cannot use newer GLEW functions...NOTE drivers up to date). I decided to use DX11 instead and take benefit from the new technologies of the latest GPUs. So I did. Now I am porting my engine to DX11 and I am quite stuck. I had procedures to be called in a render() function, like engine gt gfx render triangle list(pointer) which in principle just called a procedure like glBegin(GL TRIANGLES) ... glVertex2f(.....) ... glEnd() Now the problem that arises for me is the new pipeline of DX11. Load up vertices in the VertexBuffer, process them by the VertexShader then fill them with pixels and transform with the PixelShader. This is great as I have full access to what is being displayed on the screen, but, how do I do it the 'old fashion' way? I mean, how do I draw primitives like in OpenGL, each frame sending unique, new triangles to the screen. I didn't find any resources that explain this and I cannot think this through myself, loading some vertices in the vertex buffer is designed for meshes that are human made and static and they are only transformed by the shaders. Long story short How do I implement my old gfx render triangle list using DX11? NOTE My engine will be used as a DLL.


OpenGL light calculation I want to add somebasic point lights to my OpenGL application. I read here that I have to caluclate the light in a pre projection space Lighting can be done in any pre projection space (e.g., world coordinates or eye coordinates), as long as all the objects and lights are all in that same space. And here is my problem. My Renderer currently looks something like this public void onDrawFrame(GL10 unused) GLES20.glClear(GLES20.GL COLOR BUFFER BIT GLES20.GL DEPTH BUFFER BIT) Matrix.multiplyMM(camProjection, 0, projection, 0, camera, 0) for(int i 0 i lt sceneObjects.size() i ) SceneObject object sceneObjects.get(i) object.draw(camProjection) ... As you can see I multiply my projectionMatrix with the viewMatrix and I think that is a good solution because I only have to do this once. To draw I give the PVMatrix to all objects and multiply it with their modelMatrix and then I push the finall MVPMatrix to the shader. This is a problem because I can not calculate the light direction in eye space in the shader because I do not have any pre projection matrix here. Do I really have to push a MVMatrix to the shader and calculate the normals and so on with it? I think this is really inefficient because I have to do much more matrix multiplications, isn't it? What would you suggest to calculate this efficiently?


Can I store D3D9 textures so that they don't consume process memory and also don't require "lost device" handling? I have an OpenGL application that uses a lot of texture memory. While the texture is stored in the system memory, that texture memory is not part of my application process memory. When this application is ported to D3D and the textures are uploaded to the D3DPOOL MANAGED pool, the process memory increases proportional to the texture memory and the application crashes due to running out of memory (while in OpenGL, even though the overall system memory utilization has greatly increased, the process memory is still low) I don't want to have to switch to D3DPOOL DEFAULT, since the I would have to reload all textures when the device is reset. Is there a workable solution to get my D3D9 application to put the system texture memory somewhere else beside my process, similar to OpenGL? EDIT So I just learned about IDirect3DDevice9Ex. Turns out using this interface instead of IDirect3DDevice9 make DirectX work exactly like opengl in terms of texture memory (system memory goes up proportional to my texture usage, but not the process memory). So this is an option for me. However I would still like to know if there are any options since IDirect3DDevice9Ex doesn't work on XP.


How to map control key to a specific angle or orientation? At the moment, I basically have built out a large hash table of various angles and what direction they map to, if the user would press right, up, down, left. This is needed, in my case, as I have a collection of geometries that when the user presses right, they all go right, and when left, they all go left ... However, when the scene containing these is rotated anything other than its original state, these controls need to be updated reversed etc. That is, if you're looking at the scene from behind, pressing left now has the objects all going right, etc. I was trying to see if there is a simpler way of applying matrix transformations instead of hard coding a large hash table mapping various scene angles to keys.


Should I make a FPS game on Fixed Function Pipeline or Programmable Pipeline OpenGL? I have a FPS game I have programmed in Fixed Function Pipleline and one made in Programmable pipeline OpenGL. While the programmable pipeline has lots of weird things that you can edit, it does not have glLoadIdentity that I need for the gun to be attached to the camera. There is little to no information on this subject and most of the information that I can find is in the fixed function pipeline rather than the programmable one. Keep in mind that with the fixed function pipeline, I can just use the glloadidentity function and attach it then move on to another thing. On the programmable one, I don t know how to do this, so I have spent a whole week looking up how I can do it. Should I just use the fixed function pipeline one and abandon the programmable pipeline? What shall I do? Thanks!


What is the best way to store Vertex Buffer Object data? Until now, I have been using a vertexData structure to store data for a Vertex Buffer Object (VBO) vertexData holds a static array of 6 vertices (2 triangles). I then save them to a vector of the vertexData type, before finally using this vertexData in the buffering method struct vertexData Vertex vertices 6 position, color, UVs std vector lt vertexData gt DATA void SpriteBatch createVBO() glBindBuffer(GL ARRAY BUFFER, VBO) glBufferData(GL ARRAY BUFFER, DATA.size() sizeof(vertexData),nullptr,GL DYNAMIC DRAW) glBufferSubData(GL ARRAY BUFFER,0, DATA.size() sizeof(vertexData), DATA.data()) glBindBuffer(GL ARRAY BUFFER,0) This works good, as everything in my vector is contiguous. However, I want to work with other vertex sizes, for different shapes. I tried a vector of vector types, in oder to work with dynamically allocated arrays, but it did not work, as it was not contiguous. At first, I thought about using a polymorphic class to be stored as a vector, where every child would have a different array size but then I recognized that this vertex buffer does not work with pointers The second idea was to create a generic SpriteBatch. For example, a batch for 6 vertices, and then a batch for 2 vertices, etc. etc. What is the best way to store Vertex Buffer Object data?


FBO picking in Oculus Rift applications I am writing an Oculus Rift application, I am rendering a very high poly mesh that I wish to be able to perform picking on using the Oculus Touch. Ideally, I want to be able to get the "triangle" id and other information attached to it. Currently, I am using an OBB Tree and ray casting to perform picking on the CPU, It works perfectly, the problem is that even with OBB tree the picking process is slow. I thought I'd perform picking on the GPU by rendering the view (from the point of view of the Oculus Touch) to an FBO using a custom shader that outputs "triangle information" to the buffer and then use glReadPixels to read the central pixel data. The problem I am facing is that the Oculus does distortion to my on screen scene but there is no way to apply it to the off screen buffer, so there is significant difference between the on screen buffer and the off screen buffer. My question is, Is ray casting the only feasible way to do picking in Oculus Apps or is there a way to perform the faster FBO picking even when the view distorted?


ASSIMP aiNode mMeshes understanding I'm trying to use ASSIMP to load an fbx file with a skeleton and animations, but I'm stuck on something I'm misunderstanding and struggling to see it. I've attached 2 images, one of the fbx file as rendered by Open 3D Mod which uses ASSIMP and looks correct. The second image is my renderer that does not look correct. The only thing wrong with mine is that the main body is rotated 90 degrees from what it should be. For this fbx file, it has 3 nodes that contain a mesh to draw "Mesh 1" is the main body and "Mesh 0" is an axe. The axe is referenced twice, once from each hand node. The main body mesh's vertices are tied to the bones, so Mesh 1 gets animated with the bones. The axe mesh's vertices are not tied to bones. So I'm traversing the skeleton, and when I get to a node that references a mesh to draw, I transform to that node's position, then draw the mesh instance at that spot. This is how the axe meshes get animated the axe mesh vertices are not tied to bones, but since the hand nodes reference them, I transform wherever the hand bone animation currently is then draw them. My problem is when I do this same thing on the main body (Mesh 1), it ends up rotated 90 degrees as seen in the blue picture. The reason is because the node it is attached to has an mTransformation of 90 degrees about the x axis. Another note is that the mTransformation of the RootNode is the identity matrix, so the global inverse is identity. There's too much code involved for me to realistically be able to post it here. However, the relevant logic follows what's shown in this tutorial http ogldev.atspace.co.uk www tutorial38 tutorial38.html The one thing the tutorial doesn't mention is handling the mesh references at each node. If I ignore where the meshes are referenced from, the body works but the axes break (axes don't animate any more and simply draw at their bind position). The model I'm using was a free one I grabbed from the unity store for testing https assetstore.unity.com packages 3d animations zombie 0 1 19254 My questions are Am I correctly interpreting the mesh references at a node by transforming to the node position prior to drawing? If so, why does this get the axes to the correct place but not the main body? If not, what am I missing? Open 3D Mod's render, looking down the Z axis My render, looking down the Z axis


Drawing multiple Textures as tilemap I am trying to draw a 2d game map and the objects on the map in a single pass. Here is my OpenGL initialization code Turn off unnecessary operations glDisable(GL DEPTH TEST) glDisable(GL LIGHTING) glDisable(GL CULL FACE) glDisable(GL STENCIL TEST) glDisable(GL DITHER) glEnable(GL BLEND) glEnable(GL TEXTURE 2D) activate pointer to vertex amp texture array glEnableClientState(GL VERTEX ARRAY) glEnableClientState(GL TEXTURE COORD ARRAY) My drawing code is being called by a NSTimer every 1 60 s. Here is the drawing code of my world object (void) draw (NSRect)rect withTimedDelta (double)d GLint t glActiveTexture(GL TEXTURE0) glBindTexture(GL TEXTURE 2D, textureManager textureByName "blocks" ) glTexEnvi(GL TEXTURE ENV, GL TEXTURE ENV MODE, GL REPLACE) for (int x 0 x lt map getWidth x ) for (int y 0 y lt map getHeight y ) GLint v 16 x ,16 y, 16 x 16,16 y, 16 x 16,16 y 16, 16 x ,16 y 16 t textureManager getBlockWithNumber map getBlockAtX x andY y glVertexPointer(2, GL INT, 0, v) glTexCoordPointer(2, GL INT, 0, t) glDrawArrays(GL QUADS, 0, 4) ( textureManager is a Singelton only loading a texture once!) The object drawing codes is identical (except the nested loops) in terms of OpenGL calls (void) drawWithTimedDelta (double)d GLint t GLint v 16 xpos ,16 ypos, 16 xpos 16,16 ypos, 16 xpos 16,16 ypos 16, 16 xpos ,16 ypos 16 glBindTexture(GL TEXTURE 2D, textureManager textureByName textureName ) t textureManager getBlockWithNumber 12 glVertexPointer(2, GL INT, 0, v) glTexCoordPointer(2, GL INT, 0, t) glDrawArrays(GL QUADS, 0, 4) As soon as my central drawing routine calls the two drawing methods the second call overlays the first one. i would expect the call to world.draw to draw the map and "stamp" the objects upon it. Debugging shows me, that the first call is performed correctly (world is being drawn), but the following call to all objects ONLY draws the objects, the rest of the scene is getting black. I think i need to blend the drawn textures, but i cant seem to figure out how. Any help is appreciated. Thanks PS Here is the github link to the project. It may not be in sync of my post here, but for some more in depth analysis it may help.


How can I use OpenGL and D3D to render to the same window at the same time? I have main render loop in which initial drawing is done via OpenGL to an SDL window, and after that the same window handle is passed to a Direct3D device, which does subsequent rendering. Once I execute the program it will initially draw the OpenGL scene, and then do Direct3D drawing but that latter drawing overwrites the OpenGL work. What I want to see is both drawings in parallel. How can I accomplish that?


Difference between the terms Material Effect I'm making an effect system right now (I think, because it may be a material system... or both!). The effects system follows the common (e.g. COLLADA, DirectX) effect framework abstraction of Effects have Techniques, Techniques have Passes, Passes have States amp Shader Programs. An effect, according to COLLADA, defines the equations necessary for the visual appearance of geometry and screen space image processing. Keeping with the abstraction, effects contain techniques. Each effect can contain one or many techniques (i.e. ways to generate the effect), each of which describes a different method for rendering that effect. The technique could be relate to quality (e.g. high precision, high LOD, etc.), or in game situation (e.g. night day, power up mode, etc.). Techniques hold a description of the textures, samplers, shaders, parameters, amp passes necessary for rendering this effect using one method. Some algorithms require several passes to render the effect. Pipeline descriptions are broken into an ordered collection of Pass objects. A pass provides a static declaration of all the render states, shaders, amp settings for "one rendering pipeline" (i.e. one pass). Meshes usually contain a series of materials that define the model. According to the COLLADA spec (again), a material instantiates an effect, fills its parameters with values, amp selects a technique. But I see material defined differently in other places, such as just the Lambert, Blinn, Phong "material types shaded surfaces", or as Metal, Plastic, Wood, etc. In game dev forums, people often talk about implementing a "material effect system". Is the material not an instance of an effect? Ergo, if I had effect objects, stored in a collection, amp each effect instance object with there own parameter setting, then there is no need for the concept of a material... Or am I interpreting it wrong? Please help by contributing your interpretations as I want to be clear on a distinction (if any), amp don't want to miss out on the concept of a material if it should be implemented to follow the abstraction of the DirectX FX framework amp COLLADA definitions closely.


What's the equivalent of wglShareLists for Mac OS? I'm trying to share lists between two contexts on Mac OS but despite my research I couldn't come up with an answer so far. I've found that NSOpenGLContext was able to initialize a context with a shared context but not to set it afterward. What's the equivalent of wglShareLists on Mac OS?


Painter algorithm vs. 3D rendering with Z buffer when drawing 2D Sprites I'm currently developing a tile base engine. I want it to look like your average old school tilebased RPG like Zelda Link to the past (orthographic projection, squared tile texture, textures overlapping each other, alpha channels, etc.). The twist is that the world is internally 3d meaning that every tile has an elevation and entities are moving in a 3d space. Reason for this is beyond the scope of this question but I'm struggling on comparing the follow two ideas for the rendering. I'm using OpenGL with libGDX in Java but wouldn't mind writing my own code to interface OpenGL. That's also why I didn't tag it. A screenshot of quot Zelda Link to the past quot in case you don't know what it looks like. Painter algorithm Disable Z Buffer and use painter algorithm to draw from back to front in the appropriate order with some overdraw and a lot of texture rebinding. I know a texture atlas can minimize the texture rebinding but the engine is supposed to act more like a sandbox so I don't want to rely too heavily on assumptions like a efficient texture atlas that I might not have all the time. Pro Easy to implement and very straight forward. Con I've no idea how big the impact will be since almost every sprite will cause a texture rebinding. And I don't know how to predict the performance costs of that many texture bind calls. Full blown 3D Rotate the camera 45 degrees up around the x axis with an orthographic projection matrix. Then use the 3d information from the game world to draw the tile textures with billboarding at the real position in the worlds 3d space. Same for entities and such. This way I can gather all sprites and then render them sorted by their texture which means one texture bind per texture and reduced overdraw due to usage of the Z buffer Pro I can use a freecam to debug render problems. I assume it's significantly faster that the painter algorithm. Con Some sprites might share the same place which could lead to Z fighting. I'm thinking about how to use multiple layers on a tile. For instance you may have a bridge tile with a railing where the railing is always overlapping an entity on the bridge but the floor of it is always overlapped by the entity. So I would have to add a little offset to different layers in the 3d space. I'm not really sure how that would work out and to be honest had a hard time figuring out how old games did it so maybe I'm overthinking it. I guess I have a very rough idea of how each method will work out but I don't know how much the texture rebinding (or sorting and preparing the sprites for the 3d approach) is affecting the performance and while it's easy to find information regarding large 3D scenes I found it difficult to get information about 2D scenes with way less polygons.I hope this question is not too much a subject of personal preference. I know that Premature optimization is the root of all evil but due to how the decision is affecting almost the entire rendering process I don't want to make the wrong call. I deliberately didn't mention any OpenGL functions mainly because I've mostly used the libGDX API which hides the function calls behind it's wrappers but generally I know how the internals work and just got into the internals and how the OpenGL API works. I don't think specific OpenGL calls do matter for the question but feel free to use them for your answer I'll just look them up.


Skinning on simple model doesn't work as expected I have created a simple application to make skinning work with OpenGL. so I want to share with my vertex shader version 330 core layout (location 0) in vec3 RealPos layout (location 1) in vec3 vertex color layout (location 2) in vec2 vertex textcoord layout (location 3) in vec3 RealNor layout (location 4) in vec4 Joint layout (location 5) in vec4 Weight uniform mat4 u jointMatrix 2 out vec2 vs text out vec3 vs color out vec3 normal out vec3 FragPos uniform mat4 model uniform mat4 view uniform mat4 projection uniform bool isSkin void main() mat4 skinMatrix Weight.x u jointMatrix int(Joint.x) Weight.y u jointMatrix int(Joint.y) Weight.z u jointMatrix int(Joint.z) Weight.w u jointMatrix int(Joint.w) vs text vertex textcoord vs color vertex color FragPos vec3(model vec4(RealPos, 1.0f)) normal mat3(transpose(inverse(model))) RealNor if(isSkin) gl Position projection view model skinMatrix vec4(RealPos, 1.0f) else gl Position projection view model vec4(RealPos, 1.0f) so as you can see, if my model is skinned then it will call the first statement. and here my C code unsigned j 0 for (unsigned u 0 u lt m.numOfJoints u ) glm mat4 g glm mat4(inverseBindMatriceHandler.at(j), inverseBindMatriceHandler.at(j 1), inverseBindMatriceHandler.at(j 2), inverseBindMatriceHandler.at(j 3),inverseBindMatriceHandler.at(j 4), inverseBindMatriceHandler.at(j 5), inverseBindMatriceHandler.at(j 6), inverseBindMatriceHandler.at(j 7), inverseBindMatriceHandler.at(j 8), inverseBindMatriceHandler.at(j 9), inverseBindMatriceHandler.at(j 10), inverseBindMatriceHandler.at(j 11), inverseBindMatriceHandler.at(j 12), inverseBindMatriceHandler.at(j 13), inverseBindMatriceHandler.at(j 14), inverseBindMatriceHandler.at(j 15)) m.inverseBindMatrice.push back(g) glm mat4 gTransform glm inverse(g) m.globalTransform.push back(gTransform) j 16 if (Model.isSkinned) for (unsigned l 0 l lt Model.numOfJoints l ) jointM l Model.globalTransform.at(l) Model.inverseBindMatrice.at(l) int isSkinLoc glGetUniformLocation(program, quot isSkin quot ) glUniform1i(isSkinLoc, 1) for (unsigned l 0 l lt Model.numOfJoints l ) 2 std string name quot u jointMatrix quot std to string(l) quot quot int jointMatrixLoc glGetUniformLocation(program, name.c str()) glUniformMatrix4fv(jointMatrixLoc, 1, GL FALSE, glm value ptr(jointM l )) else int isSkinLoc glGetUniformLocation(program, quot isSkin quot ) glUniform1i(isSkinLoc, 0) inverseBindMatriceHandler is a vector. I have 2 joints (numOfJoints). I can't understand why my model doesn't work properly. can someone help me? Thanks


glOrtho setting view I am duplicating this thread from stackoverflow, please remove it if that is not allowed. I'm completely new in OpenGL. I have this problem I have quite a complicated scene, and I am looking at it from the front (default camera position). The way I have seen to move the camera is using the gluLookAt() function to set the point you want to look at, and glTranslate3f() to move the camera position. I need to move the camera with different data my data is not the point I want to look at rather, I have the data of the projection plane determined with a viewing vector and a point in the plane. Is there a way to set the camera using this data rather than a "look at" point? I am using an ortographic projection (glOrtho()), so everything is projected onto the projection plane. UPDATE To be more precise the point I have is a point in the plane, to which I want to project to. I have in fact not only the plane, but the square to which I need to project, defined. So I have a scene somewhere a space, and a square somewhere away from that scene. I want to project the scene to that square and show that projection on screen. I hope that made it a bit clearer what I need to achieve ... While gluLookAt defines a point in the scene at which to look at, and the position of the eye. While eye is one point in space and projection offers perspective, with ortographic projection, you do not have one point, you have a whole square on which to project to, so how can I define that? For easier understanding what I am trying to achieve. Here is the image of what glOrtho normally does Here is an image of what I am trying to achieve


GL GENERATE MIPMAP vs. GL MAX TEXTURE SIZE If we generate mipmaps for a texture using GL GENERATE MIPMAP (or glGenerateMipmap), how big can the original texture be? Is it the size returned by GL MAX TEXTURE SIZE, or half of it?


OpenGL color overlay I want to create a pause menu where everything in the background gets darker. I've looked up a bunch of possible solutions (even the second page on google) but it doesn't seem to work. I do already have something in my code that makes a single texture darker when hovered over, by calling GL11.glColor3f(alpha, alpha, alpha) before drawing vertices. What I want to achieve is everything getting darker, so when hovering over a texture it should be even darker than before so it is still darker than the rest in the background when that has been made darker because of a pause menu that pops up. Another thing I noticed is that glColorMask(true, false, false, true) does not get overridden and blends colours everywhere, so I was wondering if there is a version of this method that puts a transparent black overlay so everything becomes darker. I have enabled blending. Edit One solution I came up with (not just now) is multiplying alpha in every glColor3f function with a variable that is smaller than 1 so everthing gets relatively smaller, but I worry about this being uneffective and badly mantainable


How to draw a circle on the ground like in "Warcraft 3"? I've been watching "Warcraft 3", and suddenly realized that I have no idea how to draw a circle on a surface. Here is an example I guess this is projection? I also have very little idea of how to draw a shadow. I only somewhat know OpenGL. It is also interesting how this circle seems to not perfectly repeat the shape of that cliff. My guess is that it's drawn using a height map, which is stored somewhere separately, and not as the cliff, itself. It looks like it actually goes underwater, but it may be just a compression artifact.


OpenGL multiple mesh management I've been working on coding a new 3D engine in Java. For the moment at least I'm sticking to openGL... Currently I'm reworking how meshes get transformed and then drawn. ATM each mesh created has its own VBO and IBO along with its own draw method so if I wanted to draw multiple meshes it would look like this mesh1 MeshLoader.loadMesh("cube.obj") mesh2 MeshLoader.loadMesh("pyramid.obj") mesh1.addToBuffers() adds vertex and index data to vbo and ibo mesh2.addToBuffers() mesh1.draw() mesh2.draw() The draw method defined in class Mesh enables vertex attribute arrays, binds the bufffers, and then draws elements based on the ibo. Then I send my projection matrix (transformation and perspective) as a uniform to the vertex shader. QUESTION Games are made of many many meshes and each has to be identified so that transformation can be applied. I want to be able to apply transformations (translate, rotate, scale) directly to a given mesh, independent of the other meshes. In other words I want to move mesh1 and only mesh1 5 units to the right (on its own axis) without it affecting mesh2. How do I do all this without making a million draw calls to the gpu? Any advice appreciated.


GLSL shader compilation When i'm compiling a shader does it have to be complete? Can i use glCompileShader on a shader without a main() function? The OpenGL reference documentation has a nice writeup on program linking errors, but i can't find one for shader linking, so i have to ask here. I want to have the ability to have each part of a shader in a different file. So f.e. i'll have a material calculating function and i'll have a "main" shader with the main function that'll only reference the material calculating function. Right now i have my shaderes as arrays of strings that they can read from a file, then i put together an array of string pointeres and compile that into a single shader (vertex, fragment, geometry). But if i could compile each invidividual shaders (parts of vertex shaders, instead of the whole vertex shader put together in an array of strings) and put them together when i'm linking the program, that would make the code much clearer and i could move the shader compilation code from the program managing code to the shader object itself (the one that load the string from file and exposes it).


Screen Space Reflections Artifacts problem I'm trying to implement a simple (so far) screen space reflections shader. Below is my code const int numBinarySearchSteps 100 const int maxSteps 400 const float rayStep 0.01 25 const float minRayStep rayStep 2.5 vec3 BinarySearch(vec3 dir, inout vec3 hitCoord, out float dDepth, out int hit) float depth for(int i 0 i lt numBinarySearchSteps i ) vec4 projectedCoord projectionMatrix vec4(hitCoord, 1.0) projectedCoord.xyz projectedCoord.w projectedCoord.xyz projectedCoord.xyz 0.5 0.5 depth texture2D(depthMapTex, projectedCoord.xy).x vec4 viewSpaceDepth inverse(projectionMatrix) vec4(projectedCoord.xy, depth 2.0 1.0, 1.0) viewSpaceDepth.xyz viewSpaceDepth.w dDepth viewSpaceDepth.z hitCoord.z if(dDepth lt 0.0) hitCoord dir dir 0.5 hitCoord dir vec4 projectedCoord projectionMatrix vec4(hitCoord, 1.0) projectedCoord.xyz projectedCoord.w projectedCoord.xyz projectedCoord.xyz 0.5 0.5 hit 1 return vec3(projectedCoord.xy, depth) vec4 RayCast(vec3 dir, inout vec3 hitCoord, out float dDepth, out int hit) dir rayStep float depth vec4 projectedCoord projectionMatrix vec4(hitCoord, 1.0) projectedCoord.xyz projectedCoord.w projectedCoord.xyz projectedCoord.xyz 0.5 0.5 depth texture2D(depthMapTex, projectedCoord.xy).x return vec4(vec3(depth),1.0) for(int i 0 i lt maxSteps i ) hitCoord dir vec4 projectedCoord projectionMatrix vec4(hitCoord, 1.0) projectedCoord.xyz projectedCoord.w projectedCoord.xyz projectedCoord.xyz 0.5 0.5 depth texture2D(depthMapTex, projectedCoord.xy).x float zNear 5.0 float zFar 2000.0 float z n 2.0 depth 1.0 float z e 2.0 zNear zFar (zFar zNear z n (zFar zNear)) vec4 viewSpaceDepth inverse(projectionMatrix) vec4(projectedCoord.xy, depth 2.0 1.0, 1.0) viewSpaceDepth.xyz viewSpaceDepth.w dDepth hitCoord.z z e if(dDepth gt 0.0) if (dDepth gt length(dir)) Inconclusive hit 2 return vec4(0.0) return vec4(BinarySearch(dir, hitCoord, dDepth, hit), 1.0) hit 0 return vec4(0.0, 0.0, 0.0, 0.0) vec3 ssr() Reflection vector vec3 reflected normalize(reflect(normalize(viewSpacePosition), normalize(viewSpaceNormal))) Ray cast vec3 hitPos viewSpacePosition float dDepth int hit 0 no hit, 1 good hit, 2 nonsense hit vec4 coords RayCast(reflected max(minRayStep, viewSpacePosition.z) , hitPos, dDepth, hit) vec3 color if (hit 1) color texture2D(colorMapTex, coords.xy).rgb else color vec3(0.0) return color So far, all it does is just return the color of every pixels purely specular reflection, or black if there is no reflection on the screen or if the reflection ray passes behind an object. My issue is that I get these bizarre artifacts where the pixel gets a color (dDepth length(dir)), even though dDepth is supposed to be way larger than length(dir). I've been stuck on debugging this for ages now and I'm wondering if anyone can see the mistake? This is the scene using just a simple shader (to the right), and the scene running only the SSR shader (on the left) Extremely thankful for any help!!! Simon


OpenGL NDC initial values I have a set of vertex locations to create a plane this gt Vertices position color texture 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f Everything is fine, but I can't grasp how I should input these values at the very beginning. I used to give exact locations for vertices in DirectX in pixel unit, but here in OpenGL I should give vertex locations in normalized coordinates. If I wanted to create a plane say 200px by 200px how should I deal with that when I set vertex data. I know I can transform my plane with coordinate matrices through model space and view space and etc. I just don't know what I should be giving for the initial vertex location values.


Error "glGenBuffers is ambiguous" in Eclipse Mars I have called a function, which is part of OpenGL correctly. uint vboId glGenBuffers(1, amp vboId) This is definitely correct because the program successfully runs. The error shown when I hover over the second line is as follows. 'glGenBuffers' is ambiguous ' Candidates are void glGenBuffers(int, unsigned int )' The full function is below. void Loader storeDataInVao(int position, short data , ushort data length) uint vboId glGenBuffers(1, amp vboId) vbos.push back(vboId) glBindBuffer(GL ARRAY BUFFER, vboId) glBufferData(GL ARRAY BUFFER, data length 2, amp data, GL STATIC DRAW) glVertexAttribPointer(position, 2, GL SHORT, GL FALSE, 0, 0) glBindBuffer(GL ARRAY BUFFER, 0) The includes are "Loader.h", "RawModel.h" and "", two of which are my other files. However, every single one of my header files has valid header guards, defined as shown below. ifndef SRC DISPLAY LOADER H define SRC DISPLAY LOADER H code here endif SRC DISPLAY LOADER H The glGenBuffers is underlined red, just like any other error.


How can I forward GLFW's keyboard input to another object? I'm having trouble trying to execute keyboard events in a another class with GLFW3. The problem I'm having is that GLFW3 uses a static function for input as shown static UI u ... ... static void key callback(GLFWwindow window, int key, int scancode, int action, int mods) u.controls(window, key, action) u is also static and controls holds the the input for WSAD keys (the only way I could get get key events). From here, pressing a key works displaying which key is pressed in the console window. The trouble I'm having is trying to used the key pressed to manipulate a variable in another class. I have another class called MainMenu that has the function update(). Is there a way I can use my UI class within this function?


How to handle hitboxes hurtboxes in animations? I'm curious how I should go about structuring hitboxes and hurtboxes for my actors. For context, I'm developing a game engine in OpenGL, using C and OpenTK. I have developed a working skeletal animation system, which loads animations using Assimp, and then passes BoneIDs, BoneWeights, and Transform matrices to the Vertex shader, which calculates all vertex deforms appropriately for the current animation keyframe (or current interpolation between keyframes). Is there a set standard for calculating collision in animations? I'd prefer to continue using Assimp, which means using standard, recognizable animation formats that my engine can load in, so I'd rather not store any collision data in the animation files, unless there is a precedent for this or room for metadata or something. My current thoughts One option would be to calculate the hitboxes and hurtboxes upon loading an animation, and have a mapping that determines which meshes are hitboxes and which are hurtboxes. The second option would be to create a new file format where I store my hitboxes and hurtboxes in a way that is similar to animation files (minus bone weights, since I'll just be transforming the scale position of axis aligned rectangles), where I can determine keyframes for hitboxes and hurtboxes, then interpolate based off of these to get the current collision box for each frame. I could combine the two options by automatically generating these files from the animations, then editing them manually until they are reasonable. Am I on the right track, or are there smarter ways of going about this? I don't want to reinvent the wheel if there are better options available.


Separate shader programs or branch in shader? I have a bunch of point lights and directional lights. Instead of checking the light type in the fragment shader and then branch for either point light calculation or directional light calculation, is it more efficient to use two separate programs, one for point lights and one for directional lights? (Using deferred shading in OpenGL 3.3)


Do unused vertices in a 3D object affect performance? For my game I need to generate a mesh dynamically. Now I'm wondering does it have a noticeable affect in FPS if I allocate more vertices than what I'm actually using or not? and does it matter if I'm using DirectX or OpenGL? Edit Final output will be a w h cell grid, but for technical issues it's much easier for me to allocate (w 1) (h 1) vertices. Sure I'll only use w h vertices in indexing, and I know there is some memory wasting there, but I want to know if it also affect FPS or not? (Note that mesh is only generated once in each time you play the game)


Keep rasterized pixel amount constant I have a scene that is rendered from the point of view of the light using an orthographic projection matrix. For an arbitrarily shaped and oriented object that doesn't change its shape or size in any way, the amount of pixels that get rasterized change with its position. I guess it's better to explain this with an images The depth of the quads (their y coordinates) are constant. Their x and z coordinates are slightly different. However, since it's an orthographic projection matrix, their "world space" floating point sizes are the same as seen from the camera. Just in one case, one additional lines of pixels is rasterized (I drew the two white lines with mspaint to illustrate their size difference). This is highly undesirable for my application. Is there a way to keep the amount of rasterized pixels consistent? How would I go about implementing it using OpenGL?


Understanding how to create use textures for games when limited by power of two sizes I have some questions about the creating graphics for a game. As an example. I want to create a motorbike. (1pixel 1centimeter) So my motorbike will have 200 width and 150 height. (200x150) But the libgdx only allows to load sizes with the power of 2?! (2,4,8,16,...) First I thought about that way. I will create my bike with the size (200x150) and save it as png. Than I will open it again (e.g. with gimp) resize the image to a size which uses values with power of 2 (128x128). I will load that as texture in the programm and set width as 200 and height as 150. But wouldn't it be a problem? Because I will lose some pixel information when I make the first conversation.?! Isn't it?


Not clearing FBO's Texture error in battery economy mode When rendering inside a FBO's texture, I'm not using glClear() but overwriting each fragment, GL BLEND is set to true. This works just fine, but I just realised when my laptop switch to economy mode, and I guess switch to egpu (intel 630) , the texture is full of garbage data when drawn. here you can see first the working render, and then the garbage one. It should be exactly the same the only difference is my laptop is not plugged in AC


Left handed version of the reversed depth projection with infinite far plane Let's say that I have standard left handed WorldToView and ViewToScreen row major matrices in the same vein as the DirectX D3DXMatrixPerspectiveLH functions, like so EXVector vView NormalizeVector(LookAt() m Position) float fDotProduct DotProduct(m WorldUp, vView) EXVector vUp NormalizeVector(m WorldUp fDotProduct vView) Generate x basis vector (crossproduct of y amp z basis vectors) EXVector vRight CrossProduct(vUp, vView) Generate the matrix row0.Set(vRight.x, vUp.x, vView.x, 0) row1.Set(vRight.y, vUp.y, vView.y, 0) row2.Set(vRight.z, vUp.z, vView.z, 0) row3.Set( DotProduct(m Position, vRight), DotProduct(m Position, vUp), DotProduct(m Position, vView), 1) EXMatrix mWorldToView(row0, row1, row2, row3) Here's the left handed mViewToScreen projection matrix float zNear 0.001f float zFar 1000.000f float Aspect DisplayHeight() DisplayWidth() float sinfov, cosfov qsincosf(VFOV() 2, sinfov, cosfov) float cotfov cosfov sinfov cos(n) sin(n) 1 tan(n) float w Aspect (cotfov) float h 1.0f (cotfov) float Q zFar (zFar zNear) float R Q zNear row0.Set(w, 0, 0, 0) row1.Set(0, h, 0, 0) row2.Set(0, 0, Q, 1) row3.Set(0, 0, R, 0) EXMatrix mViewToScreen(row0, row1, row2, row3) Many things like map object culling depend on this fact View to cull matrix Q ( zFar zNear) (zFar zNear) R (2.0f zFar zNear) (zFar zNear) row0.Set(w, 0, 0, 0) row1.Set(0, h, 0, 0) row2.Set(0, 0, Q, 1) row3.Set(0, 0, R, 0) EXMatrix mViewToCull(row0, row1, row2, row3) Does anyone know how to derive the infamous "reverse depth with infinite far plane" from the original blog post for mViewToScreen and mViewToCull? Every single reference I have found (nlguillemot and nVidia, for example) is in the right handed space. Normally I am able to figure things out visually, but 4D matrices are a headache.


setting the position in different resolution I have a normal game window which is 640 480, and everything is fine, but when I try to maximize the window, the objects translate to different positions on the screen, for example If I have a circle which is drawn at the center in the normal window, when I try to maximize it, it shifts away from the center of the screen. How do I adjust it so it draws at the center in both normal window and maximized window ?


Normal mapping soft question What could this be? So I'm trying to implement tangent space normal mapping. I bind the uniforms, load the attributes, set the shaders, and out comes this This happens on the sides only, and not when in direct light. I'm pretty sure it's matrix related, but could it be I'm mapping the tangent values incorrectly? Has anyone seen something like this before? Or have a hunch what it could be? UV screenshot, it's a cube, turned into a sphere, and each side is separated. The final object shows no seams on the top or bottom, but rather on each side. Update When I order the tangents according to UVs, I get a much cleaner result, but some areas sides still get an inverted normal. I'm not sure why this is, or how to fix it. It happens on each side, so it is as if the sides get inverted normals.


How to mitigate this strange pattern shown in Phong lighting? I am creating an entire lighting scene in OpenGL. The entire scene consist of only one point light. I noticed some strange z fighting like pattern. This flickers when I move the camera. Can anyone tell me what is the potential cause of the problem? How should I mitigate this problem? Thank you. EDIT The problem is solved. It was primarily caused by normal transform computation error and my ill made model might have been aggravated this speckle flickering effect.


What are screen space derivatives and when would I use them? I see the ddx and ddy glsl functions and the hlsl equivalents come up in shader code every now and then. I'm currently using them to do bump mapping without a tangent or bitangent but I basically copy pasted the code. I don't understand what these functions actually are, what they do, and when I would look to use them. So questions What are the screenspace derivatives functions? What do these functions do? The input values and output values What effects are they most commonly used for? What sort of effects require that you look toward these functions?