JOGL Hardware Shadow Mapping Transparent Shadow Texture I'm using hardware shadow mapping on JOGL based on the demo(HardwareShadowMapping) supplied by the distribution. After generating the shadow texture from lights point of view, I apply it to my scene with no problems. What I'm looking for is soft shadows instead of pitch black shadows. Is there any way that I can change the alpha values while applying the shadow depth texture? Btw I'm not an expert on OpenGL especially about custom shaders and I don't want to spend more time on understanding and developing custom shaders instead of the game. Here's a screenshot of the application in case you come up with another solution to what I'm trying to achieve. The game is actually a hack amp slash RTS hybrid.Here's the pseudo code of the gl event listener attached to shadow pbuffer. gl.glClear(GL.GL COLOR BUFFER BIT GL.GL DEPTH BUFFER BIT) gl.glPolygonOffset(polygonOffsetFactor, polygonOffsetUnits) gl.glEnable(GL.GL POLYGON OFFSET FILL) render shadow casting geometry gl.glDisable(GL.GL POLYGON OFFSET FILL) gl.glBindTexture(GL.GL TEXTURE 2D, lightViewTextureID) gl.glCopyTexSubImage2D(GL.GL TEXTURE 2D, 0, 0, 0, 0, 0, textureSize, textureSize) I sense here a way of updating alpha values of this texture


How can I render a JBox2D ParticleGroup? I want to render a ParticleGroup from JBox2d using OpenGL. I've managed to define a particle group area, but I'm unsure how to draw the individual particles. Here's how I create the ParticleGroup m world.setParticleRadius(0.15f) m world.setParticleDamping(0.2f) PolygonShape shape new PolygonShape() shape.setAsBox(8, 10, new Vec2( 12, 10.1f), 0) ParticleGroupDef pd new ParticleGroupDef() pd.shape shape m world.createParticleGroup(pd) This is how I draw a normal Square (which I don't know how to apply to groups of particles) public void draw(GLAutoDrawable gLDrawable, Vec3 position, float angle) gLDrawable.getGL().getGL2().glEnable(GL.GL BLEND) gLDrawable.getGL().getGL2().glEnable(GL.GL TEXTURE 2D) gLDrawable.getGL().getGL2().glBlendFunc(GL.GL SRC ALPHA, GL.GL ONE MINUS SRC ALPHA) gLDrawable.getGL().getGL2().glBindTexture(GL2.GL TEXTURE 2D, TextureFactory.getTextureIndex(TextureCollection.valueOf(getTextureSelection()))) gLDrawable.getGL().getGL2().glPushMatrix() gLDrawable.getGL().getGL2().glTranslatef(position.x getP2M(), position.y getP2M(), position.z) gLDrawable.getGL().getGL2().glRotated(Math.toDegrees(angle), 0, 0, 1) gLDrawable.getGL().getGL2().glBegin(GL2.GL QUADS) gLDrawable.getGL().getGL2().glTexCoord2f(0.0f, 0.0f) gLDrawable.getGL().getGL2().glVertex3f( getWidth() 2 getP2M(), getHeight() 2 getP2M(), 0.0f) gLDrawable.getGL().getGL2().glTexCoord2f(0.0f, 1.0f) gLDrawable.getGL().getGL2().glVertex3f( getWidth() 2 getP2M(), getHeight() 2 getP2M(), 0.0f) gLDrawable.getGL().getGL2().glTexCoord2f(1.0f, 1.0f) gLDrawable.getGL().getGL2().glVertex3f(getWidth() 2 getP2M(), getHeight() 2 getP2M(), 0.0f) gLDrawable.getGL().getGL2().glTexCoord2f(1.0f, 0.0f) gLDrawable.getGL().getGL2().glVertex3f(getWidth() 2 getP2M(), getHeight() 2 getP2M(), 0.0f) gLDrawable.getGL().getGL2().glEnd() gLDrawable.getGL().getGL2().glFlush() gLDrawable.getGL().getGL2().glPopMatrix() gLDrawable.getGL().getGL2().glDisable(GL.GL TEXTURE 2D) gLDrawable.getGL().getGL2().glDisable(GL.GL BLEND) How should I do this? (Example code would be great.)


GLSL to Cg why is the effect different? With reference to this question, where I was trying to make the shader compile, I am now trying to make an effect appear. The effect can be shown here, through a GLSL shader But when I use the equivalent Cg shader, the result becomes this Using the same images (color map normal map) and the same code (except the way to retrieve variables). Here is the original GLSL shader uniform sampler2D color texture uniform sampler2D normal texture void main() Extract the normal from the normal map vec3 normal normalize(texture2D(normal texture, gl TexCoord 0 .st).rgb 2.0 1.0) Determine where the light is positioned (this can be set however you like) vec3 light pos normalize(vec3(1.0, 1.0, 1.5)) Calculate the lighting diffuse value float diffuse max(dot(normal, light pos), 0.0) vec3 color diffuse texture2D(color texture, gl TexCoord 0 .st).rgb Set the output color of our current pixel gl FragColor vec4(color, 1.0) And here is the Cg shader I wrote struct fsOutput float4 color COLOR uniform sampler2D color texture TEXUNIT0 uniform sampler2D normal texture TEXUNIT1 fsOutput FS Main(float2 colorCoords TEXCOORD0, float2 normalCoords TEXCOORD1) fsOutput fragm float4 anorm tex2D(normal texture, normalCoords) float3 normal normalize(anorm.rgb 2.0f 1.0f) float3 light pos normalize(float3(1.0f, 1.0f, 1.5f)) float diffuse max(dot(normal, light pos), 0.0) float3 color diffuse tex2D(color texture, colorCoords).rgb fragm.color float4(color,1.0f) return fragm Please let me know if something needs to be changed in order to obtain the effect, or if you need the C code.


removing triangle artifacts from overlapping height maps OpenGL I have two 100x100 height maps that I am drawing using a triangle mesh. One represents the land height, and the other represents (water land) height. I currently draw both meshes on top of each other, and I make the water mesh transparent when the water level is 0. But where the land meets the water there are lots of artifacts. I believe the cause is the water mesh is the height of the land mesh so at the edges the water mesh height goes from being land mesh height to , the visible slope is actually the water mesh slope and not the land mesh slope. That said, I don't know any good way to fix it. Note water level may not be flat so replacing the water mesh with a plane wont work


Using one GLSL shader program for textured and untextured rendering? Rather than have two separate shaders in my OpenGL code (one for when a texture is bound, one for when none is bound) I usually go for one shader program which handles both. This is my usual fragment shader version 330 uniform bool textured uniform sampler2D sampler in vec4 fColor in vec2 tCoord out vec4 final color void main() vec4 texel vec4(1.0, 1.0, 1.0, 1.0) if (textured) texel texture(sampler, tCoord) final color fColor texel In a modern OpenGL profile, this compiled but did not output anything but black pixels (alternatively in LWJGL legacy profile, it outputted regular colors if textured false and textured if textured true). I don't see any reason that this wouldn't work, but what is a method which would work for both textured and untextured fragments? EDIT My Shader Class My Main CPP File


OpenGL 3 Range Picking How do I perform range picking in the latest OpenGL version? By range picking I mean selecting all objects which are picked using a selection rectangle, like in an RTS game. For single object picking I'm using the ray picking method, which I guess can be used in this case as well, but I'm not sure how I should go about doing that. Could you give me any pointers? Thank you.


Wrong angles given by atan2 I have a method to calculate angle between two vectors, but it is giving wrong values. here is the code float Vector2 Dot(Vector2 a, Vector2 b) return a.x b.x a.y b.y float Vector2 Cross(Vector2 a, Vector2 b) return a.x b.y a.y b.x float Vector2 Angle(Vector2 a, Vector2 b) return atan2f(Vector2 Cross(a, b), Vector2 Dot(a, b)) As you can see in the image bellow the angle is slightly wrong. I'm giving the two positions marked by a black cross. is the code correct or Do I have a problema elsewhere? Here's is where I do my transformation matrix calculation float Transform GetLocalAngle(DeadTransform transform) if (transform gt parent ! NULL) return transform gt parent gt angle transform gt angle else return transform gt angle void Transform Update(DeadTransform transform, GLfloat depth) float angle Transform GetLocalAngle(transform) Vector2 position Transform GetLocalPosition(transform) Vector2 scale Transform GetLocalScale(transform) GLfloat data 16 (GLfloat)cosf(angle) scale.x, (GLfloat)( sinf(angle)) scale.y, 0.0f, position.x 1000, (GLfloat)(sinf(angle)) scale.x, (GLfloat)cosf(angle) scale.y, 0.0f, position.y 1000, 0.0f, 0.0f, 1.0f, depth, 0.0f, 0.0f, 0, 1.0f Matrix SetData(transform gt transformationMatrix, data) This is where I create the road direction Vector2 Subtract( tile gt top gt transform gt position, tile gt topLeft gt transform gt position) pos.x tile gt top gt transform gt position gt x direction.x 2 pos.y tile gt top gt transform gt position gt y direction.y 2 float angle Vector2 Angle( tile gt top gt transform gt position, tile gt topLeft gt transform gt position) CreateConnection(application, pos.x, pos.y, angle) void CreateConnection(struct Application application, float x, float y, float angle) DeadGameObject zone GameObject Create("Connection") zone gt transform gt position gt x x zone gt transform gt position gt y y zone gt transform gt angle angle zone gt transform gt scale gt x 64 zone gt transform gt scale gt y 6 DeadRenderer renderer Renderer Create(Texture2D Create("Images Connection.png", GL CLAMP, GL LINEAR)) Renderer SetDepth(renderer, 2) GameObject AddComponent(zone, renderer, Type Renderer) Application Instantiate(application, zone)


Should I use the X Y plane when using an orthographic projection in OpenGL? I'm currently at a loss rendering a tile based 3D map with an orthographic projection in OpenGL. Imagine any isometric 3D game (using actual geometry instead of sprites). Internally, the tiles of my map have x and y coordinates (for column and row position within the map respectively). The tile with x 0 and y 0 is the one in the "top left", the one with y 0 and x 1 the one to the right of the first tile and so on. Since in OpenGL, the coordinate system is so that the X Z plane is the "ground" plane, I create the model matrix for each tile by using the tile's y coordinate for the matrix' (or position vector's) z component. I then set up an orthographic "camera" by using glm ortho(). This seems to work fine at first, but I quickly ran into clipping issues when trying to render larger parts of the map. I assume this is due to the fact that the orthographic projection clips on z. A quick and dirty attempt of having the map in the X Y plane confirmed this, as I didn't have clipping issues then. Now, I'm not sure what's the best approach here? Change the code so the tiles are being layed out in the X Y plane? In that case, it seems as if I would have to remember to rotate every single object around x accordingly, which seems wrong. Do I need to set up the orthographic projection manually to use Y as the clipping plane? Is that even possible? I think OpenGL always uses z for clipping, right? Some other approach? I think I'm lost in coordinates and matrices, really. I assume this is a common problem with a well known solution, so I'm hoping to learn about that before I go ahead, change a lot and then learn I did it the wrong way...


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.


What book guide should I follow for GLSL I searched a lot on the web without coming to a real solution and if I ask this it's because I really have difficulties getting an answer. I need to learn well GLSL 1.20 with OpenGL 2.1. I have bought beginning OpenGL game programming, 2nd edition, but it talk too little about GLSL. So I'm following some tutorials like this one, but it just makes a lot of examples without explaining the theory. The problem is that if I want to know something, I have to search a lot, and often the thing that I'm searching doesn't come straightforward. For example I didn't know how to compute the direction between two points, I looked into some example codes and I discovered that it was done with the dot product just by seeing the example code. But with this approach I waste a lot of time. I need a book guide which tells me how to do basilar stuff and also explains the theory. I just feel like I'm travelling into the fog. What book guide would you suggest?


Is this a good way of separating graphics from game logic? My current architecture for me game engine looks like this, though it is not accurate Everything graphics related is done in by GraphicsEngine, and through its components, like Material, Mesh, etc). My problem is that I want to store the pointers in RenderData, but I have to include the Mesh, Material etc header files, which have included glew. I currently change an objects material using GetRenderer().SetMaterial("xyz"), which sets a string in the renderData, to be processed by the graphics engine then the correct pointer will be set, if it exists. This is not so modular, because the scene has graphics related files included, like glew. This is a problem. My only solution is to store indices in RenderData. There wont be a material pointer, but instead, an index where the material is in the GraphicsEngines material store. This way, RenderData is just a "blind" integer and string store, in which the Renderer egy the GraphicsEngine works. Is this a good solution? Meshes have VertexData members (position, normal, texture). When I call GraphicEngine.CreateMesh(), passing the MeshName and FileName, where should the file processing go? I use Tiny Obj Loader, and I don't know where I should include it, and call its function. I call the function from inside GraphicsEngine, then I transform the returned structures to my Mesh's structure, which I pass to the Mesh's constructor. The initialised list will assign it to the corresponding member variable. Inside Mesh, I pass the FileName to the Mesh constructor, and let it handle it all by itself. I think the first solution is better, but I don't really know why. Maybe using GraphicsEngine to "create" assets is better than GraphicsEngine commanding assets to "be created" but this is just a personal feeling. Which solution is better?


Which code is faster to convert 1 to 0 and 1 to 1? I'm writing a shader for rendering the sides of triangles with different colors. I have a value mediump float back dot(V, N) which is positive if the normal faces away from the camera and negative if towards the camera. To correctly select which diffuse color to shade a particular fragment, I need something like this lowp vec4 color max(0.0, sign( back)) frontdiffuse max(0.0, sign(back)) back diffuse It's more or less an "unrolled conditional"... Which code produces faster instructions? x 0.5 0.5, or max(0.0, x) ? The former may be better mathematically behaved than the latter, but maybe min max clamping is super efficient in hardware


OpenGL ES 2.0 Calculated Cube Vertex Normals Verification Could I kindly ask to confirm, that the calculated normals are correct, please? I have calculated them on my own, but my testcube is still strangely lighted within OpenGLES 2.0. The vertices were exported from 3D authoring application. The vertex normals were calculated using matrix cross product. The vertex and fragment shaders I were exact copies from the book, so there should not be a bug. The output in OpenGL looks like the sphere is lighted from its bottom. Moreover, it looks, like the box is visible from inside, as the top part is always transparent. Any idea, where can be a problem? Added The vertex normals are calculated based on triangulated quad polygons. The triangulation is performed internally, by the 3d application. Vertices indices are generated by calling API calls of that application. begin 8 vertices vs 24 v 25.000000 25.000000 25.000000 v 25.000000 25.000000 25.000000 v 25.000000 25.000000 25.000000 v 25.000000 25.000000 25.000000 v 25.000000 25.000000 25.000000 v 25.000000 25.000000 25.000000 v 25.000000 25.000000 25.000000 v 25.000000 25.000000 25.000000 end 8 vertices begin 12 faces fs 36 f 0 2 3 f 0 3 1 f 0 1 5 f 0 5 4 f 0 4 6 f 0 6 2 f 1 3 7 f 1 7 5 f 2 6 7 f 2 7 3 f 4 5 7 f 4 7 6 end 12 faces begin 8 calculated normals ns 24 n 0.577350 0.577350 0.577350 n 0.816497 0.408248 0.408248 n 0.408248 0.816497 0.408248 n 0.408248 0.408248 0.816497 n 0.408248 0.408248 0.816497 n 0.408248 0.816497 0.408248 n 0.816497 0.408248 0.408248 n 0.577350 0.577350 0.577350 end 8 calculated normals I use OpenGL ES 2.0, but that should not be relevant at this moment. Update I can confirm now, that the calculated vertex normals are correct, and can therefore be used by others, to verify correctness of their triangulated cube vertex normals calculations. However, I still have a problem that all the vertices, which are in positive z axis, are not rendered. Not sure if they are culled, but I have pretty large frustum. Vertices in the z axis are kept, so the rendered mesh looks like cut in half, as it is position in 0 z axis. This lines below show that I should not concsicously setup small render area mProjection glm perspective (45.0f, (float)WINDOW WIDTH (float)WINDOW HEIGHT, 1130.0f, 1130.0f) mViewTransformation glm lookAt(glm vec3(vIntCamera.x, vIntCamera.y, 1130.0f), glm vec3(vIntCamera.x, vIntCamera.y, 0.0f), glm vec3(0.0f, 1.0f, 0.0f)) Any ideas, please, what else should I check? Solved Eye position of the camera (in glm lookAt() function) should be above the top of the perspective frustum, defined by glm perspective(). Thanks for your support guys, especially with the upper part of my question.


How can I implement a camera like the one in RotMG? RotMG, an MMO top down shooter, takes on a unique 2d 3d style, and has an intriguing camera The game is obviously 3d, not simply isometric, and if you play the game and turn on camera rotation you will notice the effect the game produces, like so. RotMG is made using flash, and I am currently experimenting with libgdx (which uses lwjgl opengl). How should I go about implementing a RotMG like camera?


Blending and shadowmapping? I am trying to implement shadow mapping, and currently I have 2 point lights and 1 global ambient light source and my rendering loop looks roughly like this (the details are not relevant) void OpenGLRenderer DrawRenderables(const uint32 t windowWidth, const uint32 t windowHeight, const RenderQueue amp renderQueue, const RenderableLighting amp lighting) GLCALL(glClear(GL COLOR BUFFER BIT GL DEPTH BUFFER BIT)) for (uint32 t lightIndex 0 lightIndex lt lighting.mUsedLights lightIndex ) if (lighting.mLights lightIndex .mLightType LightType LIGHT TYPE POINT) GLCALL(glUseProgram(mShadowMapProgram.mProgramHandle)) GLCALL(glBindFramebuffer(GL FRAMEBUFFER, mFrameBuffer)) GLCALL(glViewport(0, 0, mShadowTextureWidth, mShadowTextureHeight)) for (uint32 t faceNum 0 faceNum lt CUBEMAP NUM FACES faceNum ) GLCALL(glFramebufferTexture2D(GL FRAMEBUFFER, GL DEPTH ATTACHMENT, GL TEXTURE CUBE MAP POSITIVE X faceNum, mShadowMapTexture, 0)) GLCALL(glClear(GL DEPTH BUFFER BIT)) ShadowPass() GLCALL(glBindFramebuffer(GL FRAMEBUFFER, 0)) final pass GLCALL(glUseProgram(mDefaultProgram.mProgramHandle)) GLCALL(glViewport(0, 0, (GLsizei)windowWidth, (GLsizei)windowHeight)) enable blending, how? ShadingPass() GLCALL(glUseProgram(0)) The problem is the screen will only be shown with last light in the light list, for example the ambient light and therefore ignoring the effects of the point lights. I assume I somehow needs to do blending but I was wondering how and where is this done? Thanks


How to draw 2D pixel data with OpenGL I am fairly new to OpenGL. I have a 2D game in SDL2 that uses currently works by creating a SDL Surface from the pixel data, copying it into a SDL Texture, and rendering it to the screen with SDL Renderer. But rather than using SDL to render the pixels, I'd like to switch to OpenGL. The reason I'd like to switch is because I need to render some lines on top of the pixel data and SDL RenderDrawLine() just doesn't have all the features I need (like line thickness or glScissor). At first, I attempted to switch to OpenGL by using glDrawPixels() and I was happy with the results. However, I found out that glDrawPixels() does not seem to be available in OpenGL ES (mobile devices). I have looked through some tutorials, but they all use shaders and other fancy stuff that I don't think I really need. Is there a simple way (like glDrawPixels()) to just draw pixel data to the screen for a 2D game? The pixel data is in the format GL UNSIGNED BYTE and it contains everything that I want to draw on the screen (except for several 2D line segments that I plan on using GL to render on top).


Render on texture with alpha 0 for the background colour Sorry if the question is stupid but I am very new to opengl. I render on a target a scene with a couple of object on a background that is nothing more than the clear colour (which is 0.0,0.0,0.0,0.0). When I access the texture again every single pixel has 1 has alpha, how can I make sure the background has 0.0 ? Thank you Faye


What is an appropriate OpenGL(ES) based game engine meeting these criteria? I want to try my hands on a little shooter on the Android platform, and I'm looking for a full featured 3D game engine. I can't afford to pay more than 400 for a license, so expensive engines are excluded from the start. These are my requirements The engine has to have good level editor (able to place entities, actors and triggers) so "graphics engines" like Irrlicht and Horde 3D aren't what I'm looking for. The engine should be based on OpenGL Core and use shaders rather than the fixed function pipeline. It shouldn't use octrees and BSP PVS. It needs to have decent occlusion culling because I need good frame rates on not very powerful graphics cards. It should come with source code. I like Horde 3D very, very much and I like it's smart design, rendering capabilities and compactness. Sadly, I can't use it due to the lack of tools. So far I've come across Torque 3D, C4 engine, Shiva 3D, and Unity 3D. Torque 3D is really nice, decent design, has good tools, good performance, it's really cheap and comes with source code. Sadly it's only DirectX for now. Unity has a lot of features, decent performance and tools, runs on Android but they don't give source code within my price range. C4 is good enough, has tools, and source code but there's a catch. While you have source code the source isn't ported to Android and the engine's owner expressly forbids anyone to port source code on other platforms or to release a game on not officially supported platforms. Shiva 3D seems nice, too, supports Android, has tools but they don't give you source code license for a decent sum. That's all I could find. I used the list on devmaster.net, I searched this site, I've searched gamedev.net, gamasutra, polycount.com and of course Google and Bing. Any suggestions that could help me?


clamp a 2D coordinate to fit within an ellipse I need to clamp a 2D coordinate to fit within an ellipse. Call of Duty Modern Warfare 2 does something similar where capture points are translated from a 3D vector in the world to a 2D screen coordinate and then the 2D coordinates are clamped within an ellipse. When the capture points are in view they're within the bounds of the ellipse. When they're behind you they are clamped to be within the bounds of the ellipse. Given a 2D coordinate that could be off screen, etc, what is the math behind clamping it within an ellipse?


Optimising Voxel World Rendering There are a couple of questions like this already. This one is different because it is specifically about rendering, as opposed to navigation and generation. I've implemented suggestions from here already. The current optimisations are Only render block faces that aren't adjacent to another face Render blocks in chunks, each chunk as one mesh (VAO) According to the NetBeans profiler, 96 of time is spent on the glfwSwapBuffers(long window) method, which is when OpenGL renders the scene. This implies that my other operations are efficient enough, compared to rendering. What else can I do to improve rendering performance? The chunk size is 16x16x16 voxels. Sample renders and FPS 64 chunks 500 FPS 125 chunks 300 FPS 1000 chunks 45 FPS 4096 chunks 12 FPS


Reinhard tone mapping and color space I found two ways of doing tone mapping (first, second) Ld this part of the code is the same for both versions float lum dot(rgb, vec3(0.2126f, 0.7152f, 0.0722f)) float L (scale averageLum) lum float Ld (L (1.0 L lumwhite2)) (1.0 L) first vec3 xyY RGBtoxyY(rgb) xyY.z Ld rgb xyYtoRGB(xyY) second rgb (rgb lum) Ld For an example pixel data above equations produces different results. Which way is correct ?


SFML Segmentation Fault when using VBOs? I'm trying to follow along with the gltut tutorials and for some reason when I call GLDrawArrays my program segmentation faults. I've been looking at the state of my application with the Mac OpenGL Profiler and Googling and I can't seem to figure out why it isn't working. I may have missed setting some OpenGL state somewhere. My code is here, it segfaults on line 32. If I don't call glEnableClientState(GL VERTEX ARRAY) and the respective glDisableClientState(GL VERTEX ARRAY) it compiles and runs, but I get no rendering, which is what I would expect given my limited OpenGL knowledge.


Procedural texturing with opengl I have a hexagonal grid of fields, each field has a certain terrain type. I assign every vertex of hexagon with terrain type and pass it as attribute to vertex and then fragment shader. Then I use the extrapolated value to blend terrain textures together. For instance 1 is grassy, 2 is desert. Vertex shader varying vec2 vUv attribute float terrainType varying float vTerrainType void main() vUv uv vTerrainType terrainType vec4 mvPosition mvPosition modelViewMatrix vec4( position, 1.0 ) gl Position projectionMatrix mvPosition Fragment shader uniform vec3 diffuse uniform float opacity varying vec2 vUv varying float vTerrainType uniform sampler2D map uniform sampler2D map1 void main() gl FragColor vec4( diffuse, opacity ) vec4 texelColor texture2D( map, vUv ) (2.0 vTerrainType) texture2D( map1, vUv ) (vTerrainType 1.0) gl FragColor gl FragColor texelColor Implementation is WebGL, if it makes any difference. The result looks really unnatural, so is there any way to make it smoother and rounder?


What is the right process to get compatibility or at least a workaround for the Threaded optimization feature of NVIDIA? It's peculiar this issue is not well understood on NVIDIA forums and project forums. For example, the well known ioquake3 project based on id tech 3 requires to force 'Threaded optimization' off on the NVIDIA settings or there are severe FPS drops. Do you know what a programmer has to do to acquire compatibility with the feature or at least a workaround to not get issues with it (e.g. turning it off explicitly via the application or other means)? The main importance is that such projects get issues with it by default since not all users know they have to explicitly turn off the feature.


Getting OpenGL hardware acceleration with SDL on Linux I'm trying to use SDL OpenGL but I don't believe hardware acceleration is working because the framerate for around 18000 polys is about 24fps on a quad core machine but is a hopeless 1 2fps on an Intel Atom. Even the quad core starts to struggle when the poly count rises above this. I've checked my code over but I'm clearly missing something obvious. I've changed my SDL initialisation code to use the same code as in the SDL OpenGL test. It reports that SDL GL ACCELERATED VISUAL is 1 but that hw available in SDL VideoInfo is 0 Also the vendor is reported correctly as Nvidia on both machines and accelerated apps such as Compiz and glxgears work fine. Any ideas of what to try? Thanks


GLSL Rewriting shaders from 330 to 130 I recently created a game (LD21) that uses a geometry shader to convert points into textured triangles culling. Since I was under the impression that the support for 330 was widespread I only wrote 330 shaders, but it seems that a lot of not so old hardware only support 130 (according to GLView) Now, since I'm only familiar with the 330 core functionality I am having trouble rewriting my shaders to 130. The fragment shader was quite trivial to rewrite, but I've only managed to get my vertex and geometry shader down to 150. So, is it possible to rewrite the shaders, or would it require a lot of changes in my rendering engine? Geometry shader version 150 layout(points) in layout(triangle strip, max vertices 4) out uniform mat4 oMatrix in VertexData vec4 position vec4 texcoord vec4 size vert out vec2 gTexCoord void main() if(vert.position.x gt 4f amp amp vert.position.x lt 4f amp amp vert.position.y gt 2f amp amp vert.position.y lt 2f) gTexCoord vec2(vert.texcoord.z,vert.texcoord.y) gl Position vert.position vec4(vert.size.x,vert.size.y,0,0) EmitVertex() gTexCoord vec2(vert.texcoord.x,vert.texcoord.y) gl Position vert.position vec4(0.0,vert.size.y,0,0) EmitVertex() gTexCoord vec2(vert.texcoord.z,vert.texcoord.w) gl Position vert.position vec4(vert.size.x,0.0,0,0) EmitVertex() gTexCoord vec2(vert.texcoord.x,vert.texcoord.w) gl Position vert.position EmitVertex() EndPrimitive() Vertex shader version 150 extension GL ARB explicit attrib location enable layout (location 0) in vec2 position layout (location 1) in vec4 textureCoord layout (location 2) in vec2 size uniform mat4 oMatrix uniform vec2 offset out VertexData vec4 position vec4 texcoord vec4 size outData void main() outData.position oMatrix vec4(position.x offset.x,position.y offset.y,0,1) outData.texcoord textureCoord outData.size oMatrix vec4(size.x,size.y,0,0)


How to put the camera inside a cube in OpenGL I'm really new to OpenGL and can't seem to figure out how to put the "camera" inside the cube I've created so that I can move in an FPS like style. I tried to use gluLookAt and gluPerspective but I'm clearly missing some steps. What should I do before gluLookAt? Here's the code written so far int rotate Y used to rotate the cube about the Y axis int rotate X used to rotate the cube about the X axis the display function draws the scene and redraws it void display() clear the screen and the z buffer glClear(GL COLOR BUFFER BIT GL DEPTH BUFFER BIT) glLoadIdentity() resets the transformations glRotatef(rotate X, 1.0, 0.0, 0.0) glRotatef(rotate Y, 0.0, 1.0, 0.0) Front Face of the cube vertex definition glBegin(GL POLYGON) glColor3f(0.0, 1.0, 0.0) glVertex3f( 0.5f, 0.5f, 0.5f) glVertex3f( 0.5f, 0.5f, 0.5f) glVertex3f(0.5f, 0.5f, 0.5f) glVertex3f(0.5f, 0.5f, 0.5f) glEnd() Back Face of the cube vertex definition glBegin(GL POLYGON) glColor3f(1.0, 0.0, 0.0) glVertex3f( 0.5f, 0.5f, 0.5f) glVertex3f( 0.5f, 0.5f, 0.5f) glVertex3f(0.5f, 0.5f, 0.5f) glVertex3f(0.5f, 0.5f, 0.5f) glEnd() Right Face of the cube vertex definition glBegin(GL POLYGON) glColor3f(1.0, 0.0, 1.0) glVertex3f(0.5f, 0.5f, 0.5f) glVertex3f(0.5f, 0.5f, 0.5f) glVertex3f(0.5f, 0.5f, 0.5f) glVertex3f(0.5f, 0.5f, 0.5f) glEnd() Left Face of the cube vertex definition glBegin(GL POLYGON) glColor3f(0.7, 0.7, 0.0) glVertex3f( 0.5f, 0.5f, 0.5f) glVertex3f( 0.5f, 0.5f, 0.5f) glVertex3f( 0.5f, 0.5f, 0.5f) glVertex3f( 0.5f, 0.5f, 0.5f) glEnd() Upper Face of the cube vertex definition glBegin(GL POLYGON) glColor3f(0.7, 0.7, 0.3) glVertex3f( 0.5f, 0.5f, 0.5f) glVertex3f( 0.5f, 0.5f, 0.5f) glVertex3f(0.5f, 0.5f, 0.5f) glVertex3f(0.5f, 0.5f, 0.5f) glEnd() Bottom Face of the cube vertex definition glBegin(GL POLYGON) glColor3f(0.2, 0.2, 0.8) glVertex3f( 0.5f, 0.5f, 0.5f) glVertex3f( 0.5f, 0.5f, 0.5f) glVertex3f(0.5f, 0.5f, 0.5f) glVertex3f(0.5f, 0.5f, 0.5f) glEnd() glFlush() glutSwapBuffers() send image to the screen int main(int argc, char argv ) initialize GLUT glutInit( amp argc, argv) request double buffering, RGB colors window and a z buffer glutInitDisplayMode(GLUT DOUBLE GLUT RGB GLUT DEPTH) create a window glutInitWindowSize(600, 600) glutInitWindowPosition(100, 100) glutCreateWindow("Space") enable depth glEnable(GL DEPTH TEST) callback functions glutDisplayFunc(display) display redraws the scene glutSpecialFunc(specialKeys) special allows interaction with specialkeys pass control to GLUT for events glutMainLoop() return 0 this line is never reached Feel free to ask more about what I'm trying to achieve if I wasn't clear enough. Thanks for your help.


How to change the color of an invalid texture? In openGL, when I don't bind a texture, or I bind a texture that was loaded incorrectly, any calls to texture2D texelFetch in the shader will return vec4(0, 0, 0, 1), is there a way to change this to return vec4(1, 1, 1, 1) instead? Initially I looked for a way to test if the sampler2D was valid, and when I couldn't find that I tried using glColor4f, but that doesn't seem to work either although that could be the amdgpu driver, it seems to have some trouble with the old pipeline calls generally. Is there someway to change what this default return color is?


How do I create the playing field for my game? I want to create a game with playfield as shown in the video in OpenGL www.youtube.com user stanfordcs248 I have fair knowledge of OpenGL and I know this playfield can be rendered using several different cubes but that takes a lot of effort. Also it takes away the power of easily modifying the field. One idea that was suggested to me to solve this problem was to use an XML file describing almost every component of the game. Like the floor, walls , moving floors, moving obstacles etc. That way i can easily change the playfield when I want. But this approach also seems tedious. Also I couldn't figure out the structure of the XML that would make my life quite easy. So is there any better way to create or store information about the playfield than suggested above? Note Blender is also an option. But please provide a tutorial if you are suggesting the Blender way.


View matrix in opengl Sorry for my clumsy question. But I don't know where I am wrong at creating view matrix. I have the following code createMatrix(vec4f(xAxis.x, xAxis.y, xAxis.z, dot(xAxis,eye)), vec4f( yAxis.x , yAxis.y , yAxis.z , dot(yAxis,eye)), vec4f( zAxis.x , zAxis.y , zAxis.z , dot(zAxis,eye)), vec4f(0, 0, 0, 1)) column1, column2,... I have tried to transpose it, but with no success. I have also tried to use gluLookAt(...) with success. At the reference page, I watched the remarks about the to be created matrix, and it seems the same as mine. Where I am wrong?


OpenGL doesn't draw (3.3 ) Brief I've been following this tutorial about OpenGL for 2 days, and I still can't have a triangle drawn, so I'm asking for help here. The tutorial is turned to OpenGL version 3.3 programing, using vertex arrays, buffers, etc. The libraries are GLFW3 and GLEW, and I setted them by myself. The screen keeps black all the time. Full code link here (It's just like a Hello World opengl program) Further Details I get no errors at all. I downloaded a software to test my video card, and it supports OpenGL 4.1 Standard OpenGL code for drawing (from earlier version) such as this one works normally. I'm using Microsoft Visual Studio 10.0 I presume all the OpenGL implementation was dune right I added Additional Dependences to the linker as glew32.lib, opengl32.lib, glfw3.lib. The glew.dll was placed at SysWOW64 because I'm running window 64bits, and glew is 32. Notes I've been working hard to find out what this is, but I can't find. I would appreciate if anyone could test this code for me, so I can know if I implemented something wrong, and that its not my code.


Is it possible to gain performance by omitting vertex normals in the GPU pipe? I am working on a rendering problem where I want to render as many raw triangles to the screen as I can with either OpenGL or DirectX with the absolute fastest performance possible. I wondered about omitting vertex normals completely and only transforming vertex positions during the vertex shader stage. 1) Is this possible? 2) Is it actually going to increase performance or is the "bare metal" of the GPU designed in such a way that trying to omit normals won't gain any more throughput? p.s. Yes, I realize that omitting normals will leave you with the problem of how to shade the triangle during the shader stage, but I could at least render a solid color to the screen (no shading). At this point, all I'm wondering about is how much data I can eliminate from the typical pipeline to increase the pipeline throughput to the absolute maximum.


Compressing textures and recompressing textures Which tools are considered best quality for compressing textures for use in OpenGL? Which can be used from the Linux commandline? And which lossless compressors give good ratio speed on compressed textures? (I see that Skyrim's BSA archives are typically only half the size of the DDSes they contain)


SDL2 Draw scene to texture. SDL2 RenderTexture like SFML I've been developing a 2D Engine using SFML ImGui. The editor is rendered using ImGui and the scene window is a sf RenderTexture where I draw the GameObjects and then is converted to ImGui Image to render it in the editor. Now I need to create a 3D Engine during this year in my Bachelor Degree but using SDL2 ImGui and I want to recreate what I did with the 2D Engine. I've managed to render the editor like I did in the 2D Engine using this Example that comes with ImGui. But I don't know how to create an equivalent of sf RenderTexture in SDL2, so I can draw the 3D scene there and convert it to ImGui Image to show it in the editor. If you can provide code will be better. And if you want me to provide any specific code tell me. Thanks!


Region selection in OpenGL If I have a mesh of triangles and going to make a selection on it using a region (and not rectangle using Glu.gluPickMatrix(...) ), how can I implement it?


How can I improve rendering speeds of a Voxel Minecraft type game? I'm writing my own clone of Minecraft (also written in Java). It works great right now. With a viewing distance of 40 meters I can easily hit 60 FPS on my MacBook Pro 8,1. (Intel i5 Intel HD Graphics 3000). But if I put the viewing distance on 70 meters, I only reach 15 25 FPS. In the real Minecraft, I can put the viewing disntance on far ( 256m) without a problem. So my question is what should I do to make my game better? The optimisations I implemented Only keep local chunks in memory (depending on the player's viewing distance) Frustum culling (First on the chunks, then on the blocks) Only drawing really visible faces of the blocks Using lists per chunk that contain the visible blocks. Chunks that become visible will add itself to this list. If they become invisible, they are automatically removed from this list. Blocks become (in)visible by building or destroying a neighbour block. Using lists per chunk that contain the updating blocks. Same mechanism as the visible block lists. Use nearly no new statements inside the game loop. (My game runs about 20 seconds until the Garbage Collector is invoked) I'm using OpenGL call lists at the moment. (glNewList(), glEndList(), glCallList()) for each side of a kind of block. Currently I'm even not using any sort of lighting system. I heard already about VBO's. But I don't know exactly what it is. However, I'll do some research about them. Will they improve performance? Before implementing VBO's, I want to try to use glCallLists() and pass a list of call lists. Instead using thousand times glCallList(). (I want to try this, because I think that the real MineCraft doesn't use VBO's. Correct?) Are there other tricks to improve performance? VisualVM profiling showed me this (profiling for only 33 frames, with a viewing distance of 70 meters) Profiling with 40 meters (246 frames) Note I'm synchronising a lot of methods and code blocks, because I'm generating chunks in another thread. I think that acquiring a lock for an object is a performance issue when doing this much in a game loop (of course, I'm talking about the time when there is only the game loop and no new chunks are generated). Is this right? Edit After removing some synchronised blocks and some other little improvements. The performance is already much better. Here are my new profiling results with 70 meters I think it is pretty clear that selectVisibleBlocks is the issue here. Thanks in advance! Martijn Update After some extra improvements (like using for loops in stead of for each, buffering variables outside loops, etc...), I now can run viewing distance 60 pretty good. I think I'm going to implement VBO's as soon as possible. PS All source code is available on GitHub https github.com mcourteaux CraftMania


What rotation needs to be applied to align mesh with expected axis of target? I'm using LWJGL and JOML to create a 3D view of hexagons whose positions lie on a torus. I have a number (NxM) hexagons, whose centres and normals I have calculated to be placed on the torus to completely cover the torus surface, but in the quot game quot engine I'm using I need to convert each item being rendered to a position and 3 rotation angles. I'm struggling to go from the 3 normals of the item to the 3 angles. EDIT Subsequent to posting this I have got some way in creating a matrix with the angles and converting to Euler angles, everything is now turned according to those angles, but they aren't facing directions I expect. The background I'm trying to create a visualisation of a Conway Game of Life using hexagons but instead of a simple plane, mapping each hexagon onto a Torus. I've done the maths to calculate the centres of every hexagon, and the 3 direction unit vectors that they need to point to, when in their places around the torus. For illustrative purposes, here's a view of the torus and 2 hexagons that would lie on it (not real, this is just me mocking it up in Blender) What I'm struggling to understand is how to rotate the single mesh for a hexagon to its calculated normals at the position I want to place it. i.e. How do I rotate some quot unit quot hexagon mesh (loaded from an OBJ file exported from Blender) to point in the direction of the 3 normals I've calculated they should be for each hexagon around the torus. I have read a similar question here, but I'm struggling to get from the idea of the 4d rotation matrix to how I convert that to a Vector3f for rotations. I have the 3 vector normals, could create the 4d matrix, but I need a Vector3f (the rotations about x y z) to the mesh is drawn correctly. My code is here. I'm following this guide for using LWJGL to create GameItems (my hexagons) and position rotate them from a loaded obj file mesh, but as I say, I'm struggling to calculate the rotation Vector3f needed to point in the same direction I've calculated. Here's the code section relevant to the problem at hand val mesh loadMesh( quot conwayhex models simple hexagon.obj quot ) hexGrid.hexAxes().forEach (location, axis) gt axis is a Matrix3f with my 3 normals at the centre of the hexagon, e.g cX cY cZ 0 1 0 0 0 1 1 0 0 val gameItem GameItem(mesh) gameItem.position location gameItem.scale 0.2f TODO calculate this according to the torus size what rotation do I give this? How do I calculate it from the given axis for the current item? gameItem.rotation Vector3f(30f, 30f, 30f) gameItems gameItem The output of the application given the above static 30 degree rotation is Can anyone help me unserstand how I apply the rotation to my items so they align to what I've calculated they should be?


How can I write only to the stencil buffer in OpenGL ES 2.0? I'd like to write to the stencil buffer without incurring the cost of my expensive shaders. As I understand it, I write to the stencil buffer as a 'side effect' of rendering something. In this first pass where I write to the stencil buffer, I don't want to write anything to the color or depth buffer, and I definitely don't want to run through my lighting equations in my shaders. Do I need to create no op shaders for this (and can I just discard fragments), or is there a better way to do this? As the title says, I'm using OpenGL ES 2.0. I haven't used the stencil buffer before, so if I seem to be misunderstanding something, feel free to be verbose.


PBR Metalness Implementation specColor at Value 1? I am doing a BRDF supporting the metalness roughness workflow. I know that in cases of Metalness 1.0 the reflectance value is taken from the albedo map so is the specular color to tint the highlights. My question is if the specular color is taken at the same value that it is in the albedo or is it set to 1.0 first and then used ? Example A Pixel in my Albedo Map has a Hue Sat Value of 0.5 0.5 0.5 With metalness 1 the reflectance is 0.5. Is specColor a) 0.5 0.5 0.5 b) 0.5 0.5 1.0 (to not dim the specular) ? Thanks, Jens


Projection Matrix Breaks My Rectangle This is my vertex shader, shown below. version 330 core in vec3 a position in vec4 a colour FOV 70, near plane 0.1, far plane 1000 const mat4 u projection mat4( 1.428148, 0.0, 0.0, 0.0, 0.0, 1.428148, 0.0, 0.0, 0.0, 0.0, 1.0001999, 0.20002, 0.0, 0.0, 1.0, 0.0 ) uniform mat4 u projection uniform mat4 u view uniform mat4 u transformation out vec4 v colour void main() gl Position u projection u transformation vec4(a position, 1) v colour a colour Whenever I take out u projection, my square appears. When I add it back, the square is malformed. The vertices of my square are as follows, aka the contents of a position. float vertices 0, 0, 0.5f, 0.5f, 0.5f, 0.5f, 0, 0.5f, 0.5f, 0, 0, 0.5f, 0f, 0.5f, 0.5f, 0, 0.5f, 0.5f The position of the square is (0, 0, 0), the rotation is (0, 0, 0) and the scale is 1. These are computed into u transformation and uploaded. This works perfectly. If I change the 1.0001999 and the last 0 to 1 part to 1 then the square is not hidden. void bindAttribute(int index, String name) GL20.glBindAttribLocation(program, index, name) bindAttribute(0, "a position") bindAttribute(1, "a colour")


Why do tutorials use different approaches to OpenGL rendering? http www.sdltutorials.com sdl opengl tutorial basics http www.opengl tutorial.org beginners tutorials tutorial 2 the first triangle These two tutorials use completely different approaches to get nearly the same result. The first uses things like glBegin(GL QUADS). The second one uses stuff like vertexBufferObjects, shaders based on GLEW. But the result is the same you get basic shapes. Why do these differences exist? The first approach seems much easier to understand. What's the advantage of the complicated second approach?


Do UV coordinates need correction for moving object? The image above is a static capture of a dynamic OpenGL project I created in which I wrapped a NASA albedo, i.e., sans clouds, image on an OpenGL generated sphere. In so doing, I also generated the UV coordinates associated with each vertex position. This was an incremental learning effort in which I had already applied model matrix corrections to the vertex positions for the rotating and translating (orbiting) "Earth". I was surprised to find that I did not have to apply a model matrix correction to the UV coordinates. I have tentatively concluded that once the jpg image coordinates are associated with the corresponding vertex positions with the UV coordinates in the range of 0, 1 , they are fixed and need no further correction. Does that sound correct, or is there more to the situation?


Skeletal animation unexpected quarternion values I'm following ThinMatrix's skeletal animation tutorial and his custom written Collada parser is deriving a different rotation quaternion from each keyframe matrix than the Assimp importer library does. They are close, except the values are signed inversely and unpredicatbly. I dug around his importer code but it's a mess. I assume he is manually performing an additional axis calculation somewhere, any ideas what it could be and why? Original Matrix 1 0 0 0 0 0.06466547 0.997907 0 0 0.997907 0.06466556 3.810999 0 0 0 1 Assimp rotation quaternion (0.7296115 , 0 , 0 , 0.683862) ThinMatrix's rotation quaternion 0.72961134 , 0, 0 , 0.68386203) And for reference, the position vec3 (0, 0, 3.810999) Update With an identity matrix both Assimp and the ThinMatrix code produce (0, 0, 0, 1)


Cubemaps turn black OpenGL GLSL Java LWJGL Recently I tried to add cubemaps to my 3D rendering engine. The objects with a cubemap now turn completely black. This is how I load my cubemap public static int loadCubeMap(String filename) int id GL11.glGenTextures() GL13.glActiveTexture(GL13.GL TEXTURE0) GL11.glBindTexture(GL13.GL TEXTURE CUBE MAP, id) for(int i 0 i lt CUBEMAP NAMES.length i ) TextureData data decodeTextureFile(CUBEMAPS LOCATION filename " " CUBEMAP NAMES i ) GL11.glTexImage2D(GL13.GL TEXTURE CUBE MAP POSITIVE X i, 0, GL11.GL RGBA, data.getWidth(), data.getHeight(), 0, GL11.GL RGBA, GL11.GL UNSIGNED BYTE, data.getBuffer()) GL11.glTexParameteri(GL13.GL TEXTURE CUBE MAP, GL11.GL TEXTURE MAG FILTER, GL11.GL LINEAR) GL11.glTexParameteri(GL13.GL TEXTURE CUBE MAP, GL11.GL TEXTURE MIN FILTER, GL11.GL LINEAR) GL11.glTexParameteri(GL13.GL TEXTURE CUBE MAP, GL11.GL TEXTURE WRAP S, GL12.GL CLAMP TO EDGE) GL11.glTexParameteri(GL13.GL TEXTURE CUBE MAP, GL11.GL TEXTURE WRAP T, GL12.GL CLAMP TO EDGE) return id TextureData class only contains int width, height and a ByteBuffer buffer private static TextureData decodeTextureFile(String fileName) int width 0 int height 0 ByteBuffer buffer null try FileInputStream in new FileInputStream(TEXTURES LOCATION fileName ".png") PNGDecoder decoder new PNGDecoder(in) width decoder.getWidth() height decoder.getHeight() buffer ByteBuffer.allocateDirect(4 width height) decoder.decode(buffer, width 4, Format.RGBA) buffer.flip() in.close() catch (Exception e) e.printStackTrace() return new TextureData(width, height, buffer) This is how I load the cubemap to the samplerCube cubemap i in the fragment shader public void loadCubeMap(int id, CubeMap cubemap, int cubemapid) if(cubemap ! null) super.loadTexture(location cubemaps cubemapid , cubemap.id, id, GL13.GL TEXTURE CUBE MAP) super.loadFloat(location cubemap intensity id , cubemap.intensity) else super.loadFloat(location cubemap intensity id , 0.0f) in super class protected void loadTexture(int location, int texture, int i, int texturetype) loadInt(location, i 1) GL13.glActiveTexture(GL13.GL TEXTURE0 i) GL11.glBindTexture(texturetype, texture) And this is my fragment shader version 400 core in vec4 color in vec2 texCoord0 in vec3 surface normal in vec3 to light vector in vec3 world position out out vec4 out Color uniform sampler2D sampler0 uniform samplerCube cubemap 3 uniform vec3 lightColor uniform float cubemap intensity 3 uniform int hasTexture void main(void) vec3 unitNormal normalize(surface normal) vec3 unitLight normalize(to light vector) float nDot1 dot(unitNormal, unitLight) float brightness max(nDot1, 0.02) vec3 diffuse color.xyz brightness lightColor color.xyz vec4 textureColor texture(sampler0, texCoord0.xy) if(textureColor.a lt 0.5) discard vec4 shadedTextureColor brightness vec4(lightColor, 1) textureColor vec4 coloredShadedTexture mix(vec4(diffuse, 1), shadedTextureColor, textureColor.a hasTexture) vec4 reflectionColor texture(cubemap 0 , world position out) vec4 refractionColor vec4 cubemapColor out Color reflectionColor


Drawing sprite shapes with triangles instead of textures If I want to use no textures in a game (ie. no png images), could I just break down my drawing into triangles, combined into the shape I want to draw, and draw those triangles instead? For example, I found this in Google Images, showing how an "arrow" graphic could be drawn as a triangle mesh instead of a textured sprite


Which consoles may I target with OpenGL? I'm thinking on technical design for a game game engine using OpenGL, and I wonder if there is any recent consoles (Xbox360, PS3, Wii U, Xbox one and PS4) that I could work with if I do so. I found plenty of conflicting answers through forums. The only straight answer seems that it is impossible for Xboxes because Microsoft forbid to use something else than DirectX, its own product. So, finally, does anyone know for sure which consoles can support an OpenGL based game?


Cube world rendering optimizations I'm making a Minecraft like game and I would like to apply some optimizations. Firstly I didn't and I rendered the world using a vbo in which I stored a cube model and I drow all blocks of the worlds and off course it caused lag if there were too many blocks. Then I decided to draw the world face by face and check if a face is hidden from another one. This concept is simple if I have the world made only by cubes of the same size, like this Blue and black block are two blocks of the same size and the red face is the face to ignore since is hidden (overlapped) by another opaque face. As I said if I want to make blocks of different sizes (scale) position rotation but by always drawing them from faces, the matter is different since I can't know if a face is completely visible or not. Here's an image of a normal block with a "custom" block on it Blue block is the custom block, the black a "normal" block and the red is the face overlapped by the biggest one (then it should be ignored during rendering). Here the rotation is null but if there's no way to check rotated faces I can simply ignore it and draws all rotated blocks by default (I don't rotate all the world lol)... that's not what I'd like to do but if there's no way or the way is too difficult... Anyway, finally, how can I check (using GL functions or doing it in my code) if a face is hidden and to ignore it on rendering? I forgot to say that another optimization I did is if a block is hidden (has a block relative to each face) by other blocks I don't draw it.


How to pass depth buffer from OGRE to CUDA? I am using OGRE for rendering some objects. At every frame, I would like to pass the resulting depth buffer to CUDA for running some kernels on it and computing a result. How can I achieve this? How do I get access to depth buffer in OGRE? How do I pass this to CUDA for processing? I do not need to write to the depth buffer in the CUDA kernels, it can be read only.


OpenGL Black rectangle in rendering texture I create textures (for example, I just fill the texture color), and render their. But, for some reason, to the upper edge added black rectangle. Screenshot var Textures array of GLuint procedure LoadTexture(const TextureID Byte var Texture GLuint) var w, h Cardinal Data PByteArray begin if TextureID 0 then begin w 512 h 512 end else begin w 128 h 64 end GetMem(Data, w h 3) if TextureID 0 then FillChar(Data , w h 3, 204) else FillChar(Data , w h 3, 102) glBindTexture(GL TEXTURE 2D, Texture) glTexParameteri(GL TEXTURE 2D, GL TEXTURE MAG FILTER, GL NEAREST) glTexParameteri(GL TEXTURE 2D, GL TEXTURE MIN FILTER, GL LINEAR) glTexImage2D(GL TEXTURE 2D, 0, GL RGB8, w, h, 0, GL RGB, GL UNSIGNED BYTE, Data) FreeMem(Data, w h 3) Data nil end procedure glInit begin glEnable(GL TEXTURE 2D) SetLength(Textures, 2) glGenTextures(1, Textures 0 ) LoadTexture(0, Textures 0 ) glGenTextures(1, Textures 1 ) LoadTexture(1, Textures 1 ) glClearColor(1, 1, 1, 0) glShadeModel(GL SMOOTH) glClearDepth(1) glDisable(GL DEPTH TEST) glHint(GL PERSPECTIVE CORRECTION HINT, GL NICEST) glViewport(0, 0, 800, 600) glMatrixMode(GL PROJECTION) glLoadIdentity glOrtho(0, 800, 600, 0, 0, 1) glMatrixMode(GL MODELVIEW) glLoadIdentity end procedure glDraw begin glClearColor(1, 1, 1, 0) glClear(GL COLOR BUFFER BIT or GL DEPTH BUFFER BIT) glBindTexture(GL TEXTURE 2D, Textures 0 ) glBegin(GL QUADS) glTexCoord2f(0, 0) glVertex2f(0, 0) glTexCoord2f(1, 0) glVertex2f(512, 0) glTexCoord2f(1, 1) glVertex2f(512, 512) glTexCoord2f(0, 1) glVertex2f(0, 512) glEnd glBindTexture(GL TEXTURE 2D, Textures 1 ) glBegin(GL QUADS) glTexCoord2f(0, 0) glVertex2f(128, 64) glTexCoord2f(1, 0) glVertex2f(256, 64) glTexCoord2f(1, 1) glVertex2f(256, 128) glTexCoord2f(0, 1) glVertex2f(128, 128) glEnd end


Is it reasonable to use a 2D texture as a lookup table in GLSL I need a lookup table in a shader. The input values would be color values and the output other color values. Something like uniform float lut 256 color vec3(lut int(color.r 255.) , lut int(color.g 255.) , lut int(color.b 255) ) does what I need but certain implementations of OpenGL ES do not allow arrays with variable indexing so finally I've arrived to the conclusion that the most portable way is to have a 2D texture as the LUT. A texture of 256x256 could store many different lookup tables, each one (256 entries) in a single row. In order to load a row in the texture (c ) I would use glTexSubImage2D(GL TEXTURE 2D, 0, 0, 0, 256, 1, GL LUMINANCE, GL UNSIGNED BYTE, data) to store a table in the first row (I assume that internally in the texture I'd have the value repeated in R, G and B) To fetch the LUT in the fragment shader I'd use texture2D(lut,vec2(index, constRow)) (index in the range 0 1 and constRow 0 being the row in the texture where it is stored the lut). Is that a reasonable way to implement that? Update In order to fetch values in the texture LUT you need normalized indexes (0.0 1.0), so to access row 7 I have to index it as texture2D(lut, vec2(index, 7. 255.)) From what I see the result is (or may be) an interpolation with the two other consecutive rows.


How do I wrap textures inside shader GLSL? I'm trying out GLSL and one of the problems I'm facing is wrapping a random texture sampler in the shader. Searching for answers on the web first, this leads me to using these glTexParameter() GL TEXTURE WRAP S GL REPEAT GL TEXTURE WRAP T GL REPEAT I'm not sure where to put this or how to use it. I'm using a custom engine for this shader and I would assume I could wrap the texture in the shader. My main concern on this is my final output render having left and bottom artifacts. I got some previous advise it has to do with wrapping a random texture that is used for noise if that helps in my case.


How to achieve light that changes color mid way? I thought of creating light sources, and some colored windows. Now, the windows are semi transparent. How could I make it so that when the light (say, pure white) hits the glass and continues through it, but changes the color to the same color as the glass it passed? I know the effect described here can be faked by using area lights on the "colored" side of the window, but what if I just wanted to have one white point light?


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


Shadowmapping with multiple light sources I am using shadow mapping to add shadows to my world. Currently, I use one lightsource, which means I have to draw my world twice once in the lightview, once in the camera view. I want to add more light sources to the world, I want at least 2 sources, maybe 3 or 4. My world geometry is large, roughly 1M triangles, so drawing them comes at a large cost. Are there any shortcuts I can take to avoid drawing the geometry for every light source? Would it be possible to write to multiple depth textures in a single pass? E.g. pass several lightview matrices to a vertex shader and somehow write several framebuffers in one go? I am using OpenGL core profile. What I've tried I looked at Multiple Render Targets, but it seems that every attached buffer will share the same vertex transformation, which would not help in my situation every light view has a different transformation.


glTranslate, how exactly does it work? I have some trouble understanding how does glTranslate work. At first I thought it would just simply add values to axis to do the transformation. However then I have created two objects that would load bitmaps, one has matrix set to GL TEXTURE public class Background float vertices new float 0f, 1f, 0.0f, 4f, 1f, 0.0f, 0f, 1f, 0.0f, 4f, 1f, 0.0f .... private float backgroundScrolled 0 public void scrollBackground(GL10 gl) gl.glLoadIdentity() gl.glMatrixMode(GL10.GL MODELVIEW) gl.glTranslatef(0f, 0f, 0f) gl.glPushMatrix() gl.glLoadIdentity() gl.glMatrixMode(GL10.GL TEXTURE) gl.glTranslatef(backgroundScrolled, 0.0f, 0.0f) gl.glPushMatrix() this.draw(gl) gl.glPopMatrix() backgroundScrolled 0.01f gl.glLoadIdentity() and another to GL MODELVIEW public class Box float vertices new float 0.5f, 0f, 0.0f, 1f, 0f, 0.0f, 0.5f, 0.5f, 0.0f, 1f, 0.5f, 0.0f .... private float boxScrolled 0 public void scrollBackground(GL10 gl) gl.glMatrixMode(GL10.GL MODELVIEW) gl.glLoadIdentity() gl.glTranslatef(0f, 0f, 0f) gl.glPushMatrix() gl.glMatrixMode(GL10.GL MODELVIEW) gl.glLoadIdentity() gl.glTranslatef(boxScrolled, 0.0f, 0.0f) gl.glPushMatrix() this.draw(gl) gl.glPopMatrix() boxScrolled 0.01f gl.glLoadIdentity() Now they are both drawn in Renderer.OnDraw. However background moves exactly 5 times faster. If I multiply boxScrolled by 5 they will be in sinc and will move together. If I modify backgrounds vertices to be float vertices new float 1f, 1f, 0.0f, 0f, 1f, 0.0f, 1f, 1f, 0.0f, 0f, 1f, 0.0f It will also be in sinc with the box. So, what is going under glTranslate?


How is animation handled in non immediate OpenGL? I'm a newbie to modern OpenGL. I'm comfortable with the immediate OpenGL methodology, but I've never done any serious use of VBOs. My question is about animation. In immediate mode, to achieve animation you just have to stream different vertex positions (interpolated from keyframes) in object space. How is this achieved in non immediate OpenGL? Obviously, uploading fresh VBO data for each frame is sure going to hog the graphics bus. I haven't found any literature about the modern way to do it. Thinking about it, I came to several options Attributes animation as a 3d offset. For each frame, a different (possible interpolated) offset attribute is passed for each vertex, applied to the same vertex each keyframe. Indices storing keyframes as absolute vertices and accesing them through indexing, using a different set of vertices for every keyframe. I find this approach impossible, since you can't access adjacent keyframes and therefore can't interpolate between them. Also, seems like a bad idea for procedural animation. Texture this might be very stretchy but sounds like a good solution for me. Again, animation is thought as an xyz offset for each vertex. Each keyframe can be stored in a 1D texture where the dimension maps to vertexID.If I'm not mistaken, in OpenGL 4.0 you can access textures from any shader, so you could read this texture from the vertex shader and apply each vertex transformation. A 2D texture could hold several frames. You still perform interpolation (and if interpolation works for textures outside of fragment shader, which I'm not sure of, you can linearly interpolate for free!) This could be applied to more complex animation systems like bone animation without much effort. Am I overthinking this? Can anyone shed some light?


Loading models with opengl I'm developing a video game using OpenGL as graphic API and C programming language, and I'm creating all models with blender. One question I have is how you deal with models (vertices), I mean, once you have created a model and want to load them with OpenGL you use hard coded or a software module to load them on runtime?.


OpenGL Applications Bring computer to halt Whenever I run any application that utilizes the OpenGL interface, my entire computer comes to a halt, but it doesn't do this when it utilizes the DirectX interface. I run both Linux (Ubuntu 15.10) and Windows 10 so this isn't exactly caused by the operating system. I'm running the latest drivers from NVidia and both OS's are completely up to date. This is happening on a Dell Precision M6300 laptop (Core 2 Dou 2.5ghz, NVidia Quadro FX 1600M, 4gb ram) and although it's a bit old it should be completely capable of rendering a blank OpenGL window using GLFW, however it slows down my entire computer (every application starts freezing to where it becomes unusable until the application is closed). This happens in games like Left4Dead, Half life 2, etc., but also in my own OpenGL programs. The same programs and games do not have the same effect on my desktop (although much better hardware, a blank OpenGL window shouldn't matter). Any help would be greatly appreciated, thank you. Also my apologies if I left out any vital information or made a confusing question. Just ask me to clarify or add something and I shall. Added the code for the blank OpenGL window in question include lt stdio.h gt include lt stdlib.h gt include lt GL glew.h gt include lt GLFW glfw3.h gt include lt glm glm.hpp gt using namespace glm int main(int argc, char argv ) if ( !glfwInit() ) fprintf(stderr, "Failed to initialize GLFW n") return 1 glfwWindowHint(GLFW SAMPLES, 4) 4x AA glfwWindowHint(GLFW CONTEXT VERSION MAJOR, 3) GL 3.3 glfwWindowHint(GLFW CONTEXT VERSION MINOR, 3) glfwWindowHint(GLFW OPENGL FORWARD COMPAT, GL TRUE) glfwWindowHint(GLFW OPENGL PROFILE, GLFW OPENGL CORE PROFILE) GLFWwindow window window glfwCreateWindow(1024, 768, "OpenGL Tutorial", NULL, NULL) if (window NULL) fprintf(stderr, "Failed to create OpenGL Window.") return 1 glfwMakeContextCurrent(window) glewExperimental true if (glewInit() ! GLEW OK) fprintf(stderr, "Failed to initiate the glew context!") return 1 glfwSetInputMode(window, GLFW STICKY KEYS, GL TRUE) do glfwSwapBuffers(window) glfwPollEvents() while (glfwGetKey(window, GLFW KEY ESCAPE ) ! GLFW PRESS amp amp glfwWindowShouldClose(window) 0)


How do I implement object picking, using OBB in OpenGL? I am trying to make 3D drawing software. I wanted to have the drag feature so I am using object picking using the OBB algorithm. I am facing problems in understanding the algorithm, and my implementation thus is having bugs. How do I implement object picking, using OBB in OpenGL? As I am new to OpenGL (free glut library), a step by step explanation would be helpful.


What is GL MAX COMBINED TEXTURE IMAGE UNITS? I am a beginner in OpenGL. I am learning about textures in OpenGL. What I don't understand is how to determine how many texture units are in the GPU. I heard someone said that you can see how many texture units by writing the following code. int total units glGetIntegerv(GL MAX COMBINED TEXTURE IMAGE UNITS, amp total units) std cout lt lt total units lt lt ' n' the result is 192 Is there 192 texture units in my GPU? In documentation, it says GL MAX COMBINED TEXTURE IMAGE UNITS params returns one value, the maximum supported texture image units that can be used to access texture maps from the vertex shader and the fragment processor combined. If both the vertex shader and the fragment processing stage access the same texture image unit, then that counts as using two texture image units against this limit. The value must be at least 48. See glActiveTexture. So I wanted to know how many texture units can be used to access texture maps from the vertex and fragment shaders. So I wrote and run the following code. int vertex units, fragment units glGetIntegerv(GL MAX VERTEX TEXTURE IMAGE UNITS, amp vertex units) std cout lt lt vertex units lt lt quot n quot the result is 32 glGetInteferv(GL MAX TEXTURE IMAGE UNITS, amp fragment units) std cout lt lt fragment units lt lt quot n quot the result is also 32 So 32 32 64. But why does GL MAX COMBINED TEXTURE IMAGE UNITS shows me the result of 192? I think I am missing something. What do I need to calculate to get 192? And also, in OpenGL, why are there only GL TEXTURE0 to GL TEXTURE31 macros? I think these macros are for each shaders. Am I right?


Render specific part of a texture in OpenGL (2D Sprite Sheet) I've looked at this answer to find out how to render just a part of a texture C Opengl render part of an image I tried that, but the problem is, this is how I render my texture glBegin(GL QUADS) glTexCoord2f(0, 0) glVertex2f(x, y) glTexCoord2f(1, 0) glVertex2f(x w, y) glTexCoord2f(1, 1) glVertex2f(x w, y h) glTexCoord2f(0, 1) glVertex2f(x, y h) glEnd() I tried doing this to render the top left quarter glBegin(GL QUADS) glTexCoord2f(0, 0) glVertex2f(x, y) glTexCoord2f(0.5, 0) glVertex2f(x w, y) glTexCoord2f(0.5, 0.5) glVertex2f(x w, y h) glTexCoord2f(0, 0.5) glVertex2f(x, y h) glEnd() But it just totally messes up and makes my texture bigger and cut off. What I want is to just draw a part, like you would on a sprite sheet. I've been messing around with those lines for awhile and I just can't seem to find out how to do what I want. I've been messing around with this yeah i know this math is crappy and weird but im trying EVERYTHING at this point, it draws until the dcw (width) just fine but i cant seem to integrate cx cy... double dcw double(cw) double(w) double dch double(ch) double(h) double dcx double(cx) double(dcw) double dcy double(cy) double(dch) std cout lt lt "dcw " lt lt dcx lt lt " n" lt lt "dch " lt lt dcy lt lt " n" glBegin(GL QUADS) bottom right glTexCoord2f(0, 0) glVertex2f(cx, cy) top right glTexCoord2f(dcw, 0) glVertex2f(cx cw, cy) top left glTexCoord2f(dcw, dch) glVertex2f(cx cw, cy ch) bottom left glTexCoord2f(0, dch) glVertex2f(cx, cy ch)


Shader Calculate depth relative to Object I am trying to calculate depth relative to the object.Here is a good solution to retrieve depth relative to camera Depth as distance to camera plane in GLSL varying float distToCamera void main() vec4 cs position glModelViewMatrix gl Vertex distToCamera cs position.z gl Position gl ProjectionMatrix cs position With this example the depth is relative to the camera.But I would like get the depth relative to the object. I would like the same depth and value if I am near from the object or if I am far. Here is an example of what I am trying to achieve. On the left you can see that the depth is relative to the camera. And on the right even if the camera moves back from the object, the depth remains the same because it is dependant to the object.


Camera rotation around point, but without centering Let's say i have the following Point somewhere in space Camera with position and orientation (up, right, forward) I want to rotate camera around the point, but also keep this point in same place on screen. So, if point was on (32, 32) on window, after rotation i want it to still be on (32, 32). I've seen How can I orbit a camera about it 39 s target point? , and it was somewhat helpful. I needed code to rotate point around arbitrary axis (camera's up and right), so i used this resource. Problem is, i got something like numerical errors and my camera started to wander weirdly when rotating around camera's both up and right (it seems fine when i rotate only around one of them). I tested my implementation with code Matrix m1 MatrixRotate(Vector( 1, 1, 1), 33) Matrix m2 MatrixRotate(Vector( 1, 1, 1), 33) Vector a Vector( 1, 1, 1) Vector c a c m1 c c m2 c printf(" f f f f n", c.x, c.y, c.z, c.w) And got 1.028036 0.960396 1.124331 0.000000 It worked fine when rotation axis was something 'normal' like (1, 0, 0) or (0, 0, 1). So, how else can i rotate camera around point, while keeping said point in same point on screen?


How can I efficiently render lots of 2D quads? I have lots of 2D quads. I write their local vertex position info to a buffer (accompanied with a world transform matrix) which gets sent to the render thread. I then pass the world transform matrix as a uniform into the vertex shader which applies itself to each vertex and works fine. I however have to make a call to glDrawElements() for each quad I want to render because each one has a different world transform. What is the most efficient way for me to render all of these quads? Should I do what I'm already doing, or should I calculate the world position for each vertex on the CPU before I write them to the buffer, so I can attempt to batch more quads into a single glDrawElements() call? Or is there another approach?


Why nearby triangles tend to disappear? I've just enabled back face culling and I'm noticing a weird behavior when all vertices of my triangle is outside the view and 2 of them is behind me (I think) the triangle disappears. So to see it, here is a GIF. I suspect the projection matrix reverses the order of the two vertices when they fall behind me, and changes the winding of my triangle. But it's unclear why does the triangles disappear only if all vertices out of view... How can I work around this problem, if possible? I develop on Linux if that matters. UPDATE It's pointed out it might not be due to the back face culling. I disabled it and I can indeed reproduce it. The cubes are 20 20 and the vertical field view is 90 . Its vertical apparent size roughly fills the window. UPDATE 2 Ok I'll post the relevant part of the code, projection and view matrixes are set up using my own functions void createViewMatrix( GLfloat matrix 16 , const Vector3 forward, const Vector3 up, const Vector3 pos ) Setting up perpendicular axes Vector3 rright Vector3 rup up Vector3 rforward forward vbonorm( amp rright, amp rup, amp rforward) Orthonormalization (right is computed from scratch) Filling the matrix matrix 0 rright.x matrix 1 rup.x matrix 2 rforward.x matrix 3 0 matrix 4 rright.y matrix 5 rup.y matrix 6 rforward.y matrix 7 0 matrix 8 rright.z matrix 9 rup.z matrix 10 rforward.z matrix 11 0 matrix 12 vdp(pos, amp rright) matrix 13 vdp(pos, amp rup) matrix 14 vdp(pos, amp rforward) matrix 15 1 void createProjectionMatrix( GLfloat matrix 16 , GLfloat vfov, GLfloat aspect, GLfloat near, GLfloat far ) GLfloat vfovtan 1 tan(RAD(vfov 0.5)) memset(matrix, 0, sizeof( matrix) 16) matrix 0 vfovtan aspect matrix 5 vfovtan matrix 10 (near far) (near far) matrix 11 1 matrix 14 (2 near far) (near far) Projection matrix set up with this call createProjectionMatrix(projMatrix, VERTICAL FOV, ASPECT RATIO, Z NEAR, 10000) (VERTICAL FOV 90, ASPECT RATIO 4.0 3, Z NEAR 1) Level drawing is simply void drawStuff() GLfloat projectView 16 glClearColor(0, 0, 0, 1) glClear(GL COLOR BUFFER BIT GL DEPTH BUFFER BIT) createViewMatrix(viewMatrix, amp camera.forward, amp camera.up, amp camera.pos) multiplyMatrix(projectView, viewMatrix, projMatrix) lt Row mayor multiplication. glUniformMatrix4fv(renderingMatrixId, 1, GL FALSE, projectView) bailOnGlError( FILE , LINE ) renderLevel( amp testLevel) Cubes are rendered wall by wall (optimizing this will be another story) for (j 0 j lt 6 j ) glBindTexture(GL TEXTURE 2D, cube gt wallTextureIds j ) bailOnGlError( FILE , LINE ) glDrawElements(GL TRIANGLE FAN, 4, GL UNSIGNED INT, (void )(sizeof(GLuint) 4 j)) bailOnGlError( FILE , LINE ) glUniform4f(extraColorId, 1, 1, 1, 1) bailOnGlError( FILE , LINE ) Vertex shader version 110 attribute vec3 position attribute vec3 color attribute vec2 texCoord varying vec4 f color varying vec2 f texCoord uniform mat4 renderingMatrix void main() gl Position renderingMatrix vec4(position, 1) f color vec4(color, 1) f texCoord texCoord Fragment shader version 110 varying vec4 f color varying vec2 f texCoord uniform sampler2D tex uniform vec4 extraColor void main() gl FragColor texture2D(tex, f texCoord) vec4(f color) extraColor The depth buffer simply set up by enabling it.


Java OpenGL Perspective matrix not working I'm trying to render a simple triangle with OpenGL in Java using LWJGL3. Everything is working great, but the projection matrix (perspective) is not working. In C I just used to apply the glm perspective() method which works just great. But in Java, I implemented it myself since there are no libraries like GLM handling it. So here the code for the perspective in Java public mat4 perspective(float fov, float aspectRatio, float zNear, float zFar) mat4 perspective new mat4() float halfTanFov (float) Math.tan(Math.toRadians(fov 2)) float range zNear zFar perspective.m00 1f halfTanFov aspectRatio perspective.m11 1f halfTanFov perspective.m22 (zFar zNear) range perspective.m23 1 perspective.m32 (2f zFar zNear) range return perspective Of course I tested this multiplication and a compared a result with my TI output, and it worked great. Other information, the default constructor for the mat4 class is putting all the values to 0. here is the code public void setZero() m00 0 m01 0 m02 0 m03 0 m10 0 m11 0 m12 0 m13 0 m20 0 m21 0 m22 0 m23 0 m30 0 m31 0 m32 0 m33 0 the viewMatrix() in the other hand is working great. It's a simple implementation of the lookAt() method. So when it's lookAtMatrix modelMatrix position where the position is a vec4 the result is good. But when I try to add the projection matrix for the MVP perspective lookatMatrix model position the result is nothing. Here where I do it in the code public mat4 getViewProjection() mViewProjection MatrixTransform.getInstance().lookAt(mPosition, mPosition.add(mDirection), mUp) return mViewProjection public mat4 getMVP(mat4 model) return mPerspective.mult(getViewProjection()).mult(model) And here is my simple GLSL shader (for the vertex shader ) version 430 layout(location 0) in vec3 position uniform mat4 MVP void main(void) gl Position MVP vec4(position, 1) I tried other implementation of the perspective without success, so I guess my mistake is somewhere else, but sadly enough, I can't figure out where. If someone could help, it'd be great ! thank you. If you other informations, please ask me and I'll post it. EDIT Here is how I put a mat4 into a uniform public void uniform(String variableName, mat4 matrix) int loc glGetUniformLocation(mId, variableName) FloatBuffer buffer BufferUtils.createFloatBuffer(16) matrix.putIntoBuffer(buffer) buffer.flip() glUniformMatrix4(loc, false, buffer) and the method putIntoBuffer() public void putIntoBuffer(FloatBuffer buffer) buffer.put(m00) buffer.put(m01) buffer.put(m02) buffer.put(m03) buffer.put(m10) buffer.put(m11) buffer.put(m12) buffer.put(m13) buffer.put(m20) buffer.put(m21) buffer.put(m22) buffer.put(m23) buffer.put(m30) buffer.put(m31) buffer.put(m32) buffer.put(m33)


OpenGL glVertexAttribFormat vs glVertexAttribPointer I am attempting to change my code from using glVertexAttribPointer to glVertexAttribFormat as I have heard it s more efficiend since it reduces binding calls overhead. I have 2 versions of the code, one working one not. The code looks like glGenBuffers(1, amp tvbo1) glBindBuffer(GL ARRAY BUFFER, tvbo1) glObjectLabel(GL BUFFER, tvbo1, 21, " "Mesh Vertex Buffer "") glBufferData(GL ARRAY BUFFER, sizeof(vec3) triangle.size(), triangle.data(), GL STATIC DRAW) glGenBuffers(1, amp tvbo2) glBindBuffer(GL ARRAY BUFFER, tvbo2) glObjectLabel(GL BUFFER, tvbo2, 22, " "Mesh Normals Buffer "") glBufferData(GL ARRAY BUFFER, sizeof(vec3) ns.size(), ns.data(), GL STATIC DRAW) glEnableVertexAttribArray(0) glVertexAttribPointer(0, 3, GL FLOAT, GL FALSE, 0, 0) glVertexAttribFormat(0, 3, GL FLOAT, GL FALSE, 0) comment glVertexAttribBinding(0,0) comment glEnableVertexAttribArray(1) glVertexAttribPointer(1, 3, GL FLOAT, GL FALSE, 0, 0) glVertexAttribFormat(1, 3, GL FLOAT, GL FALSE, 0) comment glVertexAttribBinding(1,1) comment GLuint ptrs tvbo1, tvbo2 GLintptr offsets 0,0 int strides 0,0 glBindVertexBuffers(0, 2, ptrs, offsets, strides) comment So whenever you see a comment. That's to denote that in the other version that line is commented out. The version that does work uses glVertexAttribPointer(0, 3, GL FLOAT, GL FALSE, 0, 0) The version that does not work uses glVertexAttribFormat(0, 3, GL FLOAT, GL FALSE, 0) comment glVertexAttribBinding(0,0) comment glBindVertexBuffers(0, 2, ptrs, offsets, strides) comment The difference between working and not working is having a purple triangle vs having a black screen. It seems that the error comes from the line glBindVertexBuffers(0, 2, ptrs, offsets, strides) comment As having that line present results in a black screen regardless of the rest of the code.


How to organize passing data to shaders in cross API render system? I try to create rendering system that supports DirectX and OpenGL. I am trying to create class for constant buffer, but DirectX constant buffers and OpenGL uniform buffers have different memory organisation rules. Is there any way to to achieve the compatibility between DirectX and std140 from OpenGL? Or probably will it be better to choose a other way to create abstraction of constant buffers for shaders? And how developers solve problem of passing data to shaders effectively in serious engines?


How costly is an OpenGL draw call, and how do I optimise them? How costly is a draw call in OpenGL? What are the ways to reduce the number of draw calls? I have seen people using glMapBufferRange, but I can't figure out how it improves the performance. How much impact do draw calls have on the overall performance of a program?


Impact of variable length loops on GPU shaders Its popular to render procedural content inside the GPU e.g. in the demoscene (drawing a single quad to fill the screen and letting the GPU compute the pixels). Ray marching is popular This means the GPU is executing some unknown number of loop iterations per pixel (although you can have an upper bound like maxIterations). How does having a variable length loop affect shader performance? Imagine the simple ray marching psuedocode t 0.f while(t lt maxDist) p rayStart rayDir t d DistanceFunc(p) t d if(d lt epsilon) ... emit p return How are the various mainstream GPU families (Nvidia, ATI, PowerVR, Mali, Intel, etc) affected? Vertex shaders, but particularly fragment shaders? How can it be optimised?


How much is atomicAdd slower than an atomic counter? I am considering replacing an atomic counter in my shader code with a SSBO an atomicAdd operation. What I need to know is the difference in performance of these two. I know the atomic counter executes in roughly 3 clock cycles on my Geforce 840m. The reason behind this is that I would like to add an arbitrary number to the counter rather than just increment by 1.


Plotting 2D map coordinates to OpenGL 3D projection I m trying to convert a 2D map created in my map editor to a 3D plotting with OpenGL. This is my map generated in my map editor Those vertices are relative to my Cartesian origin world coordinate (top up of the picture) and I m applying this formula to convert it to an OpenGL object coordinate World size 800x600 x (X 800) 0.5 y (Y 600) 0.5 Getting this result (First object face) 0.48625, 0.068333333 0.12625, 0.07 0.12875, 0.481666667 0.4875, 0.486666667 Plotting this vertex buffer in OpenGL, I got a very weird result. So how can I get a 3D model from those vertex positions? Like this picture I m rendering OpenGL in triangles mode and using this example as the start point https github.com JoeyDeVries LearnOpenGL blob master src 1.getting started 7.4.camera class camera class.cpp Edit Using the conversion formula the Earcut tessellation (https github.com mapbox earcut.hpp), I've finally got this rectangle rendering correctly inside OpenGL. With two planes with just the Z axis different, now the problem is how to render its laterals since Earcut just works with 2D coordinates...


How can I create an orthographic display that handles different screen dimensions? I'm trying to create an iPad iPhone game using GLES2.0 that contains a 3D scene with a heads up display GUI overlaid on the top. However, this problem would also apply if I were to port my game to a computer and run the game in a resizable window, or allow the user to change screen resolutions... When trying to make the 2D GUI HUD work I've made the assumption that all I'm really doing is drawing a load of 2D textured 'quads' on the screen and am trying to treat the orthographic projection as an old style 2D display with 0,0 in the upper left and screenWidth,ScreenHeight in the lower right. This causes me all sorts of confusion when I rotate my ipad into Landscape mode since I can't work out what to put into my projection and modelview matrices to turn everything around the right way. It also gets messy if I want to support the iPad's large screen, an iPhone or a Retina display since I have to then draw three sets of textures for everything and work out which ones to use. Should I be trying to map the 2D OpenGL co ords 1 1 with the screen? While typing out this question it occurs to me that I could keep my origin in the centre, still running 1 1 along the axes. This would let me scale my 2D content appropriately on the different screen sizes, but wouldn't I end up with the textures being scaled and possibly losing quality? I'm using OpenGLES 2.0 and have a matrix library that has equivalents to the GLES1.1 glOrthof() and glFrustrum() calls.


Is learning OpenGL2.1 today a bad idea? Possible Duplicate Is learning OpenGL 2.1 useless today? This question was asked around 2 years ago and i have well read the answers to it, but that was 2 years ago, i would like to know if it's a bad idea for me to learn OpenGL2.1 today. I bought the OpenGL superbible (4th edition) and not the 5th because some user in the ratings said that it was much better and i believed him. But now i'm affraid that was a long time ago. Thanks for all your feedback!


Local shape color blending I am trying to implement this in Unity 4 Pro. But I am stuck in the blending part. I don't understand how you could blend multiples textures colors using multiples volumes on an object. How could you access those volumes in the shader and check for "collision"? It's seems to be very similar to vertex pixel lighting. But maybe I am wrong. Here is the simple effect I am trying to create.


GLSL associating multiple uniform samplerBuffers At the moment I'm not sure how my VBO and TBO associate with a specific uniform samplerBuffer in my shader, I have not linked them using the location or the vbo tbo together. It seems to still work though, but now that I am using multiple samplerBuffers, how do I establish to link between a specific TBO and the uniform. Do I need to use glUniformX?


Where did I lose vertex binding? I make OpenGL render framework for my bachelor graduate work. I created simple Model and Shader classes. But when I tried to render some vertices, they do not render. I saw with an OpenGL profiler, that I haven't vertex data, but in code I bind it. There's my main class GLfloat vertex positions 0.0f, 0.5f, 1.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f GLchar vertexShader (GLchar ) " version 150 n" " n" "in vec2 position n" " n" "void main() n" " n" " gl Position vec4(position, 0.0, 1.0) n" " " GLchar fragmentShader (GLchar ) " version 400 core n" " n" "out vec4 fColor n" " n" "void main() n" " n" " fColor vec4(0.5, 0.4, 0.8, 1.0) n" " " static const GLfloat vertex colors 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f Shader shader shader.CompileShader(Shader ShaderType Fragment, fragmentShader) shader.CompileShader(Shader ShaderType Vertex, vertexShader) glBindFragDataLocation( shader.GetProgram(), 0, "fColor") shader.Link() Texture texture((GLfloat ) vertex colors, 16) Model model (vertex positions, amp shader, amp texture) while (!glfwWindowShouldClose(window)) static const float black 0.2f, 0.3f, 1.0f, 1.0f glClearBufferfv(GL COLOR, 0, black) shader.Bind() model.Draw() glfwPollEvents() glfwSwapBuffers(window) And my model class void Model Draw() glBindVertexArray( vao) glBindBuffer(GL ARRAY BUFFER, vbo) glDrawArrays(GL TRIANGLES, 0, 3) Model Model(GLfloat meshVert , int m size, GLuint vertexInd , int v size, Shader material, Texture texture) glGenVertexArrays(1, amp vao) glBindVertexArray( vao) glGenBuffers(1, amp vbo) glBindBuffer(GL ARRAY BUFFER, vbo) glBufferData(GL ARRAY BUFFER, sizeof(GLfloat) m size, meshVert, GL STATIC DRAW) GLint posAttrib glGetAttribLocation( material gt GetProgram(), "position") glEnableVertexAttribArray((GLuint) posAttrib) glVertexAttribPointer((GLuint) posAttrib, 2, GL FLOAT, GL FALSE, 5 sizeof(GLfloat), 0) GLint colAttrib glGetAttribLocation( material gt GetProgram(), "color") glEnableVertexAttribArray((GLuint) colAttrib) glVertexAttribPointer((GLuint) colAttrib, 3, GL FLOAT, GL FALSE, 5 sizeof(GLfloat), (void )(2 sizeof(GLfloat))) P.S. OpenGL profiler breaks on command glDrawArrays, but when I saw data info, it was empty. That's why I think I lost some data bind. P.S.S System macOS Sierra, Intel HD 6000.


Why does the lighting change the objects color? I have a code that draws a sphere. Without lighting it is white, but if I enable lighting, it's drawn in gray. I don't know why the sphere changed it's color include lt GL gl.h gt include lt GL glu.h gt include lt GL glut.h gt void init(void) GLfloat mat specular 1.0, 1.0, 1.0, 1.0 GLfloat mat shininess 50.0 GLfloat light position 1.0, 1.0, 1.0, 0.0 glClearColor (0.0, 0.0, 0.0, 0.0) glShadeModel (GL SMOOTH) glMaterialfv(GL FRONT, GL SPECULAR, mat specular) glMaterialfv(GL FRONT, GL SHININESS, mat shininess) glLightfv(GL LIGHT0, GL POSITION, light position) glEnable(GL LIGHTING) glEnable(GL LIGHT0) glEnable(GL DEPTH TEST) void display(void) glClear (GL COLOR BUFFER BIT GL DEPTH BUFFER BIT) glutSolidSphere (1.0, 20, 16) glFlush () void reshape (int w, int h) glViewport (0, 0, (GLsizei) w, (GLsizei) h) glMatrixMode (GL PROJECTION) glLoadIdentity() if (w lt h) glOrtho ( 1.5, 1.5, 1.5 (GLfloat)h (GLfloat)w, 1.5 (GLfloat)h (GLfloat)w, 10.0, 10.0) else glOrtho ( 1.5 (GLfloat)w (GLfloat)h, 1.5 (GLfloat)w (GLfloat)h, 1.5, 1.5, 10.0, 10.0) glMatrixMode(GL MODELVIEW) glLoadIdentity() int main(int argc, char argv) glutInit( amp argc, argv) glutInitDisplayMode (GLUT SINGLE GLUT RGB GLUT DEPTH) glutInitWindowSize (500, 500) glutInitWindowPosition (100, 100) glutCreateWindow (argv 0 ) init () glutDisplayFunc(display) glutReshapeFunc(reshape) glutMainLoop() return 0


(LWJGL) Resize window content I am having a little issue with my game trying to get the screen to draw a ton larger. I am going for a retro type of feel for my game and I believe that this would help with that. I am basically trying to take a small area (example 100x177) and draw it 9 times the original size while still keeping the nearest neighbor. The image below shows what I am trying to achieve. (image taken from http forums.tigsource.com index.php?topic 27928.0). I have been trying to set the current render area to an FrameBuffer then draw the Frame Buffer larger on the window. I have not been able to find any example code or how I would go about doing that. Thank you in advance for the help. EDIT Added sample code This code is in the same method where I initialize OpenGL fboID GL30.glGenFramebuffers() GL30.glBindFramebuffer(GL30.GL FRAMEBUFFER, fboID) colID GL11.glGenTextures() GL11.glBindTexture(GL11.GL TEXTURE 2D, colID) GL11.glTexImage2D(GL11.GL TEXTURE 2D, 0, GL11.GL RGB, scaleWidth, scaleHeight, 0, GL11.GL RGB, GL11.GL UNSIGNED BYTE, (ByteBuffer)null) GL11.glTexParameteri(GL11.GL TEXTURE 2D, GL11.GL TEXTURE MAG FILTER, GL11.GL NEAREST) GL11.glTexParameteri(GL11.GL TEXTURE 2D, GL11.GL TEXTURE MIN FILTER, GL11.GL NEAREST) GL11.glTexParameteri(GL11.GL TEXTURE 2D, GL11.GL TEXTURE WRAP S, GL12.GL CLAMP TO EDGE) GL11.glTexParameteri(GL11.GL TEXTURE 2D, GL11.GL TEXTURE WRAP T, GL12.GL CLAMP TO EDGE) depID GL30.glGenRenderbuffers() GL30.glBindRenderbuffer(GL30.GL RENDERBUFFER, depID) GL30.glRenderbufferStorage(GL30.GL RENDERBUFFER, GL11.GL DEPTH COMPONENT, scaleWidth, scaleHeight) GL30.glFramebufferRenderbuffer(GL30.GL FRAMEBUFFER, GL30.GL DEPTH ATTACHMENT, GL30.GL RENDERBUFFER, depID) GL32.glFramebufferTexture(GL30.GL FRAMEBUFFER, GL30.GL COLOR ATTACHMENT0, colID, 0) drawBuffs BufferUtils.createIntBuffer(1) drawBuffs.put(0, GL30.GL COLOR ATTACHMENT0) GL20.glDrawBuffers(drawBuffs) if(GL30.glCheckFramebufferStatus(GL30.GL FRAMEBUFFER) ! GL30.GL FRAMEBUFFER COMPLETE) System.out.println("Framebuffer not complete!") else System.out.println("Framebuffer is complete!") And this is my render method that the game loop runs (updates at 60fps) clear screen GL11.glClear(GL11.GL COLOR BUFFER BIT GL11.GL DEPTH BUFFER BIT) Start FBO Rendering Code GL30.glBindFramebuffer(GL30.GL FRAMEBUFFER, fboID) Resets the current viewport GL11.glViewport(0, 0, scaleWidth, scaleHeight) Set viewport to be the size of the FBO Clear the FrameBuffer GL11.glClear(GL11.GL COLOR BUFFER BIT) Actual render code! gameMap.render() draw the texture from the FBO GL30.glBindFramebuffer(GL30.GL FRAMEBUFFER, 0) GL11.glViewport(0, 0, scaleWidth scale, scaleHeight scale) GL11.glBegin(GL11.GL QUADS) GL11.glTexCoord2f(0.0f, 0.0f) GL11.glVertex3f(0.0f, 0.0f, 0.0f) GL11.glTexCoord2f(1.0f, 0.0f) GL11.glVertex3f((float)scaleWidth scale, 0.0f, 0.0f) GL11.glTexCoord2f(1.0f, 1.0f) GL11.glVertex3f((float)scaleWidth scale, (float)scaleHeight scale, 0.0f) GL11.glTexCoord2f(0.0f, 1.0f) GL11.glVertex3f(0.0f, (float)scaleHeight scale, 0.0f) GL11.glEnd() Resets the current viewport GL11.glViewport(0, 0, scaleWidth scale, scaleHeight scale) GL11.glMatrixMode(GL11.GL MODELVIEW) GL11.glLoadIdentity() let subsystem paint if (callback ! null) callback.frameRendering() update window contents Display.update() I had to comment out "GL32.glFramebufferTexture(GL30.GL FRAMEBUFFER,GL30.GL COLOR ATTACHMENT0, colID, 0) " because it was throwing a "Function not supported" error. Thanks


Does scaling affect performance in OpenGL? I've never been able to understand the best practice in this context. I usually want to ship my game with as minimum size as possible. So whereever possible, I try to use scaling of my graphics. Let's suppose I have to draw a 1000 X 300 px wall of yellow color in my game. So I usually just use a 3 X 3 px yellow image and stretch it in game (using nearest neighbor filter). Is this the right approach? Let us consider another situation. Let's suppose I wish to render rain in my game. Basically 2 X 30 px blue white gradient streaks . Let us suppose at any time 200 drops max are going to be rendered . Now if I just ship a 2 X 6 px streak with the game and scale it at runtime , will it affect performance? In short, how does scaling affect performance in OpenGL?


glfw resizing causing image scaling I have a quad rendered that extends from the top left of the window to with width of the window that is also 64 pixels high. When I resize the window, from its initial size, the quad and text scales proportionately bigger or smaller in the same say Photoshop can scale a image. What I'm seeking on a basic level is that regardless of how I resize the window, everything drawn remains the same. From the below image, the right side is the initial size and the left side is what happens when I drag the window to be a smaller size. The red bar and text scales with it. This is how Im handling my resizing glfwSetWindowSizeCallback(pWindow, WindowSizeCallback) initialized after context void WindowSizeCallback(GLFWwindow window, int width, int height) glfwSetWindowSize(window, width, height)


How to implement weighted blended order independent transparency in OpenGL? I want to implement weighted blended OIT in my C OpenGL 3D game, but I didn't find any C examples about weighted blended order independent transparency. Paper How to clear accumTexture(framebuffer attachment) to vec4(0)? How to clear revealageTexture(framebuffer attachment) to float(1)?


Wrong texture position on camera move When in my game i move my character, the camera follows it. I have no problem drawing this char when it is moving or moving another char when the camera is still. Now, when i move both of them, the texture position of the second character is wrong, you can see it here Under the hood i round the values before moving the viewport and drawing textures, and i had no problems except in this case. How can i fix this?


How do I render a filled and stroked path using OpenGL? I want to render a 2 dimensional geometric path consisting of B zier curves and straight lines. Paths can be concave. What is the most efficient way to draw this using modern OpenGL? Can I do this with a vertex shader? How should I store the path segments?


How to compose a matrix to perform isometric (dimetric) projection of a world coordinate? I have a 2D unit vector containing a world coordinate (the player's direction), and I want to convert that to screen coordinates (classic isometric tiles). I'm aware I can achieve this by rotating around the relevant axis but I want to see and understand how to do this using a purely matrix approach? Partly because I'm learning 'modern OpenGL' (v2 ) and partly because I will want to use this same technique for other things so need a solid understanding and my math ability is a little lacking. If needed my screen's coordinate system has it's origin at top left with x amp y pointing right and down respectively. Also, my vertex positions are converted to the NDC range in my vertex shader if that's relevant. Language is C with no supporting libraries.


Light Attenuation Formula Derivation I understand that when sampling the brightness of a given point on the surface, a certain cutoff needs to be taken into consideration. Other words, when the light is further away, the intensity decreases. I came across the following formula that is used to compute the aforementioned attenuation 1.0 (1.0 a dist b dist dist) However, I have not been able to find out why and how this formula is derived. From the formula what I can understand is that as the distance get larger, the result will become smaller but how it is derived is beyond me. If distance takes an important role in the above formula, which helps determine the intensity, could we simply ignore a and b from the formula and simply use attenuation 1.0 (1.0 dist) ? Does anyone know how the formula is derived and the importance the values a and b play within the formula? Thanks.


How to render models using a personalized projection matrix? I'm creating a game with a great sprite demand. Out team is considering automatizing the sprite generation using 3D models. The problem is we have a very particular ortographic projection We have already set up a good projection matrix. The problem is none of the 3D renderer of nowadays have an option for using custom matrixes. How is this kind of problem dealt with?