Seamless tilemap rendering (borderless adjacent images) I have a 2D game engine that draws tilemaps by drawing tiles from a tileset image. Because by default OpenGL can only wrap the entire texture (GL REPEAT), and not just part of it, each tile is split off in to a separate texture. Then regions of the same tile are rendered adjacent to each other. Here's what it looks like when it's working as intended However as soon as you introduce fractional scaling, seams appear Why does this happen? I thought it was due to linear filtering blending the borders of the quads, but it still happens with point filtering. The only solution I've found so far is to ensure all positioning and scaling only happens at integer values, and use point filtering. This can degrade the visual quality of the game (particularly that sub pixel positioning no longer works so motion is not so smooth). Things I have tried considered antialiasing reduces, but does not entirely eliminate, the seams turning off mipmapping, has no effect render each tile individually and extrude the edges by 1px but this is a de optimisation, since it can no longer render regions of tiles in one go, and creates other artefacts along the edges of areas of transparency add a 1px border around source images and repeat the last pixels but then they are no longer power of two, causing compatibility problems with systems without NPOT support writing a custom shader to handle tiled images but then what would you do differently? GL REPEAT should be grabbing the pixel from the opposite side of the image at the borders, and not pick transparency. the geometry is exactly adjacent, there are no floating point rounding errors. if the fragment shader is hard coded to return the same color, the seams disappear. if the textures are set to GL CLAMP instead of GL REPEAT, the seams disappear (although the rendering is wrong). if the textures are set to GL MIRRORED REPEAT, the seams disappear (although the rendering is wrong again). if I make the background red, the seams are still white. This suggests it's sampling opaque white from somewhere rather than transparency. So the seams appear only when GL REPEAT is set. For some reason in this mode only, at the edges of the geometry there is some bleed leakage transparency. How can that be? The entire texture is opaque.


Why does glGetString returns a NULL string I am trying my hands at GLFW library. I have written a basic program to get OpenGL renderer and vendor string. Here is the code include lt GL glew.h gt include lt GL glfw.h gt include lt cstdio gt include lt cstdlib gt include lt string gt using namespace std void shutDown(int returnCode) printf("There was an error in running the code with error d n",returnCode) GLenum res glGetError() const GLubyte errString gluErrorString(res) printf("Error is s n", errString) glfwTerminate() exit(returnCode) int main() start GL context and O S window using GLFW helper library if (glfwInit() ! GL TRUE) shutDown(1) if (glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW WINDOW) ! GL TRUE) shutDown(2) start GLEW extension handler glewInit() get version info const GLubyte renderer glGetString (GL RENDERER) get renderer string const GLubyte version glGetString (GL VERSION) version as a string printf("Renderer s n", renderer) printf("OpenGL version supported s n", version) close GL context and any other GLFW resources glfwTerminate() return 0 I googled this error and found out that we have to initialize the OpenGL context before calling glGetString(). Although I have initialized OpenGL context using glfwInit() but still the function returns a NULL string. Any ideas? Edit I have updated the code with error checking mechanisms. This code on running outputs the following There was an error in running the code with error 2 Error is no error


3D sphere generation I have found a 3D sphere in a closed source game engine that I really like the look of and would like to have something similar in my own 3D engine. This is how the sphere looks like when it is created in the game engine, at program game start At program start, a function named CreateSphere is called and the user has the option to choose a 3D position and a radius of the sphere. That's all I know about the function since the engine is closed source. Anyone have any idea of how this sphere might be generated programmatically? I have checked other posts sites discussing spheres but none of them has the look of the sphere in the image. Edit removed some unnecessary information to get to the point of what I need help with.


Can't understand these UV texture coordinates (range is NOT 0.0 to 1.0) I am trying to draw a simple 3D object generated by Google SketchUp 8 Pro onto my WebGL app, the model is a simple cylinder. I opened the exported file and copied the vertices positions, indices, normals and texture coordinates into a .json file in order to be able to use it on javascript. Everything seems to work fine, except for the texture coordinates which have some pretty big values, like 46.331676 and also negative values. Now I don't know if I am wrong, but isn't 2D texture coordinates supposed to be in a range from 0.0 to 1.0 only? Well, drawing the model using these texture coordinates gives me a totally weird look, and I can only get to see the texture properly when I am very close (not really me, the cam) to the model, as if the texture has been insanely reduced in it's size and repeated infinitely across the model's faces. (yeah, I am using GL REPEAT on that texture wrap thing) What I noticed is that if I get all these coordinates and divide them by 10 or 100 I get a much "normal" look, but still not in the 0.0 to 1.0 range. Here's my json file http pastebin.com Aa4wvGvv Here are my GLSL Shaders http pastebin.com DR4K37T9 And here is the .X file exported by SketchUp http pastebin.com hmYAJZWE I've also tried to draw this model using XNA, but still not working. Using this HLSL shaders http pastebin.com RBgVFq08 I tried exporting the same model to different formats, collada, fbx, and x. All those yields the same thing.


How to handle wildly varying rendering hardware getting baseline I've recently started with mobile programming (cross platform, also with desktop) and am encountering wildly differing hardware performance, in particular with OpenGL and the GPU. I know I'll basically have to adjust my rendering code but I'm uncertain of how to detect performance and what reasonable default settings are. I notice that certain shader functions are basically free in a desktop implemenation but can be unusable in a mobile device. The problem is I have no way of knowing what features will cause what performance issues on all the devices. So my first issue is that even if I allow configuring options I'm uncertain of which options I have to make configurable. I'm wondering also wheher one just writes one very configurable pipeline, or whether I should have 2 distinct options (high low). I'm also unsure of where to set the default. If I set to the poorest performer the graphics will be so minimal that any user with a modern device would dismiss the game. If I set them even at some moderate point, the low end devices will basically become a slide show. I was thinking perhaps that I just run some benchmarks when the user first installs and randomly guess what works, but I've not see a game do this before.


GLSL Shader compiles, but source is empty I'm trying to compile a GLSL shader, to which I use the following code. Initialization SDL Window boringInitStuff() SDL Init(SDL INIT VIDEO) SDL GL SetAttribute( SDL GL CONTEXT MAJOR VERSION, 3 ) SDL GL SetAttribute( SDL GL CONTEXT MINOR VERSION, 1 ) SDL GL SetAttribute( SDL GL CONTEXT PROFILE MASK, SDL GL CONTEXT PROFILE CORE ) Uint32 windowFlags SDL WINDOW OPENGL SDL Window sdlWindow SDL CreateWindow("Boooring", SDL WINDOWPOS UNDEFINED, SDL WINDOWPOS UNDEFINED, 400, 400, windowFlags) SDL GL CreateContext(sdlWindow) glewExperimental GL TRUE glewInit() return sdlWindow File parser void readFile(std string path, std string amp data) std ifstream f(path.c str(), std ios binary) data.assign((std istreambuf iterator lt char gt (f)), (std istreambuf iterator lt char gt ())) Main int main(int argv, char args) SDL Window sdlWindow boringInitStuff() std string buffer readFile(". compile test.vert", buffer) const char cBuffer buffer.c str() GLuint shaderID glCreateShader(GL VERTEX SHADER) glShaderSource(shaderID, 1, amp cBuffer, nullptr) glCompileShader(shaderID) while(!SDL QuitRequested()) SDL GL SwapWindow(sdlWindow) return 0 But when I try to inspect the source code in gDEBugger, the source code is gone. Linking of course doesn't work aswell. The weird thing is, that the compilation error checking works. EDIT When I copy amp paste the main part into another opengl project, it works.


Good system for experimenting with shaders in different languages I'm trying to experiment a bit with shaders and they have been programmed in several different languages (GLSL, Cg and HLSL). Now most systems (dirrectX, openGL) have only support for one of them. Does anybody know of such a system that easily allows all 3? Thank you


glsl demo suggestions? In a lot of places I interviewed recently, I have been asked many a times if I have worked with shaders. Even though, I have read and understand the pipeline, the answer to that question has been no. Recently, one of the places asked me if I can send them a sample of 'something' that is "visually polished". So, I decided to take the plunge and wrote some simple shader in GLSL(with opengl).I now have a basic setup where I can use vbos with glsl shaders. I have a very short window left to send something to them and I was wondering if someone with experience, could suggest an idea that is interesting enough to grab someone's attention. Thanks


Render rotated rectangle inside other rectangle bounds using Libgdx I have this code to generate a red rectangle inside a grey rectangle new Rectangle(grey rectangle position x, Game.SCREEN HEIGHT 2 Rectangle.height 2,0) This code makes the following Now, I want to rotate the red rectangle and randomize his X coordinate but keeping it inside the grey rectangle. This is my actual code of the rectangle public class Rectangle public static int width 30 public static int height 60 public static Color color Color.RED public Rectangle(int x, int y, int angle) super(x, y,angle) public void render(ShapeRenderer shapeRenderer) shapeRenderer.begin(ShapeType.Filled) shapeRenderer.setColor(color) shapeRenderer.identity() shapeRenderer.translate(pos x width 2, pos y, 0.f) shapeRenderer.rotate(0.f, 0.f, 1.f, angle) shapeRenderer.rect( width 2, height 2, width, height) shapeRenderer.end() And this is what I should do to randomize the position of the rectangle new Rectangle(randomized x position, Game.SCREEN HEIGHT 2 Rectangle.height 2,0) The problem is that I don't know how to calculate the randomized x position in order to keep the rectangle inside the grey rectangle. Another problem is that the current Rectangle.render() method is making my rectangle outside the grey rectangle after rotation When what I really want is


Rotate a plane defined by its normal and its distance First apologies for the amount of pictures, it's a bit hard trying to explain my problem without pictures. Hope I've provided all the relevant code. If you feel you want to know about how I am doing something else, please tell me and I will include it. I've been trying to work around rotating a plane in 3D space, but I keep hitting dead ends. The following is the situation I have a physics engine where I simulate a moving sphere inside a cube. To make things simpler, I have only drawn the top and bottom plane and moved the sphere vertically. I have defined my two planes as follows CollisionPlane p new CollisionPlane(glm vec3(0.0, 1.0, 0.0), 5.0) CollisionPlane p2 new CollisionPlane(glm vec3(0.0, 1.0, 0.0), 5.0) Where the vec3 defines the normal of the plane, and the second parameter defines the distance of the plane from the normal. The reason I defined their distance as 5 is because I have scaled the the model that represents my two planes by 10 on all axis, so now the distance from the origin is 5 to top and bottom, if that makes any sense. To give you some reference, I am creating my two planes as two line loops, and I have a model which models those two line loop, like the following top plane std shared ptr lt Mesh gt f1 std make shared lt Mesh gt (GL LINE LOOP) std vector lt Vertex gt verts Vertex(glm vec3(0.5, 0.5, 0.5)), Vertex(glm vec3(0.5, 0.5, 0.5)), Vertex(glm vec3( 0.5, 0.5, 0.5)), Vertex(glm vec3( 0.5, 0.5, 0.5)) f1 gt BufferVertices(verts) bottom plane std shared ptr lt Mesh gt f2 std make shared lt Mesh gt (GL LINE LOOP) std vector lt Vertex gt verts2 Vertex(glm vec3(0.5, 0.5, 0.5)), Vertex(glm vec3(0.5, 0.5, 0.5)), Vertex(glm vec3( 0.5, 0.5, 0.5)), Vertex(glm vec3( 0.5, 0.5, 0.5)) f2 gt BufferVertices(verts2) std shared ptr lt Model gt faceModel std make shared lt Model gt (std vector lt std shared ptr lt Mesh gt gt f1, f2 ) And like I said I scale the model by 10. Now I have a sphere that moves up and down, and collides with each face, and the collision response is implemented as well. The problem I am facing is when I try to rotate my planes. It seems to work fine when I rotate around the Z axis, but when I rotate around the X axis it doesn't seem to work. The following shows the result of rotating around Z However If I try to rotate around X, the ball penetrates the bottom plane, as if the collisionplane has moved down The following is the code I've tried to rotate the normals and the planes for (int i 0 i lt m entities.size() i) glm mat3 normalMatrix glm mat3 cast(glm angleAxis(glm radians(6.0f), glm vec3(0.0, 0.0, 1.0))) CollisionPlane p (CollisionPlane )m entities i gt GetCollisionVolume() glm vec3 normalDivLength p gt GetNormal() glm length(p gt GetNormal()) glm vec3 pointOnPlane normalDivLength p gt GetDistance() glm vec3 newNormal normalMatrix normalDivLength glm vec3 newPointOnPlane newNormal (normalMatrix (pointOnPlane glm vec3(0.0)) glm vec3(0.0)) p gt SetNormal(newNormal) float newDistance newPointOnPlane.x newPointOnPlane.y newPointOnPlane.z p gt SetDistance(newDistance) I've done the same thing for rotating around X, except changed the glm vec3(0.0, 0.0, 1.0) to glm vec3(1.0, 0.0, 0.0) m entites are basically my physics entities that hold the different collision shapes (spheres planes etc). I based my code on the answer here Rotating plane with normal and distance I can't seem to figure at all why it works when I rotate around Z, but not when I rotate around X. Am I missing something crucial?


What's better drawing every interval that the window updates, or drawing when necessary and updating when drawing? So what's better? In case the title is a bit confusing I mean 1) Drawing every window update interval. For example, for a 60FPS window, every 17 milliseconds. For example window.setFramerateLimit(60) Update every 17 milliseconds for 60FPS while(window.isOpen()) window.display() Or 2) Drawing when you need to (for example, when a sprite moves) and displaying it straight after. For example void func(sf RenderWindow amp window) window.draw(sf Sprite()) Whatever you're drawing window.display() Or is there a much better way?


For deferred rendering and SSAO, what coordinate system are the normals actually in? So, I'm following the very helpful LearnOpenGL online tutorials, and I'm working on implementing SSAO. I don't have a deferred rendering pipeline, but I need to collect normals during my depth pass so that I can sample them for the SSAO effect. I'm following this tutorial https learnopengl.com Advanced Lighting SSAO, and referencing this one when needed https learnopengl.com Advanced Lighting Deferred Shading. However, neither of these tutorials really explain what's going on with the normals. What is the normalMatrix being used in the shader? mat3 normalMatrix transpose(inverse(mat3(view model))) Normal normalMatrix (invertedNormals ? aNormal aNormal) I'm not worried about the invertexNormals conditional, that's probably just something weird the author added for handling different conventions, but what the heck is going on with that normalMatrix? Why would we invert the view model matrix? If we're starting with aNormal in object space (whether it's coming directly from a vertex buffer or from a normal map TBN calculation), I can't for the life of me figure out what coordinate system that resulting normal is going to end up in! So, long story short, what coordinate frame should my normals be in if I'm to use them for SSAO? World space? View Space? Clip space? None of the above? If it's some weird coordinate system, can somebody help me get there? I'm probably more confused than I should be.


Setting up openGL on Linux I am trying to figure out how to set up openGL on Linux based operating systems (Ubuntu 12.10) without using any GLUT libraries. I don't have much experience with developing on Linux distributions. To be more precise I'm trying to make a statically linked library that compiles on the three major OS flavours (using some preprocessor macros to figure out the os its being compiled on and switch up renderer code, window creation code etc). On windows I have successfully created a openGL 4.0 rendering context using wglCreateContextAttribsARB and the GL gl.h provided by mingw. On Ubuntu I have managed to create a openGL 2.2 rendering context using glXCreateContextAttribsARB and the GL gl.h provided by mesa3d. This was however in a VMware Ubuntu VM and so mesa(9.0.2 I believe) would only manage to go that far with a virtual graphics card. So I decided to go ahead and install Ubuntu on a external HDD to take advantage of the graphics card only to later find out that mesa(9.1) can only go up to openGL 3.1. After a little bit of research I figured out that the AMD and Nvidia drivers have support for openGL 4.3. So I installed the AMD 13.1 drivers (I have a Sapphire 7970 vapor x 6GB) but then the openGL header files that come with it are really strange, GL glATI.h tries to include windows.h, it doesn't define APIENTRY etc. The question is whats the proper way of setting up openGL (with 4.3 support) for Linux? And even if the GL glATI.h files were proper, wouldn't they fail if ran on a Nvidia card? I'm manually creating the window with XCreateWindow and then I'm loading the extensions with glXGetProcAddressARB so I'm not going to use GLUT or any GLUT like library.


How to mix pixel colors in Shader? I have a pixel that have a colour RGB. This color is calculated by the shader and can be anything. How can I override this color by a colour I choose. If my pixel is white it's simple, I can do this half3 original half3(1, 1, 1) half3 mycolor half3(1, 0, 0) half3 result original mycolor But what can I do if half3 original half3(0.36, 0.74, 0.18) half3 mycolor half3(1, 0, 0) half3 result ? What operation or function should I apply to my original pixel color to override it ?


OpenTK Camera Rotation issue I'm currently developing a 3D game engine in C using OpenTK. I have basic game objects, and each game object has transform (translation, rotation and scaling). A game object can have components (much like Unity). One game object (The camera game object) has three components, A camera, free move and a free look component. The free move component allows the user to move the camera around the scene, whilst the free look camera is SUPPOSED to rotate the camera. However, I get this odd effect https youtu.be rcdWZcaEqSY (Note that, the plane isn't changing position, it seems the camera is ... turning upside down?) On top of that, once I rotate the camera, moving the camera (using the arrow keys) gets really weird, up can become down, left can become right. It's all very odd. Anywho, here is the update method for my Free Look component protected override void OnUpdate(object sender, UpdateEventArgs e) Rectangle bounds Game.GetCurrentGame().Window.Bounds Vector2 center new Vector2(bounds.Left (bounds.Width 2), bounds.Top (bounds.Height 2)) Vector2 mousePosition new Vector2(System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y) Vector2 deltaPosition center mousePosition bool rotX deltaPosition.X ! 0 bool rotY deltaPosition.Y ! 0 if(rotY) Transform.Rotate(new Vector3(0, 1, 0), MathHelper.DegreesToRadians( deltaPosition.X sensitivity)) if(rotX) Transform.Rotate(new Vector3(1, 0, 0), MathHelper.DegreesToRadians( deltaPosition.Y sensitivity)) if (rotY rotX) System.Windows.Forms.Cursor.Position new Point((int)center.X, (int)center.Y) base.OnUpdate(sender, e) here is the Rotate method in my transform class public void Rotate(Vector3 axis, float angle) rotation (Quaternion.FromAxisAngle(axis, angle) rotation).Normalized() I hope someone can help me get to the bottom of this, I've been so frustrated! If there's any other code you need to see, just let me know.


Proper way to update pixel array data For a game that updates a board every frame I am calculating the next arrangement of board, updating pixel array data and render board as 2D texture to quad the size of the screen using OpenGL. I use glTexImage2d(GL TEXTURE 2D,0,GL RGBA,tex width,tex height,0,GL BGRA,GL UNSIGNED INT 8 8 8 8 REV, amp pixel data.front()) to initialize the texture object and glTexSubImage2d(GL TEXTURE 2D,0,0,0,tex width,tex height, BGRA,GL UNSIGNED INT 8 8 8 8 REV, amp pixel data.front()) to update the texture. The slowest part of the code is update pixels() (below) Taking 256x128 elements input array and creating four component pixel array based on that. This function is very slow(45ms) and it seems it should be done differently. What would be the proper way to implement this function? Update pixel data per frame void update pixels() update pixels std vector lt unsigned char gt pixel data float state 0 size t it 0 for (size t y 0 y lt board.getWorldHeight() y) for (size t x 0 x lt board.getWorldWidth() x) state board.get state(y golf board.getWorldWidth() x) pixel data y board.getWorldWidth() x it static cast lt unsigned char gt (state 255) it pixel data y board.getWorldWidth() x it static cast lt unsigned char gt (state 255) it pixel data y board.getWorldWidth() x it static cast lt unsigned char gt (state 255) it pixel data y board.getWorldWidth() x it static cast lt unsigned char gt (1 255) return Time measurement void render() render frame() glDrawElements() for quad and scale uniform update takes 0.2ms generate states() new states for board takes 1.3ms auto t1 std chrono high resolution clock now() update pixels() create new pixel array, takes 32 ms auto t2 std chrono high resolution clock now() float update time std chrono duration cast lt std chrono microseconds gt (t2 t1).count() 1000.0f cout lt lt updae time glfwSwapBuffers() from update pixels to swap takes 13ms


Rendering multiple textures on same image for terrain with index buffers (LWJGL 3) I have started with LWJGL3 and trying to built game engine. I'm stuck on generating terrains and this is my second big problem and I'm exhausted so I need some advice on how to solve my problem. What I want to achieve I want to have all textures in one place and to have some kind of texture map that I will use to render specific texture at that place. example textures map but result is Only thing that I think is problem is because I use same points (index buffers) So instead of 8 points, I have 6. Is it possible that then texture gets all messed up? Should I use all points, even if they are at same or almost the same location? But then I would have a lot more vertices than actually need it.


Section cut through (solid) geometry I'm looking for image based (screen space) technique to render section cuts through arbitrary (solid) geometry. I found and studied image based CSG (Kirsch 05 OpenCSG) but I found it to be perhaps a bit of a overkill for my case, where all I need is a section plane cut. Above is a naive implementation using a discard in the fragment shader, but that obviously is not even half way there as I need to close the gaps. Does anyone know of a technique hack I could use?


How does Halo draw projectiles? I am trying to draw projectiles and doing billboarding. A projectile consists of a bill boarded "particle" and a "tracer". When I billboard a projectile, it cannot be seen when the player's viewing direction is parallel to the projectile axis. How does Halo or other games solve this problem, so that projectiles can be seen from behind.


How do I play a video file in OpenGL? Is there a library that will let me load a movie file and play it in an OpenGL application? Or maybe just a code sample that someone has lying around? I'm also using GLUT, if that makes a difference. I guess file format doesn't matter, although currently my movie is in AVI format.


recommended shader pipeline infrastructure in core opengl 3.3 I am writing a game project in Go and I am using an OpenGl 3.3 core context to do my rendering stuff. At the moment I have different types of renderers. Each renderer has it's own pair of vertex and fragment shader, a struct of uniform and attribute locations. A struct with glBuffers, vertex array object, and numverts (int) which contains all data required to render one object (mesh). Last but not least a constructor to create and initialize the attribute uniform locations a method to load a mesh into mesh data and the render method itself. I am absolutely not happy with this design. Every time I want to create a new simple shader, I have to write all this code, and I haven't found a way to make the overhead of a new shader smaller. All I was able to make with the help of go reflections is to automatically get the attribute uniform location based on the variable name in attribute uniform location struct and to automatically set the attribute pointers based on the layout of the vertex struct. another thing that I don't like, is that when I want to implement for example the functionality of the function glClipPlane of the fixed function pipeline, I need to add the uniform to each shader separately and I need to set this uniform in each shader and I need to implement the discard of fragments in each fragment shader Are there some common practices that significantly reduce the code overhead of a new shader? Are there good shader pipelines that you can recommend me to take a look at? Are there some good practices to add functionality to several shaders at once?


How to solve artifacts caused by vertex lighting in my voxel engine? My current lighting system bakes the light amount based on ray tracing from the light source to the 8 corners of the block (so per vertex) and the distance to the light on the blocks. It works acceptable, but it's definitely not perfect. Of course the blocks are made out of faces, which are made out of triangles. In the situation shown in the screenshot, where there is a light directly behind the camera, you get those weird triangle lighting issues. How can I fix this problem?


Artifacts when draw particles with some alpha I want to draw in my game some particles. But when I draw one particle above another particle, alpha channel from this above "clear" previous drawed particle. I set in OpenGL blend in this way glBlendFunc( GL SRC ALPHA, GL ONE MINUS SRC ALPHA ) My fragment shader for particle is very simple precision highp float precision highp int uniform sampler2D u maps 2 varying vec2 v texture uniform float opaque uniform vec3 colorize void main() vec4 texColor texture2D(u maps 0 , v texture) gl FragColor.rgb texColor.rgb colorize.rgb gl FragColor.a texColor.a opaque I attach screenshot from this Do you know what I made wrong ? I use OpenGL ES 2.0.


Failing to move exponential depth term to depth shader in exponential shadow mapping I'm playing around in my little toy project to see if I can understand how exponential shadow mapping works. To begin, I have the following two fragment shaders Light depth texture shader layout(location 0) out float fragmentdepth void main() fragmentdepth gl FragCoord.z Main shader ... vec3 shadowDiv shadowCoords.xyz shadowCoords.w float lightDepth texture(depthMap, shadowDiv.xy) float visibility clamp(exp( 70 shadowDiv.z) exp(70 lightDepth), 0, 1) ... This works fine I have shadows where I expect them, and I'm using the approximation to the boolean function by taking the product of exponentials, as shown in the ESM paper. However, my understanding is that the whole point of this, is that I can move exp(70 lightDepth) out of this shader, and into the shader when I generate the depth texture at the light. That is New light depth texture shader layout(location 0) out float fragmentdepth void main() fragmentdepth exp(70 gl FragCoord.z) Main shader ... vec3 shadowDiv shadowCoords.xyz shadowCoords.w float lightDepth texture(depthMap, shadowDiv.xy) float visibility clamp(exp( 70 shadowDiv.z) lightDepth, 0, 1) ... When I make this change, the entire scene becomes shadowed. I'm sure I'm misunderstanding something somewhere, but I'm not sure where. I have tried varying the constant term (70) between 1 and 70, though this doesn't appear to make a difference. I have no errors reported by KHR debug I am creating my light depth texture as genLightDepthMap IO GLTextureObject genLightDepthMap do lightDepthMap lt overPtr (glGenTextures 1) glBindTexture GL TEXTURE 2D lightDepthMap glTexParameteri GL TEXTURE 2D GL TEXTURE MIN FILTER GL LINEAR glTexParameteri GL TEXTURE 2D GL TEXTURE MAG FILTER GL LINEAR glTexParameteri GL TEXTURE 2D GL TEXTURE WRAP S GL CLAMP TO EDGE glTexParameteri GL TEXTURE 2D GL TEXTURE WRAP T GL CLAMP TO EDGE glTexImage2D GL TEXTURE 2D 0 GL DEPTH COMPONENT24 shadowMapResolution shadowMapResolution 0 GL DEPTH COMPONENT GL FLOAT nullPtr


Vertex shader in OpenGL GLSL transformation of the interior of a textured quad I have a LWJGL project and ran into a problem with a vertex shader I wrote. In my scene I am rendering a map whose ground consists of rectangular tiles. On top of that there are other objects (I used tiny white balls here). Here is a screenshot of my scene screenshot of my scene http 110.imagebam.com download 0 Ktu6XjdWSMpKytTr3Trg 34736 347358711 scene static.jpg You can also click here to see the image. Each of the four larger rectangles at the bottom is one huge quad drawn in one piece. Every one of them contains four coordinates (the corners top left, top right, bottom right, bottom left). Their interior is filled with a texture. The small white balls on top are single game objects each drawn by itself. Note that I aligned them with the vertical edges of the underlying rectangles. I used the following vertex shader to render the scene default shader version 120 void main() gl TexCoord 0 gl MultiTexCoord0 gl Position gl ModelViewProjectionMatrix gl Vertex Now imagine the scene getting covered with water. I modified the shader adding a little water effect water shader version 120 uniform float amplitude uniform float phase void main() gl TexCoord 0 gl MultiTexCoord0 transform x vec4 a position gl Vertex a position.x a position.x amplitude sin(phase a position.x) gl Position gl ModelViewProjectionMatrix a position An animated image of my scene can be found here or here. You can see that the borders of the rectangles keep aligned with the white balls on top of them. However, vertices inside the rectangles (I marked the most distinct areas red) suffer a displacement relative to the white balls. In the last rectangle you can even see the balls cross the white line in the middle. I need the interior of my textured rectangles to be transformed exactly like the white balls on top and move uniformly when being animated by my shader. Please let me know if my problem is clear and if any other information is needed. Thank you very much for your help. Greetings Xoric


Send Geometry Data to Multiple Shaders So I am implementing a deferred rending model for my engine, and I want to be able to send all scene geometry into a single shader to calculate ambient, diffuse, normal, ect thats not the question. Once I have all of this data buffered into the GPU I can render all of that geometry from a camera perspective defined by a uniform for the cameras position in the scene. I am wondering if I can reuse this model data already in VRam in another shader translated by a light sources projection matrix to calculate the shadows on this scene geometry without needing to send the same data to the GPU again. Is there a way to tell my light shader, hey all that juicy geometry scene data you want is already in V Ram, just use this matrix transformation instead. Alternatively when I am sending the VAO to the GPU is there a way to send it to two shades in parallel, one for the deferred rending model, one for shadow casing light sources? Thanks so much!


Confusion over GLViewport I'm hoping someone can help me understand the GLViewport and what happens when we resize it This will illustrate my confusion.... So, here I have a quad stuck in the middle of the screen. If I have my GLViewport match the device's width and height, I get what is on the first (left hand) picture. Exactly what I would expect. Device resolution, 2560 x 1600 Viewport resolution 2560 x 1600 Quad size 200 x 200 (Note, the image above is not to scale!!! )) Quad shape, appears as square Now, for the 2nd (right hand) picture... Device resolution, 2560 x 1600 Viewport resolution 2560 x 1200 (and centered vertically) Quad size (200, 200) Quad shape, appears as rectangle My question is, why is the quad displaying as a rectangle now and not a square? I've confirmed by logging that my quad is 200 x 200 pixes surely the size of the physical pixels stays the same? They can't change. So what is going on here? I thought (clearly incorrectly) that when I scaled the viewport, it literraly just chopped off pixels. Would appreciate if someone could explain how this works. Edit Currently, I'm setting my viewport like this width (int) Math.min(deviceWidth, deviceHeight 1.702127659574468) height (int) Math.min(deviceHeight, deviceWidth 1.702127659574468) ratio width height GLES20.glViewport(offsetX, offsetY, width, height) Matrix.orthoM(mProjMatrix, 0, ratio, ratio, 1, 1, 3, 7) offsetX and offsetY are just so that when there are letterboxes, the viewport is centered.


uniform z slices in clip space 1) Context I'm using a regular OpenGL perspective projection matrix created with GLM (glm perspective) and taking the inverse (glm inverse) to transform clip space back into view space (and world space ultimately). Now with z values at the near and far plane it's easy to choose the x,y,z,w components of the clip space cube corners and get the world space point of the frustum volume. 2) Question Now, I want to harness the fact that clip space is a cube and generate a grid over the frustum. for x,y this works with the regular inverse projection matrix. For z, if I take uniform subdivisions of the range 1.0, 1.0 with w 1.0, the view space z values will not be linear. I haven't got enough sleep recently to convince myself to do the math. What would be an inverse projection matrix to do this?


How can I apply a mesh distortion to walls like in Dungeon Keeper 2? In Dungeon Keeper 2, the walls of the dungeon have different random shapes depending on its state (freshly dug or reinforced, and so on). They look like they are cubes of 3x3 vertices that have a x z planar jitter or distortion. However, the corner vertices are shared by adjacent cubes, so there must be some kind of algorithm rather than just a random jitter. How could I achieve a similar effect?


Shader Convert vector into scalar I am trying to convert a half3 as a simple half but I am facing an issue. As for an example half3(1, 0, 0) give me white but half3(0, 1, 0) gives me black. How can I convert properly a half3 to a simple black and white half value Thank you.


OpenGL Two point perspective view Summary I want vertical lines to be drawn as vertical lines regardless of their position relative to the camera (distance offset). I want the projection to be perspective so the furthest objects from camera look smaller while keeping their respective proportions. What am I trying to achieve A two (vanishing) point perspective like this one http insidetheoutline.com wp content uploads 2019 07 2 Point Perspective Cityscape.jpg Why am I at it I'm really bad at 3D (obviously) therefore I'm trying to replace character models with 2D sprites like in Populous 3, or quot The Game quot quest in Fable 3. I also want to have a top downish view like in isometric games. Alas, perspective distortion totally kills the effect, making sprites look skewed whenever they are off center. What am I doing right now glMatrixMode(GL PROJECTION) glLoadIdentity gluPerspective(FOV, wndWidth wndHeight, zNear, zFar) Googling lead me to this MV matrix, alas it's not working for me 1, 0, 0, 0, 0, 1, 0, 0, 0, camY camZ, camZ, 0, 0, 0, 0, 1 glMatrixMode(GL MODELVIEW) glLoadMatrixf( cam) camX camY camZ 50 gluLookAt( camX, camY, camZ, 0, 0, 0, 0, 0, 1 ) then I draw a uniform grid 5..5 by 5..5 and slightly off center wireframe box to test if they are drawn correctly Does it work? No, it doesn't. Provided matrix produce no result at all, so I had to change it to 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, camY camZ, camZ, 1 . Just like any text on a two point perspective says quot Set one of the values in the last column to zero quot . I tried zero in any position, except the last one, to no avail. Generally, I get something like this The rightmost vertical line the one that aligns with screen center is vertical, just as I want all of them to be, but the others are skewed away. What else I managed to google Not much, really. I found an example that kinda looks like something I want to achieve, but they place the camera at ground level with zero Z delta, effectively eliminating the third vanishing point. In some other example, they just narrowed FOV to some absurdly low value, making it look like a two point perspective to some extent. I'm afraid I'm missing or misunderstanding something. I also not sure if the desired output will, in fact, look like I want, and I won't discard it if it's not.


Ray picking get direction from pitch and yaw I am attempting to cast a ray from the center of the screen and check for collisions with objects. When rendering, I use these calls to set up the camera GL11.glRotated(mPitch, 1, 0, 0) GL11.glRotated(mYaw, 0, 1, 0) GL11.glTranslated(mPositionX, mPositionY, mPositionZ) I am having trouble creating the ray, however. This is the code I have so far ray.origin new Vector(mPositionX, mPositionY, mPositionZ) ray.direction new Vector(?, ?, ?) My question is what should I put in the question mark spots? I.e. how can I create the ray direction from the pitch and roll? Any help would be much appreciated!


Does LibGDX abstract OpenGL ES away or can I still use my OpenGL ES knowledge? I've been learning OpenGL ES, and am now turning my attention to using LibGDX. My main concern with LibGDX is, if needed, will I be able to apply my OpenGL ES knowledge to something if needed and essentially override bits and pieces of the framework, or does LibGDX essentially hide any implementations of OpenGL?


Calling opengl32.DLL from java? I don't like LWJGL in some cases, so I prefer to use Swing. The thing is that Swing doesn't have OpenGL. I have tried JOGL and it's a mess to install, needs external jars, and I have yet to get it working. So I was wondering if I could just make an OpenGL class that uses opengl32.DLL and put the graphics into a window made with Swing? Also, is opengl32.DLL able to be called with a 64 bit Java program?


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?


How to generate a multiplier map for radiosity I am following this tutorial here I am at the part where you are creating a hemicube. I have got the code to render the scene into a texture and therfore an array. Now how can I generate a so called "multiplier map" for use given these parameters width, height, camera location, camera direction normal. I want the multiplier map to be stored in an array like this unsigned char mult0 new unsigned char width height I will have 5 of these maps for each side of the hemicube.


openGL textures in bitmap mode For reasons detailed here I need to texture a quad using a bitmap (as in, 1 bit per pixel, not an 8 bit pixmap). Right now I have a bitmap stored in an on device buffer, and am mounting it like so glBindBuffer(GL PIXEL UNPACK BUFFER, BFR.G (T 1) 2 ) glTexImage2D(GL TEXTURE 2D, 0, GL RGB, W, H, 0, GL COLOR INDEX, GL BITMAP, 0) The OpenGL spec has this to say about glTexImage2D "If type is GL BITMAP, the data is considered as a string of unsigned bytes (and format must be GL COLOR INDEX). Each data byte is treated as eight 1 bit elements..." Judging by the spec, each bit in my buffer should correspond to a single pixel. However, the following experiments show that, for whatever reason, it doesn't work as advertised 1) When I build my texture, I write to the buffer in 32 bit chunks. From the wording of the spec, it is reasonable to assume that writing 0x00000001 for each value would result in a texture with 1 px wide vertical bars with 31 wide spaces between them. However, it appears blank. 2) Next, I write with 0x000000FF. By my apparently flawed understanding of the bitmap mode, I would expect that this should produce 8 wide bars with 24 wide spaces between them. Instead, it produces a white 1 px wide bar. 3) 0x55555555 1010101010101010101010101010101, therefore writing this value ought to create 1 wide vertical stripes with 1 pixel spacing. However, it creates a solid gray color. 4) Using my original 8 bit pixmap in GL BITMAP mode produces the correct animation. I have reached the conclusion that, even in GL BITMAP mode, the texturer is still interpreting 8 bits as 1 element, despite what the spec seems to suggest. The fact that I can generate a gray color (while I was expecting that I was working in two tone), as well as the fact that my original 8 bit pixmap generates the correct picture, support this conclusion. Questions 1) Am I missing some kind of prerequisite call (perhaps for setting a stride length or pack alignment or something) that will signal to the texturer to treat each byte as 8 elements, as it suggests in the spec? 2) Or does it simply not work because modern hardware does not support it? (I have read that GL BITMAP mode was deprecated in 3.3, I am however forcing a 3.0 context.) 3) Am I better off unpacking the bitmap into a pixmap using a shader? This is a far more roundabout solution than I was hoping for but I suppose there is no such thing as a free lunch.


Noisy edges, smoothing out edges between faces via fragment shader I have a generated terrain, with hexagonal geometry, as per screenshot below I then generate biomes, but as you can see the borders between them are really ugly and straight. To hide that hexagonal origin, I would need to smooth out the borders between biomes. This is how it looks now in wireframe with real tringular faces What I'm aiming for is something more like this Each vertex has attibute that holds the biome type, I can also add special attributes to the vertices on the edge between two biomes, but I just don't seem to be able to figure out how to pull this off in shader code, obviously noise is involved here, but how do I make it continous across multiple faces and entire border of multiple biomes? I'm rendering with WebGL using THREE.js


how to add water effect to an image This is what I am trying to achieve A given image would occupy say 3 4th height of the screen. The remaining 1 4th area would be a reflection of it with some waves (water effect) on it. I'm not sure how to do this. But here's my approach render the given texture to another texture called mirror texture (maybe FBOs can help me?) invert mirror texture (scale it by 1 along Y) render mirror texture at height 3 4 of the screen add some sense of noise to it OR using pixel shader and time, put pixel.z sin(time) to make it wavy (Tech C OpenGL glsl) Is my approach correct ? Is there a better way to do this ? Also, can someone please recommend me if using FrameBuffer Objects would be the right thing here ? Thanks


OpenGL Blending feedback effect I'm struggling on a simple project, as an example sandbox, I'm rendering a small oscillating rectangle on my output. I'm not using glclearcolor() but instead, on every frame I draw a black rectangle before anything else, blending with glBlendFunc(GL SRC ALPHA, GL ONE MINUS SRC ALPHA) My goal is to see as I play with the alpha of this black rectangle feedback of previous frames, slowly fading, some kind of trail, and it's more or less working. My main problem though, the trail never really disappears, and the longer I try to get the trail, the worse it gets. Also, I have to quite crank the alpha before seeing any trail, I don't really understand why.


What version of OpenGL should I target for Steam? I'm planning on developing a game (targeting towards PC and Linux) and putting it up on Steam in the future but I am not sure of what version of OpenGL to target so that the majority of steam users can be able to play my game. I know Steam has a hardware survey but I'm still not sure of what OpenGL to use but a lot of people recommend OpenGL 3.0 and to make sure not version OpenGL 3.x since 3.x ! 3.0.


Uniform not being applied to proper mesh Ok, I got some code, and you select blocks on a grid. The selection works. I can modify the blocks to be raised when selected and the correct one shows. I set a color which I use in the shader. However, I am trying to change the color before rendering the geometry, and the last rendered geometry (in the sequence) is rendered light. However, to debug logic I decided to move the block up and make it white, in which case one block moves up and another block becomes white. I checked all my logic and it knows the correct one is selected and it is showing in, in the correct place and rendering it correctly. When there is only 1 it works properly. Video Of the bug in action, note how the highlighted and elevated blocks are not the same block, however the code for color and My Renderer is here (For the items being drawn) public void render(Renderer renderer) mGrid.render(renderer, mGameState) for (Entity e mGameEntities) UnitTypes ut UnitTypes.valueOf((String)e.getObject(D.UNIT TYPE.ordinal())) if (ut UnitTypes.Soldier) renderer.testShader.begin() renderer.testShader.setUniformMatrix("u mvpMatrix",mEntityMatrix) renderer.texture soldier.bind(0) Vector2 pos (Vector2) e.getObject(D.COORDS.ordinal()) mEntityMatrix.set(renderer.mCamera.combined) if (mSelectedEntities.contains(e)) mEntityMatrix.translate(pos.x, 1f, pos.y) renderer.testShader.setUniformf("v color", 0.5f,0.5f,0.5f,1f) else mEntityMatrix.translate(pos.x, 0f, pos.y) renderer.testShader.setUniformf("v color", 1f,1f,1f,1f) mEntityMatrix.scale(0.2f, 0.2f, 0.2f) renderer.model soldier.render(renderer.testShader,GL20.GL TRIANGLES) renderer.testShader.end() else if (ut UnitTypes.Enemy Infiltrator) renderer.testShader.begin() renderer.testShader.setUniformMatrix("u mvpMatrix",mEntityMatrix) renderer.testShader.setUniformf("v color", 1.0f,1,1,1.0f) renderer.texture enemy infiltrator.bind(0) Vector2 pos (Vector2) e.getObject(D.COORDS.ordinal()) mEntityMatrix.set(renderer.mCamera.combined) mEntityMatrix.translate(pos.x, 0f, pos.y) mEntityMatrix.scale(0.2f, 0.2f, 0.2f) renderer.model enemy infiltrator.render(renderer.testShader,GL20.GL TRIANGLES) renderer.testShader.end() String vertexShader "uniform mat4 u mvpMatrix n" "attribute vec4 a position n" "attribute vec2 a uv n" "varying vec2 v uv n" "void main() n" " n" " v uv vec2(a uv.x,1.0 a uv.y) n" " gl Position u mvpMatrix a position n" " n" String fragmentShader " ifdef GL ES n" "precision mediump float n" " endif n" " uniform vec4 v color " " uniform sampler2D tex " " varying vec2 v uv n" "void main() n" " n" " gl FragColor v color texture2D(tex, v uv) n" " " testShader new ShaderProgram(vertexShader, fragmentShader)


Why is my depth buffer texture so bright? https www.youtube.com watch?v QuvAEqgHrMY amp feature youtu.be https www.youtube.com watch?v 5ob1JsPIGAs amp feature youtu.be gluPerspective(60, (float)CONTEXT WIDTH CONTEXT HEIGHT, 0.1f, 1.f) values used for first video gluPerspective(60, (float)CONTEXT WIDTH CONTEXT HEIGHT, 0.1f, 2000.f) values used for second video, the further z clip value seems to improve the depth rendered, but far from example images below. I set my projection matrix with gluPerspective. This seems to happen when I try gluPerspective when I set my projection matrix to first person. The type of image I would like to get is Is the visual result I am getting correct? Then are the listed examples of depth buffer images are merely a result of refining post rendering process, that are simply added in order for humans to see it better?


When to use a vertex array and when to use a VBO? I'm trying to learn about vertex arrays and vertex buffer objects, but I don't understand the differences in terms of case of use (static geometry like terrains, geometry that changes every frame like a particle system, etc.) performance portability (old graphics card, consoles, devices like Android or iPhone, etc.) some clarifications?


Does Blitz3D use its own 3D engine or does it wrap OpenGL? How does Blitz3D work? I mean internally, does it use OpenGL with basic wrappers or it using some open source 3D engine that itself wraps OpenGL?


Possible to create transparency shader which doesn't stack alpha values The image above best demonstrates what I'm trying to achieve. It's a transparent shader for objects, but wherever the objects with this shader intersect they don't add together but simply merge with the same amount of transparency. It seems like a simple thing, but I can't tell if it's even possible from my understanding of how the shader pipeline works. From what I understand of the process (and please correct me if I'm wrong), a fragment is created by each independent object. Once all the fragments for each object are created, the depth buffer chooses which fragment to write to that pixel in the framebuffer at a time, layering them on top of each other, so to speak. Once they've all been added to the framebuffer, the final result becomes the pixel. If I could access the individual fragments to compare them against each other before they get written ('layered') into the frame buffer, it would be a simple case of tracking them and discarding any extra fragments in the same pixel space that are part of this shader render queue. But I don't think this is possible with OpenGL? Is there perhaps another way I can achieve the same effect?


alpha test shader 'discard' operation not working GLES2 I wrote this shader to illustare alpha test action in GLES2 (Galaxy S6). I think is not working at all cause I don't see any change with or without it. Is there anything Im missing? Any syntax error? I know its better not using if in shader but for now this is the solution I need. precision highp float precision highp int precision lowp sampler2D precision lowp samplerCube 0 CMPF ALWAYS FAIL, 1 CMPF ALWAYS PASS, 2 CMPF LESS, 3 CMPF LESS EQUAL, 4 CMPF EQUAL, 5 CMPF NOT EQUAL, 6 CMPF GREATER EQUAL, 7 CMPF GREATER bool Is Alpha Pass(int func,float alphaRef, float alphaValue) bool result true if (func 0) result false break if (func 1) result true break if (func 2) result alphaValue lt alphaRef break if (func 3) result alphaValue lt alphaRef break if (func 4) result alphaValue alphaRef break if (func 5) result alphaValue ! alphaRef break if (func 6) result alphaValue gt alphaRef break if (func 7) result alphaValue gt alphaRef break return result void FFP Alpha Test(in float func, in float alphaRef, in vec4 texel) if (!Is Alpha Pass(int(func), alphaRef, texel.a)) discard


Best way to render multiple objects I have a scene that consists of 1 player object, 1 platform, 1 enemy, and 1 background. Currently, this is how my render function looks like void Sprite Render() glUseProgram(m Program) glActiveTexture(GL TEXTURE0) Background glBindVertexArray(BackgroundVAO) glBindTexture(GL TEXTURE 2D, m Textures 1 ) glUniform1i(glGetUniformLocation(m Program, "Texture1"), 0) m ProjectionMatrix m Camera.ViewToWorldMatrix() m TransformationMatrix m ProjectionMatrix m TransformationMatrixLoc glGetUniformLocation(m Program, "TransformationMatrix") glUniformMatrix4fv(m TransformationMatrixLoc, 1, GL FALSE, amp m TransformationMatrix 0 0 ) glDrawElements(GL TRIANGLES, 6, GL UNSIGNED BYTE, 0) Enemy glBindVertexArray(EnemyVAO) glBindTexture(GL TEXTURE 2D, m Textures 2 ) glUniform1i(glGetUniformLocation(m Program, "Texture3"), 0) m ProjectionMatrix glm translate(glm mat4(), glm vec3(EnemyX, EnemyY, 0.0f)) m Camera.ViewToWorldMatrix() m TransformationMatrix m ProjectionMatrix m TransformationMatrixLoc glGetUniformLocation(m Program, "TransformationMatrix") glUniformMatrix4fv(m TransformationMatrixLoc, 1, GL FALSE, amp m TransformationMatrix 0 0 ) glDrawElements(GL TRIANGLES, 6, GL UNSIGNED BYTE, 0) Platform One glBindVertexArray(PlatformVAO) glBindTexture(GL TEXTURE 2D, m Textures 3 ) glUniform1i(glGetUniformLocation(m Program, "Texture4"), 0) m ProjectionMatrix glm translate(glm mat4(), glm vec3(0.0f, 0.5f, 0.0f)) m Camera.ViewToWorldMatrix() m TransformationMatrix m ProjectionMatrix m TransformationMatrixLoc glGetUniformLocation(m Program, "TransformationMatrix") glUniformMatrix4fv(m TransformationMatrixLoc, 1, GL FALSE, amp m TransformationMatrix 0 0 ) glDrawElements(GL TRIANGLES, 6, GL UNSIGNED BYTE, 0) Player glBindVertexArray(PlayerVAO) glBindTexture(GL TEXTURE 2D, m Textures 0 ) glUniform1i(glGetUniformLocation(m Program, "Texture2"), 0) m ProjectionMatrix glm translate(glm mat4(), glm vec3(PlayerX, PlayerY, 0.0f)) m Camera.ViewToWorldMatrix() m TransformationMatrix m ProjectionMatrix m TransformationMatrixLoc glGetUniformLocation(m Program, "TransformationMatrix") glUniformMatrix4fv(m TransformationMatrixLoc, 1, GL FALSE, amp m TransformationMatrix 0 0 ) glDrawElements(GL TRIANGLES, 6, GL UNSIGNED BYTE, 0) glBindTexture(GL TEXTURE 2D, 0) glBindVertexArray(0) As you can see, it is unnecessarily complicated. And if I want to draw, say, two or more enemies, or 4 or more platforms, then it'd get ridiculously large! My question is this, how can I make this smaller? I prefer to be able to do something like this in my main.cpp Sprite.Render(Player) Sprite.Render(EnemyOne) etc... Looking forward to reading your tips, thank you!


Resizing a Framebuffer Object (ie its attachments) on Screen Resize I have been experimenting with some post processing effects and I have been using FBOs to store stuff. The problem is, I attempt to resize them when I change resolution. I get no errors, however the image has been stretched so that I only see about the bottom left quarter of it on my screen. I have looked over the internet and and found issues such as not using glTexStorage because it is immutable, and being sure to call glViewport after binding a framebuffer. As far as I can see I'm not missing anything simple like that. Here are some (very dark) screen shots showing the issue Please excuse the horrible graphics. I am working on a bloom filter and these images only contain the bright bits so it looks dark and weird. My FBOs are initialised with a blank texture attached to GL COLOR ATTACHMENT0. Here is the rough pseudo code (in java). (my actual code is abstracted behind a game engine I'm writing) Generating texture Creates the texture this.id glGenTextures() glPixelStorei(GL UNPACK ALIGNMENT, 1) glBindTexture(GL TEXTURE 2D, this.id) glTexParameteri(GL TEXTURE 2D, GL TEXTURE WRAP S, GL CLAMP TO EDGE) glTexParameteri(GL TEXTURE 2D, GL TEXTURE WRAP T, GL CLAMP TO EDGE) Set up texture scaling glTexParameteri(GL TEXTURE 2D, GL TEXTURE MAG FILTER, magnification) glTexParameteri(GL TEXTURE 2D, GL TEXTURE MIN FILTER, minification) Filling it with data (data is a ByteBuffer filled with 0s) glTexImage2D(GL TEXTURE 2D, 0, colorMode, width, height, 0, GL RGBA, GL UNSIGNED BYTE, data) glGenerateMipmap(GL TEXTURE 2D) Binding the framebuffer glBindFramebuffer(GL FRAMEBUFFER, this.id) glViewport(0, 0, width, height) width and height taken from width and height of framebuffer texture Resizing the framebuffer stores new width and height to be used with glViewport this.width width this.height height resize renderbuffer if(renderbuffer ! 0) glBindRenderbuffer(GL RENDERBUFFER, renderbuffer) glRenderbufferStorage(GL RENDERBUFFER, GL DEPTH COMPONENT, width, height) glBindRenderbuffer(GL RENDERBUFFER, 0) glBindTexture(GL TEXTURE 2D, texture) glTexImage2D(GL TEXTURE 2D, 0, GL RGBA, width, height, 0, GL RGBA, GL UNSIGNED BYTE, data) glGenerateMipmap(GL TEXTURE 2D) do i need this? Thanks very much in advance if you can spot an issue with my code. Let me know if you need the full source as well. I have a couple of ideas for issues is it possible to resize the renderbuffer like that? do I have to re attach the textures after resizing them should i just re create the entire framebuffer renderbuffer textures instead of resizing them.


Opengl texture rendered as solid color,why? her is my vertex array and texture coordinate.. float POS 0.5, 0.5, 1.0, 0.5, 0.5, 1.0, 0.5,0.5, 1.0, 0.5,0.5, 1.0 float texCoords 0.0,0.0, 1.0,0.0, 1.0,1.0, 0.0,1.0 here is my texture creation stbi set flip vertically on load(1) openglTexBuff stbi load("lena.jpg", amp w, amp h, amp c,0) glGenTextures(1, amp TexID) glActiveTexture(GL TEXTURE0) glBindTexture(GL TEXTURE 2D,TexID) glTexImage2D(GL TEXTURE 2D,0,GL RGB,w,h,GL FALSE,GL RGB,GL UNSIGNED BYTE,openglTexBuff) glGenerateMipmap(GL TEXTURE 2D) glTexParameteri(GL TEXTURE 2D,GL TEXTURE WRAP S,GL REPEAT) glTexParameteri(GL TEXTURE 2D,GL TEXTURE WRAP T,GL REPEAT) glTexParameteri(GL TEXTURE 2D,GL TEXTURE MAG FILTER,GL NEAREST) glTexParameteri(GL TEXTURE 2D,GL TEXTURE MIN FILTER,GL NEAREST) glBindTexture(GL TEXTURE 2D,0) stbi image free(openglTexBuff) ' and these are my shaders shader vertex version 330 core layout(location 0) in vec4 positions layout(location 1) in vec2 texCoords uniform mat4 translation matrix inactive shader variables.. uniform mat4 rotation matrix mat4 model matrix mat4 projection matrix out vec4 pos out vec2 frag TexCoord void main() rotation matrix gl Position rotation matrix translation matrix positions translation matrix operated with POS vector.. pos positions frag TexCoord texCoords translation matrix shader fragment version 330 core layout(location 0) out vec4 color in vec4 pos in vec2 frag TexCoord rag TexCoord uniform float col uniform sampler2D a texture void main() col a texture color texture(a texture,frag TexCoord) when i use (solid)color instead of texture in shader..everything works fine but when i use shader it gives solid color instead of texture..It seems like my whole tex is super zoomed to output single color here is draw call glClear(GL COLOR BUFFER BIT GL DEPTH BUFFER BIT) box.shader.setUniformat4x4("translation matrix",translation) box.shader.setUniformat4x4("rotation matrix",rotation arr) box.shader.setUniform1f("col",1.0) glBindTexture(GL TEXTURE 2D,TexID) box.shader.setUniform1i("a texture",0) box.render() box.render void render() vertices.bind() indices.bind() shader.bind() glDrawElements(render As,vertices.getSize(),GL UNSIGNED INT,NULL) vertices.unbind() indices.unbind()


How can I calculate a terrain's normals? Im trying to implement basic lighting in Opengl 3 (a sun) with this tutorial http www.mbsoftworks.sk index.php?page tutorials amp series 1 amp tutorial 11 Im building a basic terrain and its working well. Now im trying to add normals, and I think its not working well Terrain in wireframe As you can see I dont think my normals are good. This is how I get them for(x 0 x lt this.m size.width 1 x ) for(y 0 y lt this.m size.height 1 y ) immutable uint indice1 y this.m size.width x immutable uint indice2 y this.m size.width (x 1) immutable uint indice3 (y 1) this.m size.width x immutable uint indice4 (y 1) this.m size.width x immutable uint indice5 y this.m size.width (x 1) immutable uint indice6 (y 1) this.m size.width (x 1) Vector3 v1 vertexes indice3 vertexes indice1 Vector3 v2 vertexes indice2 vertexes indice1 Vector3 normal v1.cross(v2) normal.normalize() normals indice1 normal indices indice1, indice2, indice3, indice4, indice5, indice6 I use this basic shader http ogldev.atspace.co.uk www tutorial18 tutorial18.html or in the link I posted at the top. Thanks.


How to implement "model quality" in OpenGL In many games, there is an option named "Model Quality", which ranges from Low to High. Low model quality simply removes a lot of vertices from the model, to make it faster, while High preserves the original model vertices (I think). So I'm wondering, how do I implement this in my game?


What to do with unused vertices? Imagine yourself a vertex array in OpenGL representing blocks in a platform game. But some vertices may be not used. The environment is dynamic, so there always some vertex may suddenly become invisible. What is the best way to make them not draw? Graphic cards are complicated and it's hard to predict what is best approach. Few best ways I can think of delete and move all vertices after deleted one to fill freed space (sounds extremely inefficient) set positions to 0 set transparency to maximum I could of course benchmark, but what on my computer works faster doesn't have to on other.


GL INVALID OPERATION in glGenerateMipmap(incomplete cube map) I'm trying to learn OpenGL and i'm using SOIL to load images. I have the following piece of code GLuint texID 0 bool loadCubeMap(const char baseFileName) glActiveTexture(GL TEXTURE0) glGenTextures(1, amp texID) glBindTexture(GL TEXTURE CUBE MAP, texID) const char suffixes "posx", "negx", "posy", "negy", "posz", "negz" GLuint targets GL TEXTURE CUBE MAP POSITIVE X, GL TEXTURE CUBE MAP NEGATIVE X, GL TEXTURE CUBE MAP POSITIVE Y, GL TEXTURE CUBE MAP NEGATIVE Y, GL TEXTURE CUBE MAP POSITIVE Z, GL TEXTURE CUBE MAP NEGATIVE Z for (int i 0 i lt 6 i ) int width, height std string fileName std string(baseFileName) " " suffixes i ".png" std cout lt lt "Loading " lt lt fileName lt lt std endl unsigned char image SOIL load image(fileName.c str(), amp width, amp height, 0, SOIL LOAD RGB) if (!image) std cerr lt lt FUNCTION lt lt " cannot load image " lt lt fileName lt lt " (" lt lt SOIL last result() lt lt ")" lt lt std endl return false glTexImage2D(GL TEXTURE 2D, 0, GL RGB, width, height, 0, GL RGB, GL UNSIGNED BYTE, image) SOIL free image data(image) glTexParameteri(GL TEXTURE CUBE MAP, GL TEXTURE MAG FILTER, GL LINEAR) glTexParameteri(GL TEXTURE CUBE MAP, GL TEXTURE MIN FILTER, GL LINEAR MIPMAP LINEAR) glTexParameteri(GL TEXTURE CUBE MAP, GL TEXTURE WRAP S, GL CLAMP TO EDGE) glTexParameteri(GL TEXTURE CUBE MAP, GL TEXTURE WRAP T, GL CLAMP TO EDGE) glTexParameteri(GL TEXTURE CUBE MAP, GL TEXTURE WRAP R, GL CLAMP TO EDGE) glGenerateMipmap(GL TEXTURE CUBE MAP) glBindTexture(GL TEXTURE CUBE MAP, 0) return true When i call this, the images load successfully, but then i get an error in console OGL DEBUG message lt 1 gt 'API' reported 'Error' with 'High' severity GL INVALID OPERATION in glGenerateMipmap(incomplete cube map) BACKTRACE and no cubemap is displaying at all. Do you see any mistake in this code?


OpenGL Calculate Matrices Im trying to switch from the glTranslate etc to my own Matrices, but for some reason it does not work. Here are my 2 functions to create the view and projection matrix public Matrix4f getViewMatrix() Matrix4f viewMatrix new Matrix4f() viewMatrix.setIdentity() viewMatrix.translate(game.player.position) viewMatrix.rotate(game.player.rotation.x, new Vector3f(1.0f, 0.0f, 0.0f)) viewMatrix.rotate(game.player.rotation.y, new Vector3f(0.0f, 1.0f, 0.0f)) viewMatrix.rotate(game.player.rotation.z, new Vector3f(0.0f, 0.0f, 1.0f)) System.out.println(viewMatrix) return viewMatrix public Matrix4f getProjectionMatrix() FloatBuffer projectionBuffer BufferUtils.createFloatBuffer(16) GL11.glGetFloat(GL MODELVIEW MATRIX, projectionBuffer) Matrix4f projectionMatrix new Matrix4f() projectionMatrix.load(projectionBuffer) return projectionMatrix I send those 2 matrices to the Vertex shader with a uniform, and use gl Position view matrix proj matrix vec4(in position, 1.0) Where in position is the coordinate of the vertex. I do see some things on the screen, but it's very, very buggy, and nothing is right about it. If I use the build in gl ModelViewProjectionMatrix in the shader and use glTranslate and glRotate in OpenGL, it works perfectly fine. What am I doing wrong here? Here is the output of me view projection together with the camera position 0.5095141 0.0 0.8604623 1.1625774 0.7321221 0.52541286 0.43351877 16.980185 0.45209795 0.8508474 0.26770526 0.8665553 0.0 0.0 0.0 1.0 Vector3f 1.1625774, 16.980185, 0.8665553


What input and window handler should I learn for complement OpenGL? I have a good base in C programming and I did some 2D games using SDL. Now I want to start making 3D games, but as much as posible, I want to learn following the standars of the profesional industry. I think learning openGL I will have more acuratte skills for programming 3D graphics, so I prefer to study openGL instead of a game engine. But my cuestion is, what library I should choice for complement openGL in the area of the input and windows handler, if posible, following the standars of the industry? Thanks you in advance for the help! (And sorry for my bad english)


Point Light shows black box rect (PointLight not working) libgdx 3D I am creating a 3d scene currently a box and rect, and trying to enable lighting. When i create a PointLight and add it to Environment everything turns to black color? all i want to do is create a 3d scene and enable point light, like a sun or rays coming from a point and shading the objects. Code environment new Environment() environment.add(new PointLight().set(1f, 1f, 1f, 0, 0, 20f, 100f)) modelBatch new ModelBatch() .. square new ModelBuilder().createBox(300,300,300,new Material(ColorAttribute.createDiffuse(Color.GREEN)), VertexAttributes.Usage.Position VertexAttributes.Usage.Normal) squareinst new ModelInstance(square) squareinst.transform.setTranslation( 500,0,0) sprites.get(0).setRotationY(sprites.get(0).getRotationY() 1f) sprites.get(1).setRotationY(sprites.get(1).getRotationY() 1f) squareinst.transform.rotate(1,0,0,1) modelBatch.begin(camera) for(Sprite3D sp sprites) has 3d rect models sp.draw(modelBatch,environment) modelBatch.render(squareinst,environment) modelBatch.end() PointLight turning everything black Without using environment or lights as per my investigation, here if pointlight is not working then everything should be black as currently, because the environment needs light, it works fine with Directional light (only the backface of rect is black even after rotations, i don't know why) libgdx version 1.6.1 android studio i checked it on both android device and desktop please i really need to get this PointLight working, i don't know if it will take a custom shader, if so please guide me to some links because i am not experienced in shaders. I also read about PointLight not working on some device or not working in opengl 2.0 enabled, but i am not sure.


handling buffers in OpenGL I'm reading through the OpenGL documentation for version 3.3 core. I'm having issues understanding proper buffer deletion. At the moment I have an object that loads itself into OpenGL memory in the constructor and only exposes a VAO with the attribute pointers and a bound element array ready for rendering. When it stops existing it deletes all the buffers and sets pointers to NULL. How do I properly delete OpenGL data? I'm going to assume that the object doesn't stop existing while it's being rendered. Do I have to do something more than just delete the VAO and then delete the buffer objects? Does that leave anything out? Should I bind the VAO disable the attributes, unbind it and then delete it?


Can I directly pass a Boost ptr vector list to glBufferData? I have a data structure like this typedef struct vertex float x float y float z float s float t vertex Then I add to a list called boost ptr vector lt vector gt vertices Is there a way to use vertices to provide the parameters for glBufferData?


Do I have to take aspect ratio into account, when computing a direction in View Space? I read an article about implementing a Single Pass Volume Renderer. After thinking about it, I have a question, which concerns the provided GLSL code snippet of the Fragment Shader. To calculate the ray direction, the author uses the FocalLength (distance of the projection plane from view point) as Z component, and the fragment coordinates in NDC space as xy component. This gives a vector pointing from the view point to the pixel on the projection plane which is computed. Obviously this direction is supposed to be in View Space, because it assumes 0,0,0 as view point and the ModelView Matrix is used to convert the direction to object local space. But I am not sure if that is correct, because isn't it that in view space the projection window isn't necessarily normalized, but has a width of twice the aspect ratio? It gets normalized by applying the projection matrix (at least in Direct3D as far as i know). So if this is true, why does this work? Why he maps the x component of gl FragCoord to 1 1 , when the leftmost pixel would have an x coordinate of aspectRatio in view space?


JOGL hardware based shadow mapping computing the texture matrix I am implementing hardware shadow mapping as described here. I've rendered the scene successfully from the light POV, and loaded the depth buffer of the scene into a texture. This texture has correctly been loaded I check this by rendering a small thumbnail, as you can see in the screenshot below, upper left corner. The depth of the scene appears to be correct objects further away are darker, and that are closer to the light are lighter. However, I run into trouble while rendering the scene from the camera's point of view using the depth texture the texture on the polygons in the scene is rendered in a weird, nondeterministic fashion, as shown in the screenshot. I believe I am making an error while computing the texture transformation matrix, but I am unsure where exactly. Since I have no matrix utilities in JOGL other then the gl Load Mult Matrix procedures, I multiply the matrices using them, like this void calcTextureMatrix() glPushMatrix() glLoadIdentity() glLoadMatrixf(biasmatrix, 0) glMultMatrixf(lightprojmatrix, 0) glMultMatrixf(lightviewmatrix, 0) glGetFloatv(GL MODELVIEW MATRIX, shadowtexmatrix, 0) glPopMatrix() I obtained these matrices by using the glOrtho and gluLookAt procedures glLoadIdentity() val wdt width 45 val hgt height 45 glOrtho(wdt, wdt, hgt, hgt, 45.0, 45.0) glGetFloatv(GL MODELVIEW MATRIX, lightprojmatrix, 0) glLoadIdentity() glu.gluLookAt( xlook lightpos. 1, ylook lightpos. 2, lightpos. 3, xlook, ylook, 0.0f, 0.f, 0.f, 1.0f) glGetFloatv(GL MODELVIEW MATRIX, lightviewmatrix, 0) My bias matrix is float biasmatrix new float 16 0.5f, 0.f, 0.f, 0.f, 0.f, 0.5f, 0.f, 0.f, 0.f, 0.f, 0.5f, 0.f, 0.5f, 0.5f, 0.5f, 1.f After applying the camera projection and view matrices, I do glTexGeni(GL S, GL TEXTURE GEN MODE, GL EYE LINEAR) glTexGenfv(GL S, GL EYE PLANE, shadowtexmatrix, 0) glEnable(GL TEXTURE GEN S) for each component. Does anybody know why the texture is not being rendered correctly? Thank you.


how to use glm rotate with a eulerangle? I have a vec3 to represent my object's orientation rotation but the glm rotate method expects a quaternion. If I just convert it to a quaternion like this glm quat rot rotation The W value will just be zero, right? And then there won't be any changes in rotation. In my code I just want to be able to do rotation.x 5.0f in the update method of an object. This is the method I'm using for my transformations glm mat4 GameObject Transform(glm mat4 model, glm vec3 position, glm vec3 scale, glm quat angleAxis) model glm translate(model, position) if (angleAxis.w gt 360.0f) angleAxis.w 360.0f else if (angleAxis.w lt 0.0f) angleAxis.w 360.0f model glm rotate(model, angleAxis.w toRadians, glm vec3(angleAxis.x, angleAxis.y, angleAxis.z)) model glm scale(model, scale) return model Currently I'm just passing on that rotation vec3 to that angleAxis quaternion parameter but that obviously doesn't work. This is how i currently calculate my front, up, and right vectors void GameObject calculateCameraView() front.x cos(glm radians(rotation.x)) cos(glm radians(rotation.y)) front.y sin(glm radians(rotation.y)) front.z sin(glm radians(rotation.x)) cos(glm radians(rotation.y)) front glm normalize(front) right glm normalize(glm cross(front, worldUp)) up glm normalize(glm cross(right, front)) front.y invertMouse ? front.y 1 front.y


Accessing uniform variables from a Cg shader in OpenGL I am trying to implement a simple PC program with OpenGL, using mandatorily Cg shaders (no Unity whatsoever). I have found some tips on this page http bobobobo.wordpress.com 2008 10 05 cg 1 and kept the Cgprogram, Cgcontext and Cgprofile types in my own project. Problem is How can you access uniform variables in the C code? I have tried the glGetUniformLocation way, but that won't work because the first parameter must be the program's ID of GLuint type and I have CGprogram type. I have already searched by myself (including the Nvidia Cg 'tutorial') but I can't seem to find both Cg and OpenGL discussed on a page without having to deal with Unity. edit I can now access the variables, but in my case I'm trying to change a texture, and it doesn't bind.


Correct way to calculate Perspective Matrix I have seen at least 3 different ways to calculate the perspective matrix and I'm confused as to which one I should be using and what the differences are? OpenGL says to do it this way f cotangent(fov 0.5) f aspect, 0, 0, 0 0, f, 0, 0 0, 0, (far near) (near far), (2 far near) (near far) 0, 0, 1, 0 glm does it this way range tan(fov 0.5) near left range aspect right range aspect bottom range top range (2 near) (right left), 0, 0, 0 0, (2 near) (top bottom), 0, 0 0, 0, (far near) (far near), 1 0, 0, (2 far near) (far near), 0


How to adjust position relative to resolutions? I have a lot of objects on the screen and would like at different resolutions, object's positions rendered correctly on the screen irrespective of the resolution. Is it correct to multiply the position by aspect ratio ?


OpenGL Updating VAO array buffer range I am trying to stream data to a buffer which I have bound to a VAO vertex buffer binding point that I want to access through vertex attributes in the shader. Usually I stream to buffers which I have bound as GL UNIFORM BUFFERs and I do it like this create an immutable data storage glNamedBufferStorage(uboID, capacity, data, GL MAP WRITE BIT GL MAP PERSISTENT BIT GL MAP COHERENT BIT) map entire storage forever mappedPtr glMapNamedBufferRange(uboID, 0, capacity, GL MAP WRITE BIT GL MAP PERSISTENT BIT GL MAP COHERENT BIT) bind buffer to target(GL UNIFORM BUFFER) binding point glBindBufferBase(GL UNIFORM BUFFER, uboBinding, uboID) bind shader interface block to target binding point glUniformBlockBinding(shaderProgramID, blockIndex, uboBinding) Now the uniform block can be accessed in the shader program and i can stream to it like so copy data to mapped pointer at stream offset memcpy(mappedPtr uploadOffset, amp uploadData 0 , uploadSize) This is the important part tell the shader which range of the buffer to use glBindBufferRange(GL UNIFORM BUFFER, uboBinding, uboID, uploadOffset, uploadSize) increment offset uploadOffset uploadSize If I bind a buffer to a VAO and access its data as vertex attributes in the shader, I don t know how to give the shader the range in which the updated data can be found. I can give an offset when binding a buffer to a VAO when calling glVertexArrayVertexBuffer, but it has a few more parameters and does not seem like the right thing to call every frame. I have not gotten it to work with it, too. Is there something like glBindBufferRange for vertex buffers bound to VAOs?


Why do I see spaces between polygons in OpenGL, only on an Nvidia 720M? I'm developing an OpenGL application that renders .obj 3D models. I use VBOs to render the polygons. Using the same code, the loaded models appear fine on all PCs, except on my Nvidia 720M. My laptop sports an Intel HD 4000 embedded graphics GPU, and an Nvidia 720M. When I use the Intel GPU, it looks fine, but when I load it on the Nvidia 720M, spaces appear around polygons like so On Nvidia 720M GPU On everything else No other 3D application that runs on the Nvidia 720M GPU has the same issue. I am using the latest drivers. Is this a problem with my application? How can I fix it?


Rendering two textures with blending and alpha test What I am looking for is the following I have a circle on a square image, alpha is 0 at the corners and also a square shadow, alpha is 0 everywhere else I would like to have as final result a blending of these two renders, plus the shadow not being rendered outside the circle How could I achieve that?


Octree Frustrum Culling times came when i had to implement some culling into my engine. I started by reading some stuff and so far so good. I managed to create an octree which can effectivly divide my geometry's vertices (per mesh) into an octree. But here i have some Questions Currently i am using immediate mode to test if the culling works. And it does work, i am recursivly traversing the tree's nodes and testing against the node's bounding box if the frustum intersects with it. Repeat untill leaf is found and render that leaf's geometry (with immediate mode for testing) But now i would like to use VBO VAO's to render the geometry in the leaves and here i see two options 1.Each time the i traverse the tree push the leaves that intersect with the frustrum into a list then get the vertices out of them and construct a VBO and send it to be rendered. 2.Pre build a VBO for each leaf then just rebind for each visible leaf and render. Anyway, which is the better option rebuilding a new vbo each time the frustum changes, or just rebinding multiple vbos (which is also expensive). Also is this even the right approach , maybe i am missing something. bool view Culling(CFrustum amp frusrum, COctree node) if (!node) return false if (frusrum.CubeInFrustum(node gt GetCenter().x, node gt GetCenter().y, node gt GetCenter().z,(node gt GetWidth() 2.0f))) if (node gt IsSubDivided()) view Culling(frusrum, node gt OctreeNodes() TOP LEFT FRONT ) view Culling(frusrum, node gt OctreeNodes() TOP LEFT BACK ) view Culling(frusrum, node gt OctreeNodes() TOP RIGHT BACK ) view Culling(frusrum, node gt OctreeNodes() TOP RIGHT FRONT ) view Culling(frusrum, node gt OctreeNodes() BOTTOM LEFT FRONT ) view Culling(frusrum, node gt OctreeNodes() BOTTOM LEFT BACK ) view Culling(frusrum, node gt OctreeNodes() BOTTOM RIGHT BACK ) view Culling(frusrum, node gt OctreeNodes() BOTTOM RIGHT FRONT ) else use prebuilded vbo here or push these vertices here in a list later build a dynamic vbo from them node gt DrawOctree(node) return true return false


multiply matrix4x4 with vec4 I'm developing a game and I'd like to make model pos4 calc (that's usual in glsl vertex shader) in cpu instead of doing it in gpu. I'm using LWJGL and for the math impl I use JOML. Anyone know how to multiply a vec4 with a matrix 4x4? It would be nice showing me the JOML code but also the way to mul the mat values with the vec4 values is fine!


Dynamic VBO update possibly corrupting data? I want to draw a line between two vertices. On a mouseclick the vertex data will change and I want to update the line to use the new values. I am using a VBO for this and it looks like the update process is somehow corrupting the VBO data. The line is not drawing in a direction that I would expect given the values of the vertices. There are four lines in total and I am updating only the last two vertices. The vertex data is initialized as float vertLineBuffer 1.0f,0.0f,0.0f, right 0.0f,1.0f,0.0f, top 0.0f,0.0f,0.0f, center 1.0f,0.0f,0.0f, START 0.0f, 1.0f,0.0f END The init routine public void setLineVBOs(GL4 gl) throws Exception vboLineHandles new int 2 gl.glGenBuffers(2, vboLineHandles, 0) populate the position buffer FloatBuffer fbData Buffers.newDirectFloatBuffer(vertLineBuffer) gl.glBindBuffer(GL4.GL ARRAY BUFFER, vboLineHandles VERTICES LINE IDX ) the vertex data gl.glBufferData(GL4.GL ARRAY BUFFER, fbData.capacity() 4, fbData, GL4.GL STATIC DRAW) fbData.clear() don't need this anymore populate the color buffer FloatBuffer fbColor Buffers.newDirectFloatBuffer(vertLineColor) gl.glBindBuffer(GL4.GL ARRAY BUFFER, vboLineHandles VERTICES LINECOLOR IDX ) the vertex data gl.glBufferData(GL4.GL ARRAY BUFFER, fbColor.capacity() 4, fbColor, GL4.GL STATIC DRAW) fbColor.clear() don't need this anymore set vertex array index IntBuffer intBuffer BufferUtil.newIntBuffer(1) gl.glGenVertexArrays(1, intBuffer) iLineVao intBuffer.get(0) gl.glBindVertexArray(iLineVao) gl.glEnableVertexAttribArray(VERTICES LINE IDX) gl.glEnableVertexAttribArray(VERTICES LINECOLOR IDX) gl.glBindBuffer(GL4.GL ARRAY BUFFER, vboLineHandles VERTICES LINE IDX ) the vertex data Associate Vertex attribute 1 with the last bound VBO gl.glVertexAttribPointer(0,3, GL2ES2.GL FLOAT, false,0,0) color gl.glBindBuffer(GL4.GL ARRAY BUFFER, vboLineHandles VERTICES LINECOLOR IDX ) the vertex data gl.glVertexAttribPointer(1,3, GL2ES2.GL FLOAT, false,0,0) And then I attempt to update the VBO on an event (mouseclick) like this public void updateLine(GL4 gl, float pos) pos contains the new vertex data vertLineBuffer 9 pos 0 vertLineBuffer 10 pos 1 vertLineBuffer 11 pos 2 vertLineBuffer 12 pos 3 vertLineBuffer 13 pos 4 vertLineBuffer 14 pos 5 FloatBuffer fbData Buffers.newDirectFloatBuffer(vertLineBuffer) gl.glBufferSubData(GL4.GL ARRAY BUFFER, 0, fbData.capacity() 4, fbData) gl.glBindBuffer(GL4.GL ARRAY BUFFER, vboLineHandles VERTICES LINE IDX ) fbData.clear() The vertex shader version 430 layout (location 0) in vec3 vertexPosition layout (location 1) in vec3 vertexColor out vec3 Color void main(void) Color vertexColor gl Position vec4(vertexPosition, 1.0) The frag shader version 430 in vec3 Color layout (location 0) out vec4 FragColor void main(void) FragColor vec4(Color, 1.0) Does this look right? Can anyone see where this might damage the contents of the VBO?


Correct Rotation and Translation with a 4x4 matrix I am using a 4x4 matrix to transform verts in a shader. I multiply an identity matrix by a rotation matrix by a translation matrix. I am trying to first rotate the verts and then translate them, however in my result, it appears that the verts are being transformed and then rotated. My matrix looks something like this m00 m01 m02 tx m10 m11 m12 ty m20 m21 m22 tz 1 I am not using OpenGL's fixed function pipeline, I am multiplying matrices on the client side, and uploading the matrix to a GLSL shader. If it helps, I am using my own matrix multiplication code, but I have recreated this problem using matrices on my graphing calculator, so I don't believe my matrix code has errors.. I'll include a visual aid if needed.


Tessellation won't render I am starting to work with tessellation and have some problems right in the beginning. I try to render a quad made of two triangles with tessellation, but nothing appears on the screen. But as soon as I remove the tessellation shaders and change GL PATCHES to GL TRIANGLESagain, it starts working again, without tessellation obviously. So here is my code to setup the tessellation shaders glPatchParameteri(GL PATCH VERTICES, 3) shaderID glCreateProgram() vertex GraphicsUtilities loadShader("D vert.glsl", GL VERTEX SHADER) glAttachShader(shaderID, vertex) fragment GraphicsUtilities loadShader("D frag.glsl", GL FRAGMENT SHADER) glAttachShader(shaderID, fragment) tcs GraphicsUtilities loadShader("D tcs.glsl", GL TESS CONTROL SHADER) glAttachShader(shaderID, tcs) tes GraphicsUtilities loadShader("D tes.glsl", GL TESS EVALUATION SHADER) glAttachShader(shaderID, tes) glLinkProgram(shaderID) This is the vertex shader version 400 layout(location 0) in vec4 vertPosition layout(location 1) in vec2 vertUV layout(location 2) in vec3 vertNormal void main(void) gl Position vertPosition The TCS version 400 layout (vertices 3) out void main() gl out gl InvocationID .gl Position gl in gl InvocationID .gl Position gl TessLevelOuter 0 3.0 gl TessLevelOuter 1 3.0 gl TessLevelOuter 2 3.0 gl TessLevelInner 0 3.0 And the TES version 400 layout(triangles, equal spacing, cw) in void main() gl Position (gl TessCoord.x gl in 0 .gl Position gl TessCoord.y gl in 1 .gl Position gl TessCoord.z gl in 2 .gl Position) And this is how I draw the quad glPolygonMode( GL FRONT AND BACK, GL LINE ) glUseProgram(shaderID) glBindVertexArray(quad gt getVboID()) glDrawElements(GL PATCHES, 6, GL UNSIGNED INT, (GLvoid )0) glBindVertexArray(0) glUseProgram(0) glPolygonMode( GL FRONT AND BACK, GL FILL ) I tried using in and out variables instead of gl in out, but that doesn't work either. I also tried it without the TCS. I was also using Apitrace to look up any errors, but nothing. The function loadShader() looks for compile errors. So what could cause this problem? I really have no idea how to debug this thing any further.


OpenGL shader program per shape or model I have a program which imports models from .obj files and then draws them with OpenGL. I have a model which contains many shapes (meshes?). Not every shape has texcoords defined inside .obj file (it looks like 1 1 instead of 1 1 1) and I try to use one shader program which depends on texcoords. What would be the best solution for that problem? Should I use separate programs for shapes that have texcoords and another for shape without texcoords defined? Maybe there is a way to check if some attributes were passed to shader program? This is the gist with .obj, .mtl and shader files, maybe that will help you to understand my problem.


C from LWJGL to C with OpenGL I've been trying my best on porting my 3D game from Java to C , but to no avail. I use only LWJGL with OpenGL but I cannot find any other library in C that supports as much as LWJGL does for Java. Especially on the math part. For instance. I'm trying to port this TransformationMatrix maker to C . public static Matrix4f createTransformMatrix(Vector3f translation, float rx, float ry, float rz, float scale) Matrix4f newMatrix new Matrix4f() newMatrix.setIdentity() Matrix4f.translate(translation, newMatrix, newMatrix) Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), newMatrix, newMatrix) Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0), newMatrix, newMatrix) Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0,0,1), newMatrix, newMatrix) Matrix4f.scale(new Vector3f(scale,scale,scale), newMatrix, newMatrix) return newMatrix I've tried using Eigen and GLM, but none of them work the same like LWJGL. Now I wouldn't mind this, but the lack of actual 3D tutorials on OpenGL in C is just abysmal. Any tips or help with even converting this piece of code would be greatly appreciated.


Versions of GL and its device that don't display or required powers of 2 for the sprites From this question aside from identifying possibilities of displaying images that don't needed to require powers of 2, what are the versions of GL that can actually display images even if don't needed the power of 2 size?


Game (X Plane) boot startup time performance I use X Plane for my question but it also concerns probably every other flight simulator or simulation game in general. When developing a plugin what bothers me most is the startup time of the application to test my plugin functionality so I was wondering how I can improve the startup speed of the simulator. First I removed all additional scenery and reduced the loaded files to a minimum which gave me a startup time of 34 seconds which is quite fast already. To improve the time even further I thought it would make sense to run the whole application from memory and I installed ubuntu 64 bit and created a 2GB tempfs filesystem in memory (ram disk). When starting x plane from this memory file system it still takes 30 seconds. Can anyone explain what the application does during startup which needs so much processing time? I assume that the graphic bitmaps for the object and the environment are compressed on disk and therefore they have to be decompressed in memory first before they can be used in opengl. This would explain the time spent on startup. If it is true that the bitmaps need to be decompressed first would it be possible to improve the time by using multiple cores? If the application is multithreaded and there are four cores would the time be divided by four or does this processing happen on the GPU? Any explanation which helps me to better understand the startup process of a computer game is really appreciated because I'm interested in improving the overall performance of the system and therefore I need a better understanding of the bottlenecks (RAM, CPU, GPU, Disks (SSD Raid), OS, libraries, ...).


Inter Quake Model IQM render Directx9 I'm trying to render an Inter Quake Model(http lee.fov120.com iqm ) in DirectX9 that I exported from blender. I want to display animations which IQM supports and my model format does not. The model is a cylinder. It loads fine in the iqm sdk opengl viewer but when i try to render it in directx9 using for example(this is just to render the vertices) IDirect3DDevice9 device HRESULT hr S OK for(int i 0 i lt nummeshes i ) iqmmesh amp m meshes 0 hr device gt DrawIndexedPrimitiveUP(D3DPT TRIANGLELIST, 0, 3 m.num triangles, m.num triangles , amp tris m.first triangle ,D3DFMT INDEX32 ,inposition ,sizeof(unsigned int)) It renders like this Incorrect The light grey bit that looks like two triangles in the middle is what is rendered(ignore the other stuff). Whereas it is meant to look like this(using a custom importer which I designed which matches what is displayed in blender) Correct Anyone have any suggestions on what might be going wrong?


clip space, normalized device coordinate space and window space in OpenGL I am learning OpenGL. Clip space, normalized device coordinate space and window space are confusing. I searched but still don't understand them clearly. So, the question is what are differences between them and how are they converted from one to another? And what coordinate do the built in OpenGL functions (e.g. glBufferData) take as input?


Everything turning black when pitching down Just a quick questions about something that's occurring in my world. Every time I pitch my camera downward, everything starts turning black, and if I pitch upward, everything sort of intensifies. I'm multiplying my normals by the normal matrix in the shader, and I'm multiplying my lights direction by the model view matrix. If I leave the normal and light dir in world space everything ends up fine. I thought putting them both in view space would not cause those weird things to happen?


How can i draw a curve in modern Opengl? OpenGl is capable of rendering points, lines, triangles and quads but what if i want to draw a bezier curve? I read online you should use something called GL STRIP, but the solutions were using either legacy Opengl, or they were not explaining well the process. The question is How can i render bezier curves in Modern Opengl? I'm using C .


A little bit confused on how to set normals in this case I'm learning how to use VBOs and I'm following up on the tutorial at the bottom of this page. So I went ahead and created a structure Vertex to hold vertex data.(coordinates and normals). struct Vertex GLfloat x, y, z GLfloat nx, ny, nz GLfloat r, g, b GLfloat padding 7 For the moment I'm trying to draw a cube.So I created an array with 8 vertices. My question is how do I set the normals? When I used immediate rendering, I would just do a glNormal3f and proceeded to draw the vertices for that face. Now that the normals are defined on a per vertex basis, and a vertex practically belongs to 3 faces, I'm somewhat confused as what I should do here. Have I taken a wrong approach on making that structure, or I am missing something else. I would also like to note that I want to make something more generic, so I don't want it to be limited to just drawing cubes. Thanks.


How Extract Frustum Planes from Clip Coordinates? I'm having some problems with my Frustum Culling and I want to debug it, so I'm trying to render it's planes, to see exatly the Frustum. But I'm using the Clip Coordinates to do the culling (like OpenGL pipeline do), but I dont know how to render a frustum, in another words, I dont know how to convert a frustum in Clip Coordinates to a "Frustum Mesh". Actually to calculate the frustum I use this function glm vec3 point MVP glm vec4( radius, radius, radius, 1.0f)) leftTopPoint return (point.x gt point.w) amp amp Inside left clipping pane (point.x lt point.w) amp amp Inside right clipping pane (point.y gt point.w) amp amp Inside bottom clipping pane (point.y lt point.w) amp amp Inside top clipping pane (point.z gt point.w) amp amp Inside near clipping pane (point.z lt point.w) Inside far clipping pane Where MVP is a glm mat4 of Projection View Model matrices. This function is activated only when I press the left click of mouse, so I want to render the Frustum and see how it is. Also I dont use a "lookAt" function to rotate the camera, I'm using Quaternions (dont know if that matters). Sorry if it is a bit confusing, it's hard to explain. So I just need a tip or a orientation example of how achive this. Thanks for your attention.


How to draw textured tile map in opengl I am trying to create a textured hexagonal tile map in opengl. I have the VBO and respective index buffer. Additionally I have a texture atlas for texturing individual tiles. I'm attempting to create a distinct texture for each hex without mixing the textures. I understood that one should use a pair of (U,V) texture coordinates for each vertex. Now if the tile map would not be indexed and have the overlapping vertices, I could just set the texture coordinates for each vertex and get each hex rendering the correct texture. However, with indexing the overlapping vertices are gone and I can only set single pair of texture coordinates for each vertex which results in the textures mixing inside the hexes. Is there a way to texture tiles with indexing or another alternative approach to creating hex maps with different textures?


Simple GLSL example to render a 2d textured quad? I would really love to add shader support in my game , although i can't seem to find a SIMPLE example on how to setup opengl for using shaders. So i would like to ask Does anyone knows if there are any SIMPLE examples for beginners ? (ie Rendering a simple 2d quad or something like that)


OpenGl Error, The loaded object takes the same colors and style of the Texture? I'm new to OpenGl Faced this problem Draw function void Renderer Draw() glUseProgram(programID) shader.UseProgram() mat4 view mat4(mat3(myCamera gt GetViewMatrix())) glm mat4 VP myCamera gt GetProjectionMatrix() myCamera gt GetViewMatrix() shader.BindVPMatrix( amp VP 0 0 ) glm mat4 VP2 myCamera gt GetProjectionMatrix() myCamera gt GetViewMatrix() floorM model13D gt Render( amp shader, scale(100.0f, 100.0f, 100.0f)) scaling the skybox t2 gt Bind() model3D gt Render( amp shader, scale(2.0f, 2.0f, 2.0f)) scaling aircraft glUniformMatrix4fv(VPID, 1, GL FALSE, amp VP2 0 0 ) mySquare gt Draw() The code of loaded shader.LoadProgram() model3D new Model3D() model3D gt LoadFromFile("data models obj Galaxy galaxy.obj", true) model3D gt Initialize() myCamera gt SetPerspectiveProjection(90.0f, 4.0f 3.0f, 0.1f, 10000000.0f) model13D new Model3D() model13D gt LoadFromFile("data models obj skybox Skybox.obj", true) model13D gt Initialize() Projection matrix shader.LoadProgram() View matrix myCamera gt Reset( 0.0f, 0.0f, 5.0f, Camera Position 0.0f, 0.0f, 0.0f, Look at Point 0.0f, 1.0f, 0.0f Up Vector ) std string Images names 6 Images names 0 "right.png" Images names 1 "left.png" Images names 2 "top.png" Images names 3 "bottom.png" Images names 4 "back.png" Images names 5 "front.png" t new Texture(Images names, 0) t2 new Texture("arrakisday dn.tga", 1)


Why is the light following my camera around? I have implemented a simple Phong shader without specular highlights for now (just ambient diffuse components) The problem however, is that the calculations seem to be done in camera space as I move the camera around, the light source seems to move along with it. This is evident by me not being able to see the dark side of the models (Note Image is a gif, if it is not animating, open in a new tab) My light is a point light, that I would like to have fixed somewhere in the world. It has a defined position. To my shader, I also pass in the M, V, P matrices, as well as the normal matrix, which is the inverse transpose of the MV matrix cameraPosition glm vec3(8,8,8) cameraTarget glm vec3(0,0,0) cameraUp glm vec3(0,0,1) glm vec3 cameraDirection glm normalize(cameraPosition cameraTarget) cameraRight glm cross(cameraDirection, cameraUp) view glm lookAt(cameraPosition, cameraTarget, cameraUp) glm mat4 model view view modelMatrix glm mat4 normal matrix glm transpose(glm inverse(model view)) The following is my shader code attribute vec3 vertex position attribute vec3 vertex colour in attribute vec3 vertex normal uniform mat4 model uniform mat4 view uniform mat4 projection uniform mat4 normal matrix uniform vec3 ambient light colour in uniform vec3 light position in varying vec4 fragment colour void main(void) position gl Position projection view model vec4(vertex position, 1.0) ambient colour vec3 ambient colour ambient light colour in vertex colour in diffuse colour vec3 normal normalize(vec3(normal matrix vec4(vertex normal, 0.0))) vec4 pos4 view model vec4(vertex position, 1.0) vec4 lightPos4 vec4(light position in, 1.0) vec3 lightDirection normalize((lightPos4 pos4).xyz) vec3 diffuse colour vertex colour in max(0.0, dot(normal, lightDirection)) fragment colour.rgb ambient colour diffuse colour As far as I understand, the problem is that these lighting calculations are done in Camera space, and hence change when the camera changes position. So, my question is How would I change that to get the light to be at a fixed position, ie do the light calculations in World space


glGenArrays This functionality is not available Whenever I call glGenVertexArrays(), I get the following exception Exception in thread "main" java.lang.IllegalStateException This functionality is not available. at org.lwjgl.system.Checks.checkFunctionality(Checks.java 36) at org.lwjgl.opengl.GL30.getInstance(GL30.java 651) at org.lwjgl.opengl.GL30.nglGenVertexArrays(GL30.java 3101) at org.lwjgl.opengl.GL30.glGenVertexArrays(GL30.java 3128) at me.package.name.ClassName.methodName(ClassName.java ANY LINE NUMBER) The operating system is OS X Yosemite 10.10.2, Java 7. I think that this problem is OS X specific. Immediate mode drawing does work. I am using LWJGL 3.