How to change mac opengl version back to mesa A while ago I wanted to use the functionality of opengl 4.5 on my mac, so I installed mesa with macports, and it worked. Recently, however, I tried to use my code again and it said that these versions of opengl are not supported. I tried running glxinfo, and it seems to be telling me that my renderer is the default intel provided renderer. The last time it worked was a reasonably long time ago, and it is likely that the reason for the switch is that when I restarted my computer at some point it switched back to the old version. I don't know exactly when it stopped working. What I want to figure out is how to switch to the mesa version. I checked with macports and even looked at the files internally, and mesa is installed and updated to version 17.1.6, which is the latest version supported by macports. I can't find anything anywhere on how to change the renderer used by my computer. I think it has something to do with libGL maybe, but I can't find any information on how to change or even view libGL's environment variables. How can I switch to the mesa renderer? This is made especially difficult because I can't trust that the information from glxinfo is correct. Both mesa and the default intel renderers have their own versions of glxinfo, which may give information that is different from what the current opengl actually running on the system is. I'm not sure which one I am actually running when I run glxinfo with terminal, or how to find the executable for the mesa version. EDIT I have looked a little more, and it seems like I can control which version is used during context creation and API loading, but that requires manually doing those things, which is not something I really want to do. Currently, I have only tested this with JOGL, and I can't find anything on what it uses to create a context. I don't know if glfw will use the mesa version, but glew did install in the directory for the mesa X version and not the core version that I think JOGL is using. It did work before with JOGL, so clearly there is some system wide default setting that can change this, and I would like to know what that is.


Player being covered by glClearColor? Here is a video of the problem https www.youtube.com watch?v 6vnDOB1Vk4o (this is the game I've been making for fun practice). You notice, in the beginning of the video, I walk off the map and into the black. When I do so the black covers the player. I draw the player last in my code Draw the player amp the world public void draw(Graphics g, Graphics graphics, GameStateManager gsm) glClearColor(0, 0, 0, 0) System.out.println(player.getPlayerX() " " player.getPlayerY()) glViewport( (int)player.getPlayerX() 350, (int)player.getPlayerY() 300, Display.getWidth(), Display.getHeight()) worldGen.worldGenerator() Draw the player to the screen (60, 60) player.draw()


How and when to split draw calls in OpenGL and OpenGL ES My application (with a modernish OpenGL 3.0 and an OpenGL ES 2.0 backend) renders more or less streaming data with up to millions of vertices with different vertex layouts and sizes (some simple, some quite big). Some data is indexed, some is not. I'm currently hitting the problem of draw calls and buffers (index and or vertex) becoming too large, so I need to split them. I have a hard time understanding when and how I should correctly split draw calls. My questions The limits GL MAX ELEMENTS VERTICES and GL MAX ELEMENTS INDICES, according to the docs, tell the application the maximum value for well performing glDrawRangeElements calls. Why is this ONLY for glDrawRangeElements, why not glDrawRangeElementsBaseVertex or even glDrawElements?! This does not make sense to me, because glDrawRangeElements is more or less glDrawElements after all. Also I've see a couple of OpenGL implementations reliably crash when rendering indices above that limit, even with glDrawElements. On the other hand some stackoverflow answers say that the limits are not relevant anymore... What else should I use to decide how to split my draw calls then? What about glDrawArrays? Is there an upper limit (e.g. GL MAX ELEMENTS VERTICES)? For the OpenGL ES 2.0 backend I require the extension "GL OES element index uint" to use indices above the 65k limit. What limits should I choose there for draw call size? I have decided to limit my IBO and VBO sizes to a certain limit (max. 64MB), as there's no way to ask OpenGL about what buffer size I can allocate, else than checking for GL OUT OF MEMORY. That means I have to additionally split according to that buffer size (both IBO and VBO). Is there a better way to check buffer limits? What should be the preferred way to split draw calls? Make them small in the application already, then batch them when rendering? This will lead to lots of duplicate vertices in some case, which is not ideal. Splitting them in the render code can be complicated, because index data has to be analyzed, indices changed or memory copied, but in the end it is the only place where you can be sure all limits are respected... I'd prefer reliable, stable solutions even if they provide lower performance. I'm targeting OpenGL Desktop hardware newer than 2010 and Angle as a conversion layer from OpenGL ES 2.0 Direct3D in case of Remote Desktop connections.


How do I position a 2D camera in OpenGL? I can't understand how the camera is working. It's a 2D game, so I'm displaying a game map from (0, 0, 0) to (mapSizeX, 0, mapSizeY). I'm initializing the camera as follow Camera Camera(void) position (0.0f, 0.0f, 0.0f), rotation (0.0f, 0.0f, 1.0f) void Camera initialize(void) glMatrixMode(GL PROJECTION) glLoadIdentity() glTranslatef(position .x, position .y, position .z) gluPerspective(70.0f, 800.0f 600.0f, 1.0f, 10000.0f) gluLookAt(0.0f, 6000.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f) glMatrixMode(GL MODELVIEW) glLoadIdentity() glEnable(GL DEPTH TEST) glDepthFunc(GL LEQUAL) So the camera is looking down. I currently see the up right border of the map in the center of my window and the map expand to the down left border of my window. I would like to center the map. The logical thing to do should be to move the camera to eyeX mapSizeX 2 and the same for z. My map has 10 x 10 cases with CASE 400, so I should have gluLookAt((10 2) CASE 2000 , 6000.0f, (10 2) CASE 2000 , 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f) But that doesn't move the camera, but seems to rotate it. Am I doing something wrong? EDIT I tried that gluLookAt(2000.0f, 6000.0f, 0.0f, 2000.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f) Which correctly moves the map in the middle of the window in width. But I can't move if correctly in height. It always returns the axis Z. When I go up, It goes down and the same for right and left. I don't see the map anymore when I do gluLookAt(2000.0f, 6000.0f, 2000.0f, 2000.0f, 0.0f, 2000.0f, 0.0f, 1.0f, 0.0f)


ETC1 texture opacity I'm using the cocos2d x engine and want to support etc1 on android devices for my game. For ETC1 i'm using the mali compression tool, and GLSL. Everything is working, but I can't change the opacity of my sprites anymore. my alpha blending is GL SRC ALPHA, GL ONE MINUS SRC ALPHA . can anyone help? Here are one of my Textures with rgb tex alpha tex Vertex Shader attribute vec4 a position attribute vec2 a texCoord attribute vec4 a color varying vec4 v fragmentColor varying vec2 v texCoord varying vec2 v texCoord2 uniform sampler2D tex1 void main() gl Position CC PMatrix a position CC PMatrix comes from engine v fragmentColor a color v texCoord a texCoord v texCoord2 v texCoord Fragment Shader varying vec4 v fragmentColor varying vec2 v texCoord varying vec2 v texCoord2 uniform sampler2D u texture1 alpha texture void main() CC Texture0 comes from cocos2d x engine and represents the rgb vec3 tex texture2D(CC Texture0, v texCoord).rgb float alpha texture2D(u texture1, v texCoord).r gl FragColor vec4(tex,alpha)


Android Object get Jagged at the border I am new to OpenGL ES 1 in android. My 3D Model border getting Jagged. Please help me to look like a smooth border instead of jagged. Screenshot http i.stack.imgur.com 1Gq83.png private class Renderer implements GLSurfaceView.Renderer public Renderer() setEGLConfigChooser(8, 8, 8, 8, 16, 0) getHolder().setFormat(PixelFormat.TRANSLUCENT) setZOrderOnTop(true) public void onSurfaceCreated(GL10 gl, EGLConfig config) gl.glClearColor(0.0f,0.0f,0.0f, 0.0f) gl.glDisable(GL10.GL DITHER) gl.glEnable(GL10.GL DEPTH TEST) gl.glEnable(GL10.GL BLEND) gl.glBlendFunc(GL10.GL SRC ALPHA SATURATE, GL10.GL ONE) gl.glDepthFunc(GL10.GL LEQUAL) gl.glHint(GL10.GL POLYGON SMOOTH HINT, GL10.GL NICEST) gl.glHint(GL10.GL PERSPECTIVE CORRECTION HINT, GL10.GL FASTEST) gl.glEnable(GL10.GL TEXTURE 2D) gl.glShadeModel(GL10.GL SMOOTH) public void onSurfaceChanged(GL10 gl, int w, int h) mViewWidth (float)w mViewHeight (float)h gl.glViewport(0,0,w,h) gl.glMatrixMode(GL10.GL PROJECTION) gl.glLoadIdentity() GLU.gluPerspective(gl, 45, mViewWidth mViewHeight, 0.1f, 100f) gl.glMatrixMode(GL10.GL MODELVIEW) gl.glLoadIdentity() public void onDrawFrame(GL10 gl) gl.glClear(GL10.GL COLOR BUFFER BIT GL10.GL DEPTH BUFFER BIT) gl.glPushMatrix() gl.glDisable(GL10.GL DITHER) GLU.gluLookAt(gl, 0, 0, 10, 0, 0, 0, 0, 1, 0) draw model gl.glPushMatrix() if(mOrigin ! null amp amp mRotate ! null) gl.glTranslatef(mOrigin.x, mOrigin.y, mOrigin.z) gl.glRotatef(mRotate.x, 1f, 0f, 0f) gl.glRotatef(mRotate.y, 0f, 1f, 0f) gl.glRotatef(mRotate.z, 0f, 0f, 1f) if(mModel ! null) mModel.draw(gl) if(!RendererView.textureFileName.equals("")) mModel.bindTextures(mContext, gl) gl.glPopMatrix() gl.glPopMatrix() if(isPictureTake) w getWidth() h getHeight() b new int w (y h) bt new int w h IntBuffer ib IntBuffer.wrap(b) ib.position(0) gl.glReadPixels(0, 0, w, h, GL10.GL RGBA, GL10.GL UNSIGNED BYTE, ib) createBitmapFromGLSurface(context) isPictureTake false Thanks in advance.


Why do I have to switch T(v) texture coordinates while importing OpenGL to Direct3D? I am importing my code from OpenGL to Direct3D. My D3DTS PROJECTION uses D3DXMatrixPerspectiveFovRH, and my D3DTS VIEW uses D3DXMatrixLookAtRH to set a view equal to OpenGL's view. My question is why do I have to switch all of my 1.0000 Tex(v) texture coordinates to "minus value" in D3D to get equal texture mapping as in OpenGL. OpenGL T(u) T(v) 1.0000, 1.0000, 0.0000, 1.0000, 1.0000, 0.0000, 1.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.0000, 0.0000, 1.0000, 0.0000, ... Direct3D T(u) T(v) D3DXVECTOR2( 1.0000f, 1.0000f) D3DXVECTOR2( 0.0000f, 1.0000f) D3DXVECTOR2( 1.0000f, 0.0000f) D3DXVECTOR2( 1.0000f, 0.0000f) D3DXVECTOR2( 0.0000f, 1.0000f) D3DXVECTOR2( 0.0000f, 0.0000f) D3DXVECTOR2( 0.0000f, 1.0000f) D3DXVECTOR2( 0.0000f, 0.0000f) D3DXVECTOR2( 1.0000f, 1.0000f) D3DXVECTOR2( 1.0000f, 1.0000f) D3DXVECTOR2( 0.0000f, 0.0000f) D3DXVECTOR2( 1.0000f, 0.0000f) ... Is it because Direct3D's origin (0.0) of texture coordinates lies in different place than in OpenGL?


Skeletal animation in OpenGL I'm using Assimp to do skeletal animation in my OpenGL application. I used Blender to export this one boned model to a COLLADA file The model has only one bone, called arm bone, that controls the arm mesh. All the other meshes are static. I made several structures and classes that help me play animations. All the nodes are added to an std vector of Node objects. each Node contains aiNode data and a toRoot matrix. The bone hierarchy is encapsulated in a Skeleton class, and the animation matrix (T R) are updated for each bone in a class called Animation. My Model Draw() function is this void Model draw() iterate through all animation sets. if the animation is running, update the bones it affects. for(size t i 0 i lt animations.size() i ) if( animations i .running()) animations i .updateAnimationMatrices( amp skeleton) calculate Bone finalMatrix for each bone skeleton.calculateFinalMatrices( skeleton.rootBone()) iterate through the nodes and draw their meshes. for(size t i 0 i lt nodes.size() i ) shaderProgram.setUniform("ModelMatrix", nodes i .toRoot()) nodes i .draw() To get the "animationMatrix" for each bone (the TR matrix) I call Animation updateAnimationMatrices(). Here's what it looks like void Animation updateAnimationMatrices(Skeleton skeleton) double time ((double) timer.elapsed() 1000.0) while(time gt animation gt mDuration) time animation gt mDuration iterate through aiNodeAnim (called channels) and update their corresponding Bone. for(unsigned int iChannel 0 iChannel lt animation gt mNumChannels iChannel ) aiNodeAnim channel animation gt mChannels iChannel Bone bone skeleton gt getBoneByName(channel gt mNodeName.C Str(), skeleton gt rootBone()) rotation glm mat4 R ... calculate rotation matrix based on time translation glm mat4 T ... calculate translation matrix based on time set animation matrix for the bone bone gt animationMatrix T R bone gt needsUpdate true Now in order to calculate the "finalMatrix" for each bone (based on animationMatrix, offsetMatrix etc..), and upload it to the vertex shader, I call Skeleton calculateFinalMatrices(). void Skeleton calculateFinalMatrices(Bone root) if(root) Node node getNodeByName(root gt name gt C Str()) if(node nullptr) std cout lt lt "could not find corresponding node for bone " lt lt root gt name gt C Str() lt lt " n" return if(root gt needsUpdate) update only the bones that need to be updated (their animationMatrix has been changed) root gt finalMatrix root gt animationMatrix root gt offsetMatrix upload the bone matrix to the shader. the array is defined as "uniform mat4 Bones 64 " std string str "Bones " char buf 4 0 itoa s(root gt index, buf, 10) str buf str " " shaderProgram gt setUniform(str.c str(), root gt finalMatrix) root gt needsUpdate false for(unsigned int i 0 i lt root gt numChildren i ) calculateFinalMatrices(root gt children i ) Here's my bone structure, if it helps. My glsl vertex shader is pretty standard. Here it is. And finally, here's the result I get (ignore the model's static legs. that must be some bug in the Blender exporter). And here's the result I should get (using a 3d party software) It looks like there's something wrong with the bone's matrix calculation, although I don't know what. Any ideas or tips? Thanks!


C Help with Separating Axis Theorem I am trying to detect collision between two triangles using Separating Axis Theorem however I am unaware what is wrong with my code. The CollisionHelper isTriangleIntersectingTriangle is called every frame and passes in the vertices of both triangles. It never returns true, however. I've been stuck on this for days now. Any help is appreciated. glm vec3 CalcSurfaceNormal(glm vec3 tri1, glm vec3 tri2, glm vec3 tri3) Subtracts each coordinate respectively glm vec3 u tri2 tri1 glm vec3 v tri3 tri1 glm vec3 nrmcross glm cross(u, v) nrmcross glm normalize(nrmcross) return nrmcross bool SATTriangleCheck(glm vec3 axis, glm vec3 tri1vert1, glm vec3 tri1vert2, glm vec3 tri1vert3, glm vec3 tri2vert1, glm vec3 tri2vert2, glm vec3 tri2vert3) int t1v1 glm dot(axis, tri1vert1) int t1v2 glm dot(axis, tri1vert2) int t1v3 glm dot(axis, tri1vert3) int t2v1 glm dot(axis, tri2vert1) int t2v2 glm dot(axis, tri2vert2) int t2v3 glm dot(axis, tri2vert3) int t1min glm min(t1v1, glm min(t1v2, t1v3)) int t1max glm max(t1v1, glm max(t1v2, t1v3)) int t2min glm min(t2v1, glm min(t2v2, t2v3)) int t2max glm max(t2v1, glm max(t2v2, t2v3)) if ((t1min lt t2max amp amp t1min gt t2min) (t1max lt t2max amp amp t1max gt t2min)) return true if ((t2min lt t1max amp amp t2min gt t1min) (t2max lt t1max amp amp t2max gt t1min)) return true return false bool CollisionHelper isTriangleIntersectingTriangle(glm vec3 tri1, glm vec3 tri2, glm vec3 tri3, glm vec3 otherTri1, glm vec3 otherTri2, glm vec3 otherTri3) Triangle surface normals, 2 axes to test glm vec3 tri1FaceNrml CalcSurfaceNormal(tri1, tri2, tri3) glm vec3 tri2FaceNrml CalcSurfaceNormal(otherTri1, otherTri2, otherTri3) glm vec3 tri1Edge1 tri2 tri1 glm vec3 tri1Edge2 tri3 tri1 glm vec3 tri1Edge3 tri3 tri2 glm vec3 tri2Edge1 otherTri2 otherTri1 glm vec3 tri2Edge2 otherTri3 otherTri1 glm vec3 tri2Edge3 otherTri3 otherTri2 axes TODO may need to (un)normalize the cross products glm vec3 axis1 tri1FaceNrml glm vec3 axis2 tri2FaceNrml glm vec3 axis3 glm normalize(glm cross(tri1Edge1, tri2Edge1)) glm vec3 axis4 glm normalize(glm cross(tri1Edge1, tri2Edge2)) glm vec3 axis5 glm normalize(glm cross(tri1Edge1, tri2Edge3)) glm vec3 axis6 glm normalize(glm cross(tri1Edge2, tri2Edge1)) glm vec3 axis7 glm normalize(glm cross(tri1Edge2, tri2Edge2)) glm vec3 axis8 glm normalize(glm cross(tri1Edge2, tri2Edge3)) glm vec3 axis9 glm normalize(glm cross(tri1Edge3, tri2Edge1)) glm vec3 axis10 glm normalize(glm cross(tri1Edge3, tri2Edge2)) glm vec3 axis11 glm normalize(glm cross(tri1Edge3, tri2Edge3)) Perform SAT if (SATTriangleCheck(axis1, tri1, tri2, tri3, otherTri1, otherTri2, otherTri3)) return true if (SATTriangleCheck(axis2, tri1, tri2, tri3, otherTri1, otherTri2, otherTri3)) return true if (SATTriangleCheck(axis3, tri1, tri2, tri3, otherTri1, otherTri2, otherTri3)) return true if (SATTriangleCheck(axis4, tri1, tri2, tri3, otherTri1, otherTri2, otherTri3)) return true if (SATTriangleCheck(axis5, tri1, tri2, tri3, otherTri1, otherTri2, otherTri3)) return true if (SATTriangleCheck(axis6, tri1, tri2, tri3, otherTri1, otherTri2, otherTri3)) return true if (SATTriangleCheck(axis7, tri1, tri2, tri3, otherTri1, otherTri2, otherTri3)) return true if (SATTriangleCheck(axis8, tri1, tri2, tri3, otherTri1, otherTri2, otherTri3)) return true if (SATTriangleCheck(axis9, tri1, tri2, tri3, otherTri1, otherTri2, otherTri3)) return true if (SATTriangleCheck(axis10, tri1, tri2, tri3, otherTri1, otherTri2, otherTri3)) return true if (SATTriangleCheck(axis11, tri1, tri2, tri3, otherTri1, otherTri2, otherTri3)) return true return false


How to use a buffer in GLSL to do a LUT lookup? I am currently on a medical application which needs different kinds (up to totally individual) lookup tables (LUT) for image display. And this done with 10bit finish. So it is most of the time required to use 16 bit gray scale pixels. I chose to use modern OpenGL and thus I'll want the lookup to happen in a GLSL shader program. I had a try in uploading a 1D Tedture (R16) using sampler1D to do the lookup as such uniform sampler2D tex uniform sampler1D lutData in vec2 fragTexCoord out vec4 finalColor void main() float primaryLvl texture(tex, fragTexCoord) index image 'color' in Lut Texture float red texture(lutData, primaryLvl) finalColor vec4(red, red, red, 1.0) It works about as expected however Textures (also 1D aparently) are limited to 8192 in size (on my machine). So the requirement for full range 16 bit images is not met. For this above test I upload my images as R16 (for me it is gray) normalized float 0 1.0. Would it be feasible to upload a buffer (arbitrary data) and do the lookup there? How would I do this (Syntax)? And will my current pixel format interfere with my idea so I have to upload it as R16 INT instead. Or can (and should) I convert it in the shader from Normalized to Int (how is this done)? Thanks


Directional light type I am currently trying to implement a specific directional light type. This light type has been used in the game INSIDE and is called orthogonal spotlight (aka local directional light). I assume that this is a directional light which behaves like a spot light and have a squared or rectangular attenuation but I have some difficulties to integrate it in my deferred pipeline and get the general concept of this light type. Implementing a simple directional light is simple dot(worldNormal, lightDir) but what kind of data should I use to constraint its application into a square or a rectangle ? I hope that you'll be able to give me some clues. Thanks a lot !


Finding correct index of triangles I'm generating a basic terrain and it looks something like this Load the vertex and index array with the terrain data. for (j 0 j lt (m terrainHeight 1) j ) for (i 0 i lt (m terrainWidth 1) i ) index1 (m terrainHeight j) i Top left. index2 (m terrainHeight (j 1)) i Bottom left. index3 (m terrainHeight j) (i 1) Top right. index4 (m terrainHeight (j 1)) (i 1) Bottom right. Top left vertices index .position glm vec3(m heightMap index1 .x, m heightMap index1 .y, m heightMap index1 .z) vertices index .texture glm vec2(m heightMap index1 .tu 0.0f, m heightMap index1 .tv 0.0f) indices index index index Bottom left. vertices index .position glm vec3(m heightMap index2 .x, m heightMap index2 .y, m heightMap index2 .z) vertices index .texture glm vec2(m heightMap index2 .tu 0.0f, m heightMap index2 .tv 1.0f) indices index index index Top right. vertices index .position glm vec3(m heightMap index3 .x, m heightMap index3 .y, m heightMap index3 .z) vertices index .texture glm vec2(m heightMap index3 .tu 1.0f, m heightMap index3 .tv 0.0f) indices index index index Top right. vertices index .position glm vec3(m heightMap index3 .x, m heightMap index3 .y, m heightMap index3 .z) vertices index .texture glm vec2(m heightMap index3 .tu 1.0f, m heightMap index3 .tv 0.0f) indices index index index Bottom left. vertices index .position glm vec3(m heightMap index2 .x, m heightMap index2 .y, m heightMap index2 .z) vertices index .texture glm vec2(m heightMap index2 .tu 0.0f, m heightMap index2 .tv 1.0f) indices index index index Bottom right vertices index .position glm vec3(m heightMap index4 .x, m heightMap index4 .y, m heightMap index4 .z) vertices index .texture glm vec2(m heightMap index4 .tu 1.0f, m heightMap index4 .tv 1.0f) indices index index index Now If I wanted to find which grid square the player is on, we could simply (if the camera position is relative to the terrain) Grid square the camera is on int gridX (int)std floor(cameraX gridSquareSize) int gridZ (int)std floor(cameraZ gridSquareSize) Continuing, we know that each face consists of two triangles, and the top triangle is represented by three vertices which index corresponds to top left, bottom left and top right. The bottom triangle would then be top right, bottom left and bottom right. Now I'm having a hard time trying to find height values (y values) at these points because if I try to do Top left triangle glm vec3(0, vertices (m terrainHeight gridZ) gridX .position.y, 0) Top left glm vec3(0, vertices (m terrainHeight (gridZ) 1) gridX .position.y, 1) Bottom left glm vec3(1, vertices ((m terrainHeight gridZ)) (gridX 1) .position.y, 0) Top right we conclude that the top left and bottom left position will be okay, but the top right position won't get the correct index, because as it is now (if we say that gridX 0 and gridZ 0), the index will generate a value of 1, which is not the correct height value at that position because the index we want should be 2 (top right). So, is there a way I could write the code so I would get the correct index for the triangles of the terrain?


What's the best practice to use the pbo to upload multi textures? I have a basic model to upload textures as shown in the following picture. I design this for several reasons Only the primary thread owns the OpenGL context, so I choose to create buffers, map buffers and unmap buffers in the primary thread. I have many pictures to load and I don't want them to block the primary thread, so I use the subthread to load images and copy the memory. Here are my questions Is my model correct? Is my model the best practice? Should I create a PBO for each picture or create two PBO for all pictures and use them in turn? Should I use a shared context? Thank you for helping me out


OpenGL back front end threading and Doom 3 BFG engine Introduction I have been reading through the source code of id Software's Doom 3 BFG engine. The whole codebase is on GitHub at id Software DOOM 3 BFG. The architecture is both clean and elegant. The whole code base is of exceptional code quality. (It makes for a great code read.) Fabian Sanglard has an easy to follow code review of the engine. In particular, I am interested in id Software's implementation of the renderer, which is explained here http fabiensanglard.net doom3 bfg renderer.php. Architecture of renderer Fabian's site offers this architectural diagram of the renderer. From the source code, and from the review, you can see that the renderer consists of a frontend and a backend. The engine is multithreaded in two ways, first there is a job pool whose task items are consumed by worker threads without relying on mutexes (this is awesome). In addition to the job pool, the renderer front end and back also each have their own thread. My implementation of something similar I played around with trying to build something similar in my own game engine. I will probably make the repo public and link to it here at some point, in the future. The renderer front end lives on the same thread as the program entry point main(), where my Service Provider and Subsystem Singletons also live. Upon startup it launches the backend on a separate thread. The front end talks to the back end via a non blocking command buffer. I implemented it using this awesome single producer single consumer non locking queue on GitHub at cameron314 readerwriterqueue. The backend consumes commands of the command buffer queue, and turns them into OpenGL calls. The backend creates and manages the OpenGL context lifecycle. (At the moment this is an obstacle, because I am using SDL2, and I don't want SDL API related functionality, like input, running on the renderer backend thread. Is it worth it? Aren't OpenGL calls suppose to occur asynchronously, given that we are somewhat successful at minimizing GPU CPU synchronization? Is all the added architectural complexity worth it from a performance perspective? With more modern rendering techniques like vertex buffer streaming, it seems as if more and more work is done to transfer load from the CPU to the GPU, and to make drawing asynchronous. Adding the command buffer queue also adds a relatively heavy layer of abstraction between the originating draw service call and the underlying driver call. This complexity certainly must impact cache coherence and branch prediction. Newer, closer to the silicon graphics APIs like METAL, only further exaggerate my point. I guess moving away from the CPU is the obvious future path of progression for graphics performance. Is it relevant? As elegant as the Doom 3 BFG engine is, the architecture is probably a bit dated, and probably misses out on some new innovations. Did the engine originally rely on a fixed pipeline? This might explain this design choice. Do any modern game engines use something like this? Apology Sorry for the long winded and multi faceted question. I hope the community will forgive me. I also realize, profiling would be able to answer my question. Unfortunately, neither my implementation of the technique I described, nor the method without it, is mature enough, to do any meaningful profiling. Not to mention, there are a whole lot of other variables as well. I'd rather not build a complete rendering pipeline around a flawed and outdated idea, only to discover that it is over engineered and slow. In the meantime, I will continue to develop my job schedular approach, but this could be a feature design improvement. Any insights or discussion would be greatly appreciated. Thanks!


rotating objects in a double orbit I have a object at the center. Other set of objects rotating around center in first orbit. Now i want other objects to rotate around the objects in 1st orbit. In the above fig, set of triangles are rotating around the square and circles are rotating around the triangle. I have the code which works for 1st orbit, but i am not able to render that second orbit. I am calling display in loop. i is static global variable. which transformations will do the second orbit?


OpenGL textures look poor I'm having some issues loading in textures in OpenGL, as my textures keep rendering incorrectly or coming out looking muddy. For instance, here I tried to load a 256x256 color spectrum image. On the left is how it looks in OpenGL and on the right is how it looks in an image viewing program As you can see, while the left image resembles the right image, the left image appears to squish the blues, and greens, and extend the pinks. I also tried loading in this 512x512 image of a dog and the result came out like this (again, left is OpenGL, right is image viewer) For this image, the image looks like it has lost a lot of its color, resulting in something that looks white washed and like it came out of a 1970s camera. (the fact that is flipped is fine however since the cube that I am drawing this on has some texture coordinates flipped to accommodate for a different image). I load in these .BMP textures using SOIL, as such glEnable(GL TEXTURE 2D) GLuint texID 0 glGenTextures(1, amp texID) int height 0, width 0 unsigned char imgData SOIL load image(filePath.c str(), amp width, amp height, 0, SOIL LOAD AUTO) glBindTexture(GL TEXTURE 2D, texID) glTexImage2D(GL TEXTURE 2D, 0, GL RGB, width, height, 0, GL RGB, imgData) set texture filtering, gen mip map Then in my fragment shader I do the following to apply the texture version 330 core in vec2 TexCoord uniform sampler2D textureSampler void main() gl FragColor texture2D(textureSampler, TexCoord)


Do OpenGL buffers overflow to CPU memory? This is a question about OpenGL buffers and memory. My game world is mid sized, one contiguous space, unchanging, and only partially visible from any position. Will modern OpenGL overflow buffers into CPU memory? And if so, can I just allocate buffers (vertex and texture) for all of it, and adjust my draw calls to skip non visible areas, and let OpenGL pull buffers into GPU as needed, hopefully minimizing thrashing? (Or does OpenGL just fail on the allocate after a while?) EDIT The above was ambiguous. But maybe both variations are interesting. Could I just allocate one huge vertex buffer and a few giant textures, and hope that OpenGL moves parts of it in and out of the GPU as needed, and maybe enough early depth testing lets it skip some of the texture drawing... Could I have a handful, or maybe a lot, of "sensibly sized" vertex and texture buffers, but only glDrawXxx() some of them on each frame? In that case, would OpenGL move them up and down from the GPU, maybe in a least recently used sort of way?


Why does reading my depth texture in GLSL return less than one? I've created a depth texture in OpenGL (using C ) as follows Create the framebuffer. var framebuffer 0u glGenFramebuffers(1, amp framebuffer) glBindFramebuffer(GL FRAMEBUFFER, framebuffer) Create the depth texture. var depthTexture 0u glGenTextures(1, amp depthTexture) glBindTexture(GL TEXTURE 2D, depthTexture) glTexImage2D(GL TEXTURE 2D, 0, GL DEPTH COMPONENT24, 800, 600, 0, GL DEPTH COMPONENT, GL FLOAT, null) glTexParameteri(GL TEXTURE 2D, GL TEXTURE WRAP S, GL REPEAT) glTexParameteri(GL TEXTURE 2D, GL TEXTURE WRAP T, GL REPEAT) glTexParameteri(GL TEXTURE 2D, GL TEXTURE MIN FILTER, GL NEAREST) glTexParameteri(GL TEXTURE 2D, GL TEXTURE MAG FILTER, GL NEAREST) glFramebufferTexture2D(GL FRAMEBUFFER, GL DEPTH ATTACHMENT, GL TEXTURE 2D, depthTexture, 0) Later, I sample from the depth texture as follows float depth texture(depthTexture, texCoords).r But even when no geometry has been rendered to that pixel, the depth value coming back is less than 1 (seems to be very slightly above 0.5). This is confusing to me since, per the documentation on glClearDepth, the default value is 1. Note that this is not a problem of linearizing depth since I'm attemping to compare depth directly (using the same near and far planes), not convert that depth back to world space. Why is my depth texture sample returning lt 1 when no geometry has been rendered?


Can't get simple OpenGL texture working using SDL2 and FreeImage3 I created a simple OpenGL program that display a quad with texture, but it doesn't seem to be working as it only displays a white quad. What could possibly be wrong? I checked everything I could think of that could cause the issue. The bitmap is also 256x256. Any clues? Here's the source code http pastebin.com 5nVbMPVp I'm also on Linux if that helps. Thanks!


Why is this orthographic projection matrix not showing my textured quad? I've been following tutorials, mainly this one, and I am still not quite sure why my textured quad is not showing inside the frustum that I've rendered before. I can see it if and only if I don't multiply gl Position with OrthoProjMatrix vertexmodelspace, and instead, multiply gl position with vertexmodelspace. Here is some of my code my Main.CPP is also available via PasteBin. Orthographic Projection Matrix Setup Code void OpenGL Engine OrthoProjectionSetup(GLuint program) GLfloat Right 100.0 GLfloat Left 50.0 GLfloat Top 100.0 GLfloat Bottom 50.0 GLfloat zFar 1.0 GLfloat zNear 1.0 GLfloat LeftAndRight 2.0f (Right Left) GLfloat TopAndBottom 2.0f (Top Bottom) GLfloat ZFarAndZNear 2.0f (zFar zNear) GLfloat orthographicprojmatrix XX XY XZ XW LeftAndRight, 0.0, 0.0, (Right Left) (Right Left), YX YY YZ YW 0.0, TopAndBottom, 0.0 , (Top Bottom) (Top Bottom), ZX ZY ZZ ZW 0.0, 0.0 , ZFarAndZNear, WX WY WZ WW (zFar zNear ) (zFar zNear), 0.0, 1.0 GLint orthographicmatrixloc glGetUniformLocation(program, "OrthoProjMatrix") glUniformMatrix4fv(orthographicmatrixloc, 1, GL TRUE, amp orthographicprojmatrix 0 ) Vertex Shader Code version 330 core layout(location 0) in vec4 vertexposition modelspace layout(location 1) in vec2 vertexUV out vec2 UV uniform mat4 OrthoProjMatrix void main() gl Position OrthoProjMatrix vertexposition modelspace UV vertexUV I'm having problems with the orthographic projection matrix either it is not being done correctly, not setup correctly, my shader is not setup correctly or it's the textured quad that is not in view. Please note that I do not want to use a library for this. What am I doing wrong?


How can I pass an array of matrices to a VertexShader I'm trying to learn how to use OpenGL but I'm having problems trying to pass an array of matrices to my VertexShader. I think the problem is in the VertexShader because it seems the values in modelvalue are passed correctly to the components of model, but for some reason at the end only one of the three cubes I've created is drawn. Here's the Main code. glm mat4 model 3 GLint ModelLocation glGetUniformLocation(MyShader.program, "model") vector lt GLfloat gt modelvalue const int n int(sizeof(model 0 ) sizeof(GLfloat)) for (int i 0 i lt 3 i ) model i glm translate(model i , cubePositions i ) for (int j 0 j lt n j ) modelvalue.push back(glm value ptr(model i ) j ) glUniformMatrix4fv(ModelLocation, 3, GL FALSE, amp modelvalue 0 ) The VertexShader version 400 core layout (location 0) in vec3 Position layout (location 1) in vec2 texCoord out vec2 TexCoord out vec4 position0 out vec4 position1 out vec4 position2 uniform mat4 model 3 uniform mat4 view uniform mat4 projection void main() position0 projection view model 0 vec4(Position,1.0f) position1 projection view model 1 vec4(Position,1.0f) position2 projection view model 2 vec4(Position,1.0f) TexCoord vec2(texCoord.x,1 texCoord.y) And the FragmentShader version 400 core layout (location 0) in vec3 Position layout (location 1) in vec2 texCoord out vec2 TexCoord out vec4 position0 out vec4 position1 out vec4 position2 uniform mat4 model 3 uniform mat4 view uniform mat4 projection void main() position0 projection view model 0 vec4(Position,1.0f) position1 projection view model 1 vec4(Position,1.0f) position2 projection view model 2 vec4(Position,1.0f) TexCoord vec2(texCoord.x,1 texCoord.y)


OpenGL have object follow mouse I want to have an object follow around my mouse on the screen in OpenGL. (I am also using GLEW, GLFW, and GLM). The best idea I've come up with is Get the coordinates within the window with glfwGetCursorPos. The window was created with window glfwCreateWindow( 1024, 768, "Test", NULL, NULL) and the code to get coordinates is double xpos, ypos glfwGetCursorPos(window, amp xpos, amp ypos) Next, I use GLM unproject, to get the coordinates in "object space" glm vec4 viewport glm vec4(0.0f, 0.0f, 1024.0f, 768.0f) glm vec3 pos glm vec3(xpos, ypos, 0.0f) glm vec3 un glm unProject(pos, View Model, Projection, viewport) There are two potential problems I can already see. The viewport is fine, as the initial x,y, coordinates of the lower left are indeed 0,0, and it's indeed a 1024 768 window. However, the position vector I create doesn't seem right. The Z coordinate should probably not be zero. However, glfwGetCursorPos returns 2D coordinates, and I don't know how to go from there to the 3D window coordinates, especially since I am not sure what the 3rd dimension of the window coordinates even means (since computer screens are 2D). Then, I am not sure if I am using unproject correctly. Assume the View, Model, Projection matrices are all OK. If I passed in the correct position vector in Window coordinates, does the unproject call give me the coordinates in Object coordinates? I think it does, but the documentation is not clear. Finally, to each vertex of the object I want to follow the mouse around, I just increment the x coordinate by un 0 , the y coordinate by un 1 , and the z coordinate by un 2 . However, since my position vector that is being unprojected is likely wrong, this is not giving good results the object does move as my mouse moves, but it is offset quite a bit (i.e. moving the mouse a lot doesn't move the object that much, and the z coordinate is very large). I actually found that the z coordinate un 2 is always the same value no matter where my mouse is, probably because the position vector I pass into unproject always has a value of 0.0 for z. Edit The (incorrectly) unprojected x values range from about 0.552 to 0.552, and the y values from about 0.411 to 0.411.


smooth shading vs flat shading, what's the difference in the models? I'm loading the exact same model with Assimp, except one is exported from Blender, shaded smoothly, and the other was exported from Blender, shaded flatly. Here is my results from loading both into my game The Flat drawn model has 1968 vertices and the Smooth drawn model only has 671, why is this happening, I don't understand why there would be less vertices when it's shaded smoothly...?


Rotation along normal vector I have a triangle in the 3D world. I have the positions for the three points the normal vectors for the three points (all the same, because vertices are not shared) This triangle faces to a direction, so it has a XYZ rotation (but I dont know the rotation itself). If I put a cube into the same scene, how I can achieve the same rotation for the cube? So if the triangle "looks" upwards, the cube should do the same. If it has a 10f x rotation, how can I get what is the x?


Rotate an object given only by its points? I was recently writing a simple 3D maze FPP game. Once I was done fiddling with planes in OpenGL, I wanted to add support for importing Blender objects. The approach I used was triangulization of the object, then using Three.js to export the points to plaintext and then parsing the result JSON in my app. The example file can be seen here https github.com d33tah tinyfpp blob master Data Models cross.txt The numbers represent x,y,z,u,v of a single vertex, which combined in three make a triangle. Then I rendered such an object triangle by triangle and played with it. I could move it back and forth and sideways, but I still have no idea how to rotate it by some axis. Let's say I'd like to rotate all the points by five degrees to the left, how would a code doing it look like?


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


How do i writing timing function for lightning flash in C ? I need to write a horror scene with lightning flash. Unfortunately I am new to both C and OpenGL and I am looking for efficient way to mimic lightning timing in C OpenGL? I don't need graphical implementation, just algorithmic implementation. as such, the function should return a float representing lighting intensity and the delay of lightning flash should be random (5 seconds followed by 10 seconds then 3 seconds.. etc) I hope I made everything clear!


OpenGL global local states OpenGL has so many APIs which can modify different states. It's not so obvious whether an API has global effect or local effect. For example, rumour says glTexEnv has global effect while glTexParameter has local effect (it only affects the current bound texture). Is this true? How to determine whether an API has global or local effect?


reflecting objects by rendering them to the cubemap I have 2 sphere objects and it isn't reflecting the other one. The picture is when it simply reflects the cube map but when I try to render to the cube map the spheres turn out black. In camera class void switchToFace(int faceIndex) For Cube Map camera switch (faceIndex) case 0 m pitch 0 m yaw 90 break case 1 m pitch 0 m yaw 90 break case 2 m pitch 90 m yaw 180 break case 3 m pitch 90 m yaw 180 break case 4 m pitch 0 m yaw 180 break case 5 m pitch 0 m yaw 0 break default break In main static GLuint createEmptyCubeMap(int width, int height) GLuint textureID glGenTextures(1, amp textureID) glBindTexture(GL TEXTURE CUBE MAP, textureID) for (GLuint i 0 i lt 6 i) glTexImage2D(GL TEXTURE CUBE MAP POSITIVE X i, 0, GL RGB, width, height, 0, GL RGB, GL UNSIGNED BYTE, nullptr) glTexParameteri(GL TEXTURE CUBE MAP, GL TEXTURE MAG FILTER, GL LINEAR) glTexParameteri(GL TEXTURE CUBE MAP, GL TEXTURE MIN FILTER, GL LINEAR) glTexParameteri(GL TEXTURE CUBE MAP, GL TEXTURE WRAP S, GL CLAMP TO EDGE) glTexParameteri(GL TEXTURE CUBE MAP, GL TEXTURE WRAP T, GL CLAMP TO EDGE) glTexParameteri(GL TEXTURE CUBE MAP, GL TEXTURE WRAP R, GL CLAMP TO EDGE) glBindTexture(GL TEXTURE CUBE MAP, 0) return textureID main() stuff glm vec3 spherePositions glm vec3(0.0f, 0.0f, 0.0f), glm vec3( 1.5f, 2.2f, 2.5f), new cubemap Camera reflectionCamera(glm vec3(0.0f, 0.0f, 0.0f)) Camera position. Should be on ball GLint imageWidth, imageHeight SOIL load image(faces 1 , amp imageWidth, amp imageHeight, 0, SOIL LOAD RGB) GLuint newEnvironment createEmptyCubeMap(imageWidth, imageHeight) GLuint FBO , DBO glGenFramebuffers(1, amp FBO) glBindFramebuffer(GL FRAMEBUFFER, FBO) glDrawBuffer(GL COLOR ATTACHMENT0) glGenRenderbuffers(1, amp DBO) glBindRenderbuffer(GL RENDERBUFFER, DBO) glRenderbufferStorage(GL RENDERBUFFER, GL DEPTH COMPONENT24, imageWidth, imageHeight) glFramebufferRenderbuffer(GL FRAMEBUFFER, GL DEPTH ATTACHMENT, GL RENDERBUFFER, DBO) glViewport(0, 0, imageWidth, imageHeight) for (GLuint i 0 i lt 6 i) glFramebufferTexture2D(GL FRAMEBUFFER, GL COLOR ATTACHMENT0, GL TEXTURE CUBE MAP POSITIVE X i, newEnvironment, 0) reflectionCamera.switchToFace(i) glBindFramebuffer(GL FRAMEBUFFER, 0) glViewport(0, 0, WIDTH, HEIGHT) while(window.isOpen() SFML) glBindVertexArray(sphereVAO) for (GLuint i 0 i lt 2 i) model glm mat4() model glm translate(model, spherePositions i ) glUniformMatrix4fv(modelLoc, 1, GL FALSE, glm value ptr(model)) modelLoc is location of uniform model glActiveTexture(GL TEXTURE0) glBindTexture(GL TEXTURE CUBE MAP, newEnvironment) glDrawElements(GL TRIANGLES, numberOfIndexes, GL UNSIGNED INT, 0) The sphereVAO is simply the Vertex Array Object for the sphere and here we bind the texture to the newEnvironment which is supposed to reflect the other object in spherePositions i The picture above is the sphere Position at (0, 0, 0). But the code results in this


Understanding VAOs and adding different arrays to VAOs I'm really confused on what you do. I can do them, however I got this problem. Say you have several squares, say 1,000 squares. Now I can make a VAO for each 1,000 squares and then do some for loop to render all of the squares. I can also use shaders to move the squares. However, is it possible to put all 1,000 squares in one VAO. The problem is I'm going to create a voxel game. So I need to render about 10,000 cubes. However, the game will lag a lot even if I render 200 squares how I'm currently doing it. float points 0.0f, 0.0f, 0.0f, 0.3f, 0.0f, 0.0f, 0.3f, 0.3f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.3f, 0.0f, 0.3f, 0.3f, 0.0f float colours 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f unsigned int points vbo 0 glGenBuffers (1, amp points vbo) glBindBuffer (GL ARRAY BUFFER, points vbo) glBufferData (GL ARRAY BUFFER, 18 sizeof (float), amp points, GL STATIC DRAW) unsigned int colours vbo 0 glGenBuffers (1, amp colours vbo) glBindBuffer (GL ARRAY BUFFER, colours vbo) glBufferData (GL ARRAY BUFFER, 18 sizeof (float), amp colours, GL STATIC DRAW) unsigned int vao 0 glGenVertexArrays (1, amp vao) glBindVertexArray (vao) glBindBuffer (GL ARRAY BUFFER, points vbo) glVertexAttribPointer (0, 3, GL FLOAT, GL FALSE, 0, (GLubyte )NULL) glBindBuffer (GL ARRAY BUFFER, colours vbo) glVertexAttribPointer (1, 3, GL FLOAT, GL FALSE, 0, (GLubyte )NULL) glEnableVertexAttribArray (0) glEnableVertexAttribArray (1) Setup shaders std string vertex shader loadshaders("test vs.txt") std string fragment shader loadshaders("test fs.txt") unsigned int vs glCreateShader (GL VERTEX SHADER) const char str vertex shader.c str () glShaderSource (vs, 1, amp str, NULL) glCompileShader (vs) unsigned int fs glCreateShader (GL FRAGMENT SHADER) const char strb fragment shader.c str () glShaderSource (fs, 1, amp strb, NULL) glCompileShader (fs) unsigned int shader programme glCreateProgram () glAttachShader (shader programme, fs) glAttachShader (shader programme, vs) glLinkProgram (shader programme) main loop while (!glfwWindowShouldClose(window)) float ratio int width, height glfwGetFramebufferSize(window, amp width, amp height) glClear (GL COLOR BUFFER BIT GL DEPTH BUFFER BIT) glClearColor (0.6f, 0.6f, 0.8f, 1.0f) glUseProgram (shader programme) glBindVertexArray (vao) glDrawArrays (GL TRIANGLES, 0, 6) glfwSwapBuffers(window) glfwPollEvents() So how would I say add points2 , points3 and put them into the same VAO. How can I design my shader so I can then do transformation on the points in the arrays say translate points2 array 4 blocks right, without effecting every other point.


Screen space decals, converting world to decal space I'm trying to do screen space deferred decals following the presentation made by Pope Kim about SSDs in WH40K Space Marine (link). I've gotten to the point where I can render a decal if the bounding box is placed at the world space origin (0, 0, 0). The moment I move the bounding volume the decal is still trying to render at the world space origin and can be seen if you look "through" the bounding volume. The red planes in the picture are the bounding volume rendered for reference, the circular patch is the decal. Picture showing a decal rendered correctly at world space origin Picture showing a decal clipped when rendered offset from world space origin Decal as seen "through" offset bounding volume. My code is fairly similar to that off Kim, with minor differences accounting for the D3D to OpenGL transition. Vertex shader version 430 layout (shared) uniform PerFrameBlock mat4 gView mat4 gProjection uniform mat4 modelMatrix uniform vec3 decalSize layout ( location 0 ) in vec4 positionIN layout ( location 1 ) in vec4 normalIN layout ( location 2 ) in vec4 tangentIN layout ( location 3 ) in ivec4 boneIndices layout ( location 4 ) in vec4 boneWeights layout ( location 5 ) in vec2 uvIN out vec4 posFS out vec4 posW out vec2 uvFS void main() posW modelMatrix vec4(positionIN.xyz 1, positionIN.w) Move position to clip space posFS gProjection gView posW uvFS uvIN gl Position posFS Fragment shader version 430 extension GL ARB texture rectangle enable in vec4 posFS in vec4 posW in vec2 uvFS uniform sampler2D gNormalDepth uniform sampler2D gDiffuse uniform float gGamma uniform mat4 invProjView uniform mat4 invModelMatrix vec4 reconstruct pos(float z, vec2 uv f) vec4 sPos vec4(uv f 2.0 1.0, z, 1.0) sPos invProjView sPos return vec4((sPos.xyz sPos.w ), sPos.w) layout ( location 1 ) out vec4 diffuseRT layout ( location 2 ) out vec4 specularRT layout ( location 3 ) out vec4 glowMatIDRT void main() vec2 screenPosition posFS.xy posFS.w vec2 depthUV screenPosition 0.5f 0.5f depthUV vec2(0.5f 1280.0f, 0.5f 720.0f) half pixel offset float depth texture2D(gNormalDepth, depthUV).w vec4 worldPos reconstruct pos(depth, depthUV) vec4 localPos invModelMatrix worldPos float dist 0.5f abs(localPos.y) float dist2 0.5f abs(localPos.x) if (dist gt 0.0f amp amp dist2 gt 0) vec2 uv vec2(localPos.x, localPos.y) 0.5f vec4 diffuseColor texture2D(gDiffuse, uv) diffuseRT diffuseColor else diffuseRT vec4(1.0f, 0, 0, 1) I think my problem stems from the conversion from world space to decal space using the inverse model matrix. The model matrix is build by the following code glm quat rot glm mat4 rotationMatrix glm mat4 translationMatrix glm mat4 scaleMatrix rotationMatrix glm toMat4(rotation) translationMatrix glm translate(glm mat4(1.0f), position) scaleMatrix glm scale(scaleX, scaleY, scaleZ) modelMatrix translationMatrix rotationMatrix scaleMatrix To get the inverse I just use the following glm inverse(modelMatrix) What I'm wondering is if inverting the model matrix like this actually correct or am I doing something with it which would cause this kind of behaviour? I've tried offsetting the calculated local space position in the shader with no luck (probably because the distance gets borked) and I'm starting to run out of ideas. Any help is much appreciated!


How can I get the texture file name for my polygon? I have a problem with the FBX SDK. I read in the data for the vertex position and the UV coordinates. It works fine, but now I want to read for each polygon to which texture it belongs, so that I can have models with multiple textures. Can anyone tell me how I can get the texture file name for my polygon? My code to read in vertex position and uv coordinates is the following int i, j, lPolygonCount pMesh gt GetPolygonCount() FbxVector4 lControlPoints pMesh gt GetControlPoints() int vertexId 0 for (i 0 i lt lPolygonCount i ) int lPolygonSize pMesh gt GetPolygonSize(i) for (j 0 j lt lPolygonSize j ) int lControlPointIndex pMesh gt GetPolygonVertex(i, j) FbxVector4 pos lControlPoints lControlPointIndex current model vertex index .x pos.mData 0 pivot offset 0 current model vertex index .y pos.mData 1 pivot offset 1 current model vertex index .z pos.mData 2 pivot offset 2 FbxVector4 vertex normal pMesh gt GetPolygonVertexNormal(i,j, vertex normal) current model vertex index .nx vertex normal.mData 0 current model vertex index .ny vertex normal.mData 1 current model vertex index .nz vertex normal.mData 2 read in UV data FbxStringList lUVSetNameList pMesh gt GetUVSetNames(lUVSetNameList) get lUVSetIndex th uv set const char lUVSetName lUVSetNameList.GetStringAt(0) const FbxGeometryElementUV lUVElement pMesh gt GetElementUV(lUVSetName) if(!lUVElement) continue only support mapping mode eByPolygonVertex and eByControlPoint if( lUVElement gt GetMappingMode() ! FbxGeometryElement eByPolygonVertex amp amp lUVElement gt GetMappingMode() ! FbxGeometryElement eByControlPoint ) return index array, where holds the index referenced to the uv data const bool lUseIndex lUVElement gt GetReferenceMode() ! FbxGeometryElement eDirect const int lIndexCount (lUseIndex) ? lUVElement gt GetIndexArray().GetCount() 0 FbxVector2 lUVValue get the index of the current vertex in control points array int lPolyVertIndex pMesh gt GetPolygonVertex(i,j) the UV index depends on the reference mode int lUVIndex pMesh gt GetTextureUVIndex(i, j) lUVValue lUVElement gt GetDirectArray().GetAt(lUVIndex) current model vertex index .tu (float)lUVValue.mData 0 current model vertex index .tv (float)lUVValue.mData 1 vertex index float v1 3 , v2 3 , v3 3 v1 0 current model vertex index 3 .x v1 1 current model vertex index 3 .y v1 2 current model vertex index 3 .z v2 0 current model vertex index 2 .x v2 1 current model vertex index 2 .y v2 2 current model vertex index 2 .z v3 0 current model vertex index 1 .x v3 1 current model vertex index 1 .y v3 2 current model vertex index 1 .z collision model gt addTriangle(v1,v2,v3)


glGetUniformLocation returns 23724032 as the title says, I have a problem using glGetUniformLocation call that returns, for the following code, the value 23724032. I'm writing a little engine and the draw function of my models is void Model draw() enable the shader program m material gt enable() set the current value of the ModelViewProjection matrix m material gt getShaderProgram() gt uniform("u mvp", getPose()) draw the mesh using VAO m mesh gt draw() disable the shader program m material gt disable() where void ShaderProgram uniform(std string i varName, glm mat4 amp i value) get the location of the uniform variable in the shader program GLint loc glGetUniformLocation(m programId, i varName.c str()) if(loc ! 1) glUniformMatrix4fv(loc, 1, GL FALSE, glm value ptr(i value)) My shaders are very simple vertex shader version 330 uniform mat4 u mvp attribute vec4 i position attribute vec4 i normal attribute vec2 i texcoords void main(void) gl Position u mvp i position and fragment shader version 330 precision highp float void main(void) gl FragColor vec4(1.0, 0.0, 0.0, 1.0) So, I have a question why I get this weird value from the glGetUniformLocation call? I found this topic (link) from the OpenGL discussion board, but I still don't understand why my code doesn't draw anything. If the Intel integrated video card uses its own ids for attributes and uniforms, why is this a problem? What I have to do to fix it? Note that if I run my application on high performance (with the dedicated video card), the function returns 0 as expected. My notebook is a HP Pavilion dv7 6c90el with a ATI Radeon HD 7690M XT and a Intel 3000. Thanks.


How to manage different shaders dynamically? Currently I have only a really basic shader and a shader class. My question is that if I want to make different shaders (with different uniforms, inputs, etc) how should the architecture look like? Edit I want it in a way that I can add remove modify shaders without recompiling. ( 1, 2, 3 were written before this edit, so I'm sorry if they are irrelevant now) (I wrote 4 just now, and currently I am very happy with it, but I would like to hear your opinion about it.) I have a few ideas (1.) Should I make an abstract shader class, and a derived class for every invidual shader program? (So the abstract class handles the general things, and the derived class handles the specific things, like uniforms, inputs, etc) But in my opinion this isn't a good practice, because for every shader I create, I have to create a new class too, which means that if I want to add a new shader, or modify one's source, I have to recompile the engine. (2.) Should I register the shader specific things (location of inputs, uniforms, etc.), and pass EVERY possible required data to the shader, which will use only the ones which were registered during the shader's compile time? Like Shader A needs position and normal, Shader B needs position and UV. position, normal and UV will be passed to the active shader object, and it will buffer only those which it needs (based on the registered inputs, uniforms, etc) and won't care about the others. (3.) Having every possible input, uniform etc in all the shaders. The active shader will receive every required input, uniform, etc. So a shader is only unique in its main(). Like Shader A uses input 1,2,3, shader B uses input 1,2,5. (But both of them will receive all inputs) These are the way I thought of, but these aren't very good in my opinion, there must be a good way for this. Edit (4.) What I most recently thought of Only one shader class. has a field unordered map lt name, location at shader During shader initialization, I store the input, uniforms, etc in the previously mentioned map. When I want to render the Object, I call the active shader's SetInput(...) or SetUniform(...) method These methods receive a string and a data (like vec3, vec4, mat4, etc) In these methods, I check if the string is in the map, and if it is, I buffer the data to the location. I think this is good, because there will be a few method calls for every object, and then finding a key in an unordered map is really fast. What do you say?


OpenGL Stack overflow if I do, Stack underflow if I don't! I'm in a multimedia class in college, and we're "learning" OpenGL as part of the class. I'm trying to figure out how the OpenGL camera vs. modelview works, and so I found this example. I'm trying to port the example to Python using the OpenGL bindings it starts up OpenGL much faster, so for testing purposes it's a lot nicer but I keep running into a stack overflow error with the glPushMatrix in this code def cube() for x in xrange(10) glPushMatrix() glTranslated( positionx x 1 10, 0, positionz x 1 10) translate the cube glutSolidCube(2) draw the cube glPopMatrix() According to this reference, that happens when the matrix stack is full. So I thought, "well, if it's full, let me just pop the matrix off the top of the stack, and there will be room". I modified the code to def cube() glPopMatrix() for x in xrange(10) glPushMatrix() glTranslated( positionx x 1 10, 0, positionz x 1 10) translate the cube glutSolidCube(2) draw the cube glPopMatrix() And now I get a buffer underflow error which apparently happens when the stack has only one matrix. So am I just waaay off base in my understanding? Or is there some way to increase the matrix stack size? Also, if anyone has some good (online) references (examples, etc.) for understanding how the camera model matrices work together, I would sincerely appreciate them! Thanks! EDIT Here is the pastebin of the full code http pastebin.com QXxNisuA


How forward rendering done using OpenGL? Recently I come across the term forward rendering. I'm kind of curious how this could be done in OpenGL. I have done a lot of search on this, majority of the result I get are on theory but not code implementation. May I know is there any code implementation on OpenGL for this rendering technique?


How to modify VBO data I am learning LWJGL so i can start working on my game. In order to learn LWJGL I got the idea to implement the map builder so I can get comfortable with graphics programming. Now, for the map creation tool I need to draw new elements or draw the old one's with different coordinates. Let me explain this My game will be a 2D scroller. The map will be consisting of multiple rectangles ( 2 strip triangles). When I click my left mouse button i want to start the rectangle and when I release it I want to stop the rectangle bottom right at that position. As I want to use VBOs I want to know how to modify data inside the VBO based on user input. Should i have a copy of a vertex array and then add the whole array to the VBO at each user input? How is usually implemented the VBO update?


What are the implications of using multiple OpenGL Contexts on a single thread? I'm trying to integrate two third party OpenGL rendering pipelines into the same application, namely Cinder's OpenGL API for 3D drawing and backbuffer rendering, and Google Skia's API for 2D drawing. Unfortunately, Skia tends to trigger a lot of GL state changes in general use, and offers no functionality to reset the GL state. To make matters worse, Cinder (GLNext branch) tries to keep an internal record of all of its GL state changes so that they can be easily 'unwound', but bad things can happen if its internal representation becomes different from the actual GL state. The easiest way to alleviate these problems was to create a new OpenGL context for use exclusively by Skia, performing context switches only when 2D updates were necessary. However, I've noticed some weird behaviours when I'm required to switch context more frequently, like certain draw calls failing or blend states flickering. Everything I've read about GL contexts indicates that they're meant for use in multiple threads or multiple windows. I've also read about context switches failing in certain circumstances? Is there anything terribly wrong with switching context in a single threaded, single windowed application?


Libgdx Transparent color over texture I am attempting to tint a texture a color but I want the texture to show under the tint. For example, I have a picture of a person but I want to tint them a light green and not change the transparency of the actual person itself. So far I have attempted to use the SpriteBatch method setColor which takes rgba values. When I set the alpha value to .5 it will render the tinting and the texture with that alpha value. Is there any way to separate the alpha values of the tint and the texture? I know I could draw another texture on top of it but I don't want to have two draw passes for the one texture because it will be inefficient. If there's anyway to do it in raw OpenGL that'd be great too.


Rendering up close, OpenGL performance issues I have been developing a massive RTS during the past 18 months, which is comming together nicely! Now i have an issue i can't really wrap my head around. If i render 100 models from a distance where the camera can see them all, everthing works perfectly. If i then render them when there camera is up close, my GPU goes to 100 and of course everything starts to lag. I don't really get the difference, the math is the same. Works on Nvidia m1000m and burns on AMD RX5700. OpenGl version 4.1. CPU, memory and GPU memory stays the same so i don't suspect any leaks. I have tried debugging with glGetError() and CodeXL, no luck. Am i missing something simple in OpenGL?


Best way to initialize values on 32 bit FP framebuffer in OpenGL I have a framebuffer bound to 32 bit FP texture glGenTextures(1, amp texColor) glBindTexture(GL TEXTURE 2D, texColor) glTexImage2D(GL TEXTURE 2D, 0, GL R32F, w, h, 0, GL RGBA, GL FLOAT, (GLvoid )NULL) glBindTexture(GL TEXTURE 2D, 0) glGenFramebuffers(1, amp fbo) glBindFramebuffer(GL FRAMEBUFFER, fbo) glFramebufferTexture2D(GL FRAMEBUFFER, GL COLOR ATTACHMENT0, GL TEXTURE 2D, texColor, 0) What's the best way to initialize framebuffer to a value 1000.0? The problem is that glClearColor(1000.0f, 0.0f, 0.0f, 0.0f) glClear(GL COLOR BUFFER BIT) clamps values to 0,1 interval, and clearing the texture texColor would require memory allocation of w h sizeof(float) bytes of memory and manual filling of that buffer with value 1000.0 which is slow (I would inject it using glTexImage2D). I'm using OpenGL 3.2 Core profile. Thanks, Josip


Opengl Quad Tessellation Control Shader I have the generic tessellation evaluation shader for triangles but I need to make it work for quads. Is there any chance someone could explain what is happening here and point me in the right direction? layout(triangles, equal spacing, cw) in in vec3 tcPosition out vec3 tePosition out vec3 tePatchDistance uniform mat4 Projection uniform mat4 Modelview void main() vec3 p0 gl TessCoord.x tcPosition 0 vec3 p1 gl TessCoord.y tcPosition 1 vec3 p2 gl TessCoord.z tcPosition 2 tePatchDistance gl TessCoord tePosition normalize(p0 p1 p2) gl Position Projection Modelview vec4(tePosition, 1) I understand that they're multiplying the control points (the original patch vertices) by the components of the new vertex (I guess relative to the patch verts?) and then normalizing the sum of these vectors to get the actual position of the new vertex which conforms to a nice unit sphere when applied to a cube of patches. I want to extend this to work on quads layout(quads, ...) in and add the tcPosition 3 vector but I don't really know how to get the same behavior with the fourth vertex.


OpenGL Cubemap skybox edge issue I implemented a skybox into my program using a tutorial, and using the provided 6 textures from that tutorial to make a cube map texture, my skybox looked fine. However, ever since then every other skybox texture set I have tried to add has had issues with the edges not blending together. Here is generally how they always end up looking here is my code for for loading the textures and the parameters glActiveTexture(GL TEXTURE0) textureID SOIL load OGL cubemap(textures 0 , textures 1 , textures 2 , textures 3 , textures 4 , textures 5 , 0, 0, SOIL LOAD RGB) glBindTexture(GL TEXTURE CUBE MAP, textureID) if (textureID 0) glGenTextures(1, amp textureID) int width, height unsigned char image glBindTexture(GL TEXTURE CUBE MAP, textureID) for (GLuint i 0 i lt 6 i ) GLuint sID SOIL load OGL texture(textures i , 0, 0, 0) image SOIL load image(textures i , amp width, amp height, 0, SOIL LOAD RGB) glTexImage2D(GL TEXTURE CUBE MAP POSITIVE X i, 0, GL RGB, width, height, 0, GL RGB, GL UNSIGNED BYTE, image) SOIL free image data(image) glTexParameteri(GL TEXTURE CUBE MAP, GL TEXTURE MAG FILTER, GL LINEAR) glTexParameteri(GL TEXTURE CUBE MAP, GL TEXTURE MIN FILTER, GL LINEAR) glTexParameteri(GL TEXTURE CUBE MAP, GL TEXTURE WRAP S, GL CLAMP TO EDGE) glTexParameteri(GL TEXTURE CUBE MAP, GL TEXTURE WRAP T, GL CLAMP TO EDGE) glTexParameteri(GL TEXTURE CUBE MAP, GL TEXTURE WRAP R, GL CLAMP TO EDGE) glBindTexture(GL TEXTURE CUBE MAP, 0) And code for rendering the skybox glDepthMask(GL FALSE) shader gt bind() glBindTexture(GL TEXTURE CUBE MAP, textureID) viewMatrix.r4.x 0 viewMatrix.r4.y 0 viewMatrix.r4.z 0 shader gt loadMatrix("viewMatrix", amp viewMatrix.m11) glBindVertexArray(vao) glEnableVertexAttribArray(0) glDrawArrays(GL TRIANGLES, 0, 36) glBindVertexArray(0) glBindTexture(GL TEXTURE CUBE MAP, 0) shader gt unbind() glDepthMask(GL TRUE) And the shader code const char vertexShader " version 330 r n" "in vec3 position r n " "out vec3 texCoord r n" "uniform mat4 projectionMatrix r n" "uniform mat4 viewMatrix r n" "void main() r n" " r n" "gl Position projectionMatrix viewMatrix vec4(position, 1) r n" "texCoord position r n" " " const char fragmentShader " version 330 r n" "in vec3 texCoord r n" "out vec4 color r n" "uniform samplerCube sampler r n" "void main() r n" " r n" "color texture(sampler, texCoord) r n" " " Does anyone see something that I might be missing that's causing my skybox to not render properly for most cube maps?


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


OpenGL SDL textures... game shuts down I'm going to create a game in C with SDL amp openGL but adding textures won't work. the code is in some different classes. here's the main file include "ZOMBOX.h" ZOMBOX ZOMBOX() isRunning true int ZOMBOX Execute() Init() bool mainloop false SDL Event event Create an texture unsigned int Ball texture 0 Load the image into the texture using the function Ball texture loadTexture("Smile.png") std cout lt lt "OpenGL is running n" while(isRunning) while(SDL PollEvent( amp event)) Event( amp event) if(mainloop false) std cout lt lt "Main loop has started n" mainloop true Logic() Render() Clear() SDL Quit() return 0 int main(int argc, char argv ) ZOMBOX theApp return theApp.Execute() Ok, now the rendering include "ZOMBOX.h" void ZOMBOX Render() extern float ballX extern float ballY extern float ballWH extern int vellX extern int vellY extern unsigned int Ball texture Ball texture loadTexture("Smile.png") RENDERING to the screen Enable textures when we are going to blend an texture glClear(GL COLOR BUFFER BIT) glPushMatrix() Start rendering phase glOrtho(0,800,600,0, 1,1) Set the matrix glColor4ub(0,0,0,255) White color glEnable(GL TEXTURE 2D) glBindTexture(GL TEXTURE 2D, Ball texture) glBegin(GL QUADS) Start drawing the pad We set the corners of the texture using glTexCoord2d glTexCoord2d(0,0) glVertex2f(ballX,ballY) Upper left corner glTexCoord2d(1,0) glVertex2f(ballX ballWH,ballY) Upper right corner glTexCoord2d(1,1) glVertex2f(ballX ballWH,ballY ballWH) Down right corner glTexCoord2d(0,1) glVertex2f(ballX,ballY ballWH) Down left corner glEnd() End drawing Disable textures when we are done using them glDisable(GL TEXTURE 2D) glPopMatrix() End rendering phase SDL GL SwapBuffers() SDL Delay(1) i know the comments are not right but i understand it... now the texture here's the fault i think include "ZOMBOX.h" Function for loading an image into an texture GLuint ZOMBOX loadTexture( const std string amp fileName ) SDL Surface image IMG Load( fileName.c str() ) SDL DisplayFormatAlpha(image) unsigned object(0) glGenTextures(1, amp object) glBindTexture(GL TEXTURE 2D, object) glTexParameterf(GL TEXTURE 2D, GL TEXTURE MIN FILTER, GL LINEAR) glTexParameterf(GL TEXTURE 2D, GL TEXTURE MAG FILTER, GL LINEAR) glTexParameterf(GL TEXTURE 2D, GL TEXTURE WRAP S, GL CLAMP TO EDGE) glTexParameterf(GL TEXTURE 2D, GL TEXTURE WRAP T, GL CLAMP TO EDGE) glTexImage2D(GL TEXTURE 2D, 0, GL RGBA, image gt w, image gt h, 0, GL RGBA, GL UNSIGNED BYTE, image gt pixels) Free surface SDL FreeSurface(image) return object I use variables you cant see but that's no problem thus they are not nessecary(i think). Sorry for my bad English im just a dutch highschool student.


Adding 2d hud gui to a 3d game engine which has no 2d features I have been following the 3d game engine tutorial series made by theBennyBox for a few months now, and have finally decided to create a game with it. My problem is that it is a 3d only engine which does not have an easy way to draw in 2d. The code for it is here (github) I've figured that I need to change the camera class to take in a generic matrix, so The old camera class was this public class Camera extends GameComponent private Matrix4f projection public Camera(float fov, float aspect, float zNear, float zFar) this.projection new Matrix4f().initPerspective(fov, aspect, zNear, zFar) public Matrix4f getViewProjection() Matrix4f cameraRotation getTransform().getTransformedRot().conjugate().toRotationMatrix() Vector3f cameraPos getTransform().getTransformedPos().mul( 1) Matrix4f cameraTranslation new Matrix4f().initTranslation(cameraPos.getX(), cameraPos.getY(), cameraPos.getZ()) return projection.mul(cameraRotation.mul(cameraTranslation)) Override public void addToEngine(CoreEngine engine) engine.getRenderingEngine().addCamera(this) To this public class Camera extends GameComponent private Matrix4f projection public Camera(Matrix4f projection) this.projection projection public Matrix4f getViewProjection() Matrix4f cameraRotation getTransform().getTransformedRot().conjugate().toRotationMatrix() Vector3f cameraPos getTransform().getTransformedPos().mul( 1) Matrix4f cameraTranslation new Matrix4f().initTranslation(cameraPos.getX(), cameraPos.getY(), cameraPos.getZ()) System.out.println("Location " cameraPos.getX() " " cameraPos.getY() " " cameraPos.getZ()) return projection.mul(cameraRotation.mul(cameraTranslation)) Override public void addToEngine(CoreEngine engine) engine.getRenderingEngine().setMainCamera(this) But now I don't know what to do. I can't work out how to switch between 2 cameras and draw in 2d. How would I achieve this? Thanks!!


How do I add a border to rectangles using a shader? I want to draw some rectangles with a border. Currently I render the fill with glDrawArrays(Triangles, ...) and the border with glDrawArrays(LineLoop, ...). Is there a neater way? I'm targeting OpenGL 3.3. Details Illustrative excerpt vertexBuffer gt VertexAttribArray(0) colorBuffer gt VertexAttribArray(1) texCoordBuffer gt VertexAttribArray(2) GL.DrawArrays(PrimitiveType.Triangles, 0, 12) 2 test rectangles GL.DisableVertexAttribArray(1) Disable color array GL.DisableVertexAttribArray(2) Disable texture array GL.DrawArrays(PrimitiveType.LineLoop, 0, 6) First rectangle border GL.DrawArrays(PrimitiveType.LineLoop, 6, 6) Second rectangle border Lots of draw calls for every rectangle, if there are more than the 2 test rectangles... This works fine, but I don't like having to draw the additional LineLoops for every rectangle. How can I improve this? Could I do this elegantly with a shader? Something like this VertexArributes GL.DrawArrays(Triangles, 0, vertices.Length) Shader does the border DisableVertexAttributes My current shaders Vertex version 330 core layout(location 0) in vec4 position layout(location 1) in vec4 color layout(location 2) in vec2 texCoord uniform mat4 projMatrix uniform mat4 worldMatrix out vec4 vColor out vec2 texCoords void main() gl Position projMatrix worldMatrix position texCoords 0 texCoord vColor color Fragment version 330 core in vec4 vColor in vec2 texCoords uniform sampler2D tex out vec4 fColor void main(void) fColor texture2D(tex, texCoords 0 .st) vColor


Memory leak with glfwSetWindowTitle? I am using GLFW for a game, and I have a function which allows me to set the window title. PROBLEM WITH INCREASING MEMORY USAGE void WindowSystem setTitle( const string amp title ) glfwSetWindowTitle( window, title.c str() ) This function is called once during every iteration of the main program loop, so that I can have a basic FPS counter. Under Xcode the program memory usage increases faster and faster. If I replace title.c str() with a literal, the problem does not happen, i.e., the following does not cause the same memory usage growth. DOESN'T CAUSE PROBLEM void WindowSystem setTitle( const string amp title ) glfwSetWindowTitle( window, "Hello world!" ) This where the function is called. int SystemControl update() double time glfwGetTime() double timeStep time control gt lastUpdate control gt lastUpdate time float frameRate 1.0f timeStep string windowTitle std to string( frameRate ) control gt windowSystem gt setTitle( windowTitle ) control gt physicsSystem gt update( timeStep ) return OK The string title is allocated on the stack, and should be freed at the end of update. Could there possibly be a memory leak? I understand that the pointer for c str() is internally managed, and does not need to be freed.


OpenGL get the outline of multiple overlapping objects I just had an idea for my on going game made with opengl in c I'd like to have a big outline (5 6 pixel) on multiple overlapping object when the player win something. I thought the best way is to use stencil buffer but it's few hours that I' trying to do some off screen render of the stencil buffer and I can't achieve any kind of result so probab. there are some other techniques! This is what I want to get Any ideas?


Issue translating objects by one unit in the y direction I'm currently making space invaders (in OpenGL SDL) and I'm running into an issue with the movement of the aliens. I have a 2 d vector of aliens (5 rows of 11) and I'm translating each in the x direction by a constant factor times elapsed time. If the right or leftmost alien in the vector hits either side of the screen, I decrement the y position of every alien. For some reason, when it collides the side of the screen, it infinitely translates downward in the y direction. I thought that this would not happen since I wasn't multiplying the y position by elapsed time, but I think that its probably happening due to the fact that the update() method is being called once per frame. Here is the code for the update function (inside of the enemies class which holds the 2 d array) void update(float elapsed) Update positions float minX 5.2 float maxX 5.2 bool hitRight false bool hitLeft false if the enemies haven't hit the right side if (((enemyVect 0 rightmost gt x) ((enemyVect 0 rightmost gt width) 2.0) lt maxX)) for (int i 0 i lt enemyVect.size() i ) for (int j 0 j lt enemyVect i .size() j ) enemyVect i j gt x elapsed 0.4 xDirect if they've hit the right side else if(((enemyVect 0 rightmost gt x) ((enemyVect 0 rightmost gt width) 2.0) gt maxX)) xDirect 1 hitRight true for (int i 0 i lt enemyVect.size() i ) for (int j 0 j lt enemyVect i .size() j ) if(hitRight)enemyVect i j gt y 0.6 move each row of enemyVect down to the next level hitRight false if the enemies haven't hit the left side if (((enemyVect 0 leftmost gt x) ((enemyVect 0 leftmost gt width) 2.0) gt minX)) for (int i 0 i lt enemyVect.size() i ) for (int j 0 j lt enemyVect i .size() j ) enemyVect i j gt x elapsed 0.4 xDirect if they've hit the left side else if (((enemyVect 0 leftmost gt x) (enemyVect 0 leftmost gt width 2.0) lt minX)) xDirect 1 for (int i 0 i lt enemyVect.size() i ) for (int j 0 j lt enemyVect i .size() j ) enemyVect i j gt y 0.6 move each row of enemyVect down to the next level How should I go about making it so that the y position of each alien only gets decremented once right after the collision with either side of the screen?


How To Resize Existing Texture In OpenGL 4.3 I would like to know how to resize an existing OpenGL 4.3 texture while keeping the current contents. i'm using glTexImage2D(). Do I simply re call glTexImage2D() with nullptr for the data paramater?


OpenGL rendering to multiple windows, having 1 main loop for each window I have written a little OpenGL framework in the past year that i would like to extend to support multiple windows in the near future. I have an idea about what I would like to do but I am not sure if that is possible so far. I a nutshell the inner working of my framework is as following A window is created. A render context for that window is created. An application deriving from an interface is created. window.run() is called, passing the application running in the window and the render context used as parameter. sglr W32Window w(nCmdShow) w.create(L"DemoApp", sglr DISPLAY MODE ENUM WINDOWED, sglr Resolution(800, 800)) sglr W32Rendercontext r r.create(w, 4, 0, sglr CONTEXT TYPE ENUM DEBUG) TestApp app return w.run(app, r) The run method on the Win32 implementation looks like following (just some of the code) mRunningApp gt onInit() start message loop while (1) while (PeekMessage( amp msg, NULL, 0, 0, PM REMOVE)) TranslateMessage( amp msg) DispatchMessage( amp msg) if message is WM QUIT, exit loop if (msg.message WM QUIT) break mRunningApp gt onUpdate(mDt) mRenderContext gt setAsCurrent() mRunningApp gt onRender() mRenderContext gt disableAsCurrent() What I would like to do is to create a seperate window, rendercontext and application and start a seperate main loop by calling run() just like with the first window. I already have a seperate rendercontext for each window and know about setting it active before rendering to each window. What possible solutions would exist to do that? Just running each run() method in a seperate threads sound like a kinda naive approach to me. (I admit I already tried it with failure D)


Simple mouseray picking in openGL Ive been looking at tutorials and trying to figure out how to do basic ray picking. But I'm stuck at figuring out what space to do the distance calculations in. What space does glm unproject() lead to exactly? This is what I'm doing first I get the mouse unprojected, like so mouse ray start vec3 m uproj glm unProject( vec3(mouse xy .x glutGet(GLUT WINDOW WIDTH), mouse xy .y glutGet(GLUT WINDOW HEIGHT),0.0f), workshop.access gui() gt view mat(), workshop.access gui() gt proj mat(), glm ivec4(0, 0, glutGet(GLUT WINDOW WIDTH), glutGet(GLUT WINDOW HEIGHT))) end of ray vec3 m uproj2 glm unProject( vec3(mouse xy.x glutGet(GLUT WINDOW WIDTH), mouse xy.y glutGet(GLUT WINDOW HEIGHT), 1.0f), workshop.access gui() gt view mat(), workshop.access gui() gt proj mat(), ivec4(0, 0, glutGet(GLUT WINDOW WIDTH), glutGet(GLUT WINDOW HEIGHT))) Then I find its direction, mray, like so vec3 mouse ray normalize(m uproj2 m uproj) get mray direction And Im expecting to find the closest point to some object by using this calculation vec3 closest point mouse ray glm dot(locations i , mouse ray) closest point But locations seems to be in the wrong space? Or am I thinking about this the wrong way? Ive been looking around, but I cant find anywhere that explains just this part that I must be misunderstanding. the idea is to compare the distance between closest point and locations i , but the results are incorrect. Im getting something like this Where it should be red only if the cursor is over the square. What space does glm unproj() put my ray in anyway? And in what space should I put the objects that I want to pick highlight?


using DirectX to generate a sprite sheet I am building a site in HTML5 for my client and it must run on the iPad iPhone (i.e. Safari on iOS). They want a 3D effect where they have a simple, yet, specific product they want to show on the site in 3D with user generated data as the texture. Normally, I would use either flash silverlight webgl but these are not supported on iOS. Also, CSS 3D transforms are close, but since I need a specific shape and size, creating hundreds of div elements and transforming them just wont work in the long run. My idea, is to use server side code to generate a sprite sheet that could be used on the site to fake the 3D ness of the object. What I really lack is the knowledge around DirectX OpenGL in order to automate this process. My question is, can I use DirectX OpenGL from a command line (or programatically) to pass is a model and textures to generate a PNG JPG sprite sheet of a rotating object?


OpenGL texture2d image sampling issue. Strange artifacts in texture I have an issue when using textures in OpenGL, strange artifacts occur where geometry overlaps, but not always. Video Reference. I am using a GL TEXTURE 2D with GL ARB image load store to make a custom depth test shader that stores material data for opaque and transparent geometry. The video given shows the artifacts occur where the support structure for a table is occluded behind the top of the table, but strangely, not occurring where the base of the table is occluded by the support. version 450 core in VS OUT vec3 Position vec3 Normal vec2 TexCoords mat3 TanBitanNorm fs in Material data uniform sampler2D uAlbedoMap uniform sampler2D uNormalMap uniform sampler2D uMetallicMap Material info out layout(rgba16f) coherent uniform image2D uAlbedoDepthOpaque layout(rgba16f) coherent uniform image2D uNormalMetallicOpaque layout(rgba16f) coherent uniform image2D uAlbedoDepthTransparent layout(rgba16f) coherent uniform image2D uNormalAlphaTransparent Depth info in out layout(r8) uniform image2D uDepthBufferOpaque layout(r8) uniform image2D uDepthBufferTransparent void main() vec3 n tex texture(uNormalMap, fs in.TexCoords).xyz n tex n tex 2.0f 1.0f ivec2 tx loc ivec2(gl FragCoord.xy) const float opaque depth imageLoad(uDepthBufferOpaque, tx loc).r Stored depth of opaque const float trans depth imageLoad(uDepthBufferTransparent, tx loc).r Stored depth of transparent Depth processing if (gl FragCoord.z gt opaque depth) bool tran false if (trans depth gt opaque depth) tran trans depth gt gl FragCoord.z else tran true Transparent if (texture(uAlbedoMap, fs in.TexCoords).a lt 1.0f amp amp tran) imageStore(uDepthBufferTransparent, tx loc, vec4(gl FragCoord.z)) imageStore(uAlbedoDepthTransparent, tx loc, vec4(texture(uAlbedoMap, fs in.TexCoords).rgb, gl FragCoord.z)) imageStore(uNormalAlphaTransparent, tx loc, vec4(abs(length(n tex) 1.0f) gt 0.1f ? fs in.Normal normalize(fs in.TanBitanNorm n tex), texture(uAlbedoMap, fs in.TexCoords).a)) Opaque else imageStore(uDepthBufferOpaque, tx loc, vec4(gl FragCoord.z)) imageStore(uAlbedoDepthOpaque, tx loc, vec4(texture(uAlbedoMap, fs in.TexCoords).rgb, gl FragCoord.z)) imageStore(uNormalMetallicOpaque, tx loc, vec4(abs(length(n tex) 1.0f) gt 0.1f ? fs in.Normal normalize(fs in.TanBitanNorm n tex), texture(uMetallicMap, fs in.TexCoords).r)) if (opaque depth 0.0f) imageStore(uDepthBufferOpaque, tx loc, vec4(0.125f)) else imageStore(uDepthBufferOpaque, tx loc, vec4(0.125f opaque depth)) Render with overlapping geometry shows that artifacts still occur outside of reading from the texture. Also in the video, I move the camera back and forth (with orthographic projection) and the artifacts become brighter and darker. Render with overlapping geometry w out depth processing shows that the brighter darker values were from the depth test. Any ideas on why this occurs, and how can I fix it?


Texture Not Rendering in C SDL OpenGL(glut) I don't understand why my texture("texture.bmp"), is not showing on the screen. Please help me. The whole drawing function HERE EVERYTHING IS BEING RENDERED void Main display() int startTime GetTickCount() BACKGROUND COLOR glClearColor(0.3f, 0.3f, 2.0f, 1.0f) glClear(GL COLOR BUFFER BIT GL DEPTH BUFFER BIT) LOAD THE IDENTITY MATRIX FOR THE DRAWING glLoadIdentity() SO EVERYTHING HAS THE CORRECT SIZE glTranslatef(0.0f, 0.0f, 5.0f) CAMERA MOVEMENT glTranslatef(cameraX, 0.0f, 0.0f) THE SUN glBegin(GL QUADS) glColor3f(1.0f,1.0f,0.0f) glVertex2f( 3.0f, 2.0f) The bottom left corner glVertex2f( 3.0f, 2.5f) The top left corner glVertex2f( 2.5f, 2.5f) The top right corner glVertex2f( 2.5f, 2.0f) The bottom right corner glEnd() THE GROUND glBegin(GL QUADS) glColor3f(0.5f,2.0f,0.5f) glVertex2f( 20.0f, 4.0f) glVertex2f( 20.0f, 1.0f) glVertex2f(130.0f, 1.0f) glVertex2f(130.0f, 4.0f) glColor3f(0.0f,1.0f,0.0f) for(float i 0.0f i lt 100.0f i 5.0f) glVertex2f(i, 1.0f) glVertex2f(i,ranFloat static cast lt int gt (i 4.0f) ) glVertex2f(i 1.0f,ranFloat static cast lt int gt (i 4.0f) ) glVertex2f(i 1.0f, 1.0f) glEnd() THE GRASS glBegin(GL QUADS) glColor3f(0.0f,0.5f,0.0f) glVertex2f( 20.0f, 1.2f) glVertex2f( 20.0f, 1.0f) glVertex2f(130.0f, 1.0f) glVertex2f(130.0f, 1.2f) glEnd() THE PLAYER glTranslatef(playerX,playerY,0.0f) glBegin(GL QUADS) glColor3f(1.0f,0.0f,0.0f) glVertex2f( 3.0f, 1.0f) glVertex2f( 3.0f,0.0f) glVertex2f( 2.8f,0.0f) glVertex2f( 2.8f, 1.0f) glEnd() TEXTUREEEEEEEEEEEEEEEEEEEEEE glBindTexture(GL TEXTURE 2D,texture) glEnable(GL TEXTURE 2D) int X 0 int Y 0 int Width 1 int Height 1 glBegin(GL QUADS) glTexCoord2f(0, 0) glVertex3f(X, Y, 0) glTexCoord2f(0, 1) glVertex3f(X Width, Y, 0) glTexCoord2f(1, 1) glVertex3f(X Width, Y Height, 0) glTexCoord2f(1, 0) glVertex3f(X, Y Height, 0) glEnd() glDisable(GL TEXTURE 2D) CLOUDS glBegin(GL QUADS) glColor3f(1.0f,1.0f,1.0f) for(float i 0.0f i lt 100.0f i 5.0f) glVertex2f(i,3.0f) glVertex2f(i,4.0f) glVertex2f(i 4.0f,3.0f) glVertex2f(i 4.0f,4.0f) glEnd() if(Input flying) Input returnFly(0.007f) elapsedMS GetTickCount() startTime Time since start of loop std cout lt lt "FPS " lt lt elapsedMS lt lt std endl THE ACTUAL MOVEMENT playerY playerFly elapsedMS playerX cameraSpeed 1 elapsedMS cameraX cameraSpeed elapsedMS SWAP THE BUFFERS FOR SMOOTH RENDERING glutSwapBuffers() The rest of my code has nothing to do with the texture loading. The loading is not the problem, because I didn't get any errors.


How to properly delete unwanted models I am implementing bullets into my game, and each bullet has a lifetime. Whenever the bullet has existed for a set amount of time or collides with an object, the bullet should be deleted. I implemented the timer properly and whenever the bullet reaches the end of its life, it gets deleted. The problem occurs whenever I shoot another bullet. This instantly causes a crash with the code Exception thrown at 0x044765D7 (nvoglv32.dll) in gravityGame.exe 0xC0000005 Access violation reading location 0x00000000. After some research, I've found that this usually means that I am trying to render something that is a nullptr. My thinking is that I am not deleting the previous bullet properly and this affects the new one. A single bullet object is created on startup, and every new bullet is copied using the following line of code std shared ptr lt Bullet gt bullet std make shared lt Bullet gt ( std dynamic pointer cast lt Bullet gt (modelsLoaded.at(i))) The reason for the dynamic pointer cast is because it is in a vector of its base class that it inherits from. Whenever the bullet needs to get deleted, it is erased from the bullets vector using bullets.erase(bullets.begin() index) and the object it is pointing to should go out of scope, there is nothing else pointing to it. I feel like somehow having that object getting deleted has an adverse effect on the other bullets in the vector, but I do not know how. A new object is created and all the data from the original bullet gets copied over. How could deleting a copy of an object mess with the other copied objects? The functions to create, and render the models are below. Generate Model Function binds id glGenBuffers(1, amp VBO) glGenVertexArrays(1, amp VAO) glGenBuffers(1, amp EBO) glGenTextures(1, amp texture) glBindVertexArray(VAO) glBindBuffer(GL ARRAY BUFFER, VBO) glBufferData(GL ARRAY BUFFER, verticesSizeTexture 8 sizeof(float), verticesTexture, GL STATIC DRAW) position attribute glVertexAttribPointer(0, 3, GL FLOAT, GL FALSE, 8 sizeof(float), (void )0) glEnableVertexAttribArray(0) color attribute glVertexAttribPointer(1, 3, GL FLOAT, GL FALSE, 8 sizeof(float), (void )(3 sizeof(float))) glEnableVertexAttribArray(1) glBindBuffer(GL ELEMENT ARRAY BUFFER, EBO) glBufferData(GL ELEMENT ARRAY BUFFER, indicesSizeTexture 4, indicesTexture, GL STATIC DRAW) texture glBindTexture(GL TEXTURE 2D, texture) glVertexAttribPointer(2, 2, GL FLOAT, GL FALSE, 8 sizeof(float), (void )(6 sizeof(float))) glEnableVertexAttribArray(2) glBindBuffer(GL ARRAY BUFFER, 0) glBindVertexArray(0) Rendering Function unsigned int transformLoc glGetUniformLocation(shader gt ID, quot location quot ) glUniformMatrix4fv(transformLoc, 1, GL FALSE, glm value ptr(trans)) glBindTexture(GL TEXTURE 2D, texture) glBindVertexArray(VAO) glDrawElements(GL TRIANGLES, indicesSizeTexture, GL UNSIGNED INT, 0) glBindVertexArray(0) Destructor glDeleteVertexArrays(1, amp VAO) glDeleteBuffers(1, amp VBO) glDeleteBuffers(1, amp EBO) Update After removing the contents of the destructor, the problem goes away. However, I would like to have some sort of destructor to allow for the proper freeing of memory.


Libgdx, TiledMap, and tearing My TiledMap tears when the window is specific sizes, resized, or the camera moves. The tileset is padded by 2px and have tried as high as 10px. Each tile is 70x70. Here are the pack.json settings, paddingX 2, paddingY 2, bleed true, edgePadding true, duplicatePadding true, maxWidth 4096, maxHeight 4096, filterMin Nearest, filterMag Nearest, ignoreBlankImages true, wrapX ClampToEdge, wrapY ClampToEdge, grid true, fast false Here is the code. Parameters params new Parameters() params.textureMinFilter TextureFilter.Nearest params.textureMagFilter TextureFilter.Nearest TileMap map new TmxMapLoader().load(file.getAbsolutePath(),params) So what am I doing wrong? If nothing, does that mean libgdx absolutely cannot handle TileMaps of any sort?


OpenGL not rendering textures i'm using OpenGL 2.1 with SDL2.0 and i'm trying to render a texture, using this steps load the image Image image new Image() image gt image SDL LoadBMP(path.c str()) if (!image gt image) throw std runtime error(SDL GetError()) return image and then generate a texture for it Texture2D Texture2D fromImage(const Image image) GLint format Texture2D t2d new Texture2D() glGenTextures(1, amp t2d gt tid) glBindTexture(GL TEXTURE 2D, t2d gt tid) t2d gt size.setWidth(image gt getWidth()) t2d gt size.setHeigth(image gt getHeight()) glTexParameteri(GL TEXTURE 2D, GL TEXTURE MIN FILTER, GL NEAREST) switch (image gt getBPP()) case 24 format GL RGB break case 32 format GL RGBA break default throw std runtime error("Unsurpoted pixel format!") break glTexImage2D(GL TEXTURE 2D, 0, format, image gt getWidth(), image gt getHeight(), 0, format, GL UNSIGNED BYTE, image gt getPixels()) return t2d and then i try to render it void Painter drawTexture(Texture2D texture, const SizeF amp size, const PointF amp position) camera.set(camera.getWidth(), camera.getHeight()) texture gt bind() only call glBindTexture(GL TEXTURE 2D, tid) glBegin(GL QUADS) glColor4f(color.getR(), color.getG(), color.getB(), color.getA()) glTexCoord2f(0.0f, 1.0f) glVertex2f(position.getX(), position.getY()) glTexCoord2f(1.0f, 1.0f) glVertex2f(position.getX() size.getWidth(), position.getY()) glTexCoord2f(1.0f, 0.0f) glVertex2f(position.getX() size.getWidth(), position.getY() size.getHeight()) glTexCoord2f(0.0f, 0.0f) glVertex2f(position.getX(), position.getY() size.getHeight()) glEnd() but all i got is box with the defined color, i don't understand why, i have already followed this steps before to render a texture, but this time it is not working, i'm not using glEnable(GL TEXTURE 2D) because i read that this is not necessary, but when i do call it i got the error code 1282, but i got no errors on the textures creation, can someone give me some light here? thanks


LWJGL OpenGL Texture shading I want to use LWJGL to create a shader that all it does is change the color of the given texture. For example I tell it to draw the letter A using a sprite sheet then I can tell the shader to draw the letter in a certain color. How would you do something like this without needed to create different colored letter sprite sheets? Task for the shader Simply change all pixels to a certain color in the texture. Input Color , texture. Output it draws onto the screen the new colored texture. How do i accomplish such a thing?


How should I organize my matrices in a 3D game engine? I'm working with a group of people from around the world to create a game engine (and hopefully a game with it) within the next upcoming years. My first task is to write a camera class for the engine to use in order to add cameras to the scene, with position and follow points. The problem I have is with using matrices for transformations in the class, should I keep matrices separate to each class? Such as have the model matrix in the model class, camera matrix in the camera class, or have all matrices placed in one class chuck? I could see pros and cons for each method, but I wanted to hear some input form a more professional standpoint.


OpenGL RayCasting and Intersection with plane I have been trying for a couple of days to raycast. I have a Renderable Texture Primitive Whatever placed in the WORLD at 0.0f,0.0f,0.0f, and when I click the mouse I want to know at what X,Y coordinates was the Primitive "clicked". We can safely assume that the primitive will always be at Z 0 Basically, I should do raycasting. But it does not work. I tried finding the 3D position of the ends of the ray(near far plane), and then compute the intersection, but it does not work. I tried getting Z from the DEPTH BUFFER, but I always get 0 and it still does not work. Does anyone have any fast, simple method for this?


Is OpenGl still supported in C? I'm reading the OpenGl superbible 3th edition (well I plan to) and it's all in C. Since this book was written in 2004 and all the other later versions are written in C , i was wondering whether or not OpenGl is still supported in C, and whether the relevant downloads required will still be available. I want to do it this way, because I'm more comfortable with C, and I'm still learning C .


matrix 4x4 position data I understand that a 4x4 matrix holds rotation and position data. The rotation data is held in the 3x3 sub matrix at the top left of the matrix. The position data is held in the last column of the matrix. e.g. glm vec3 vParentPos( mParent 3 0 , mParent 3 1 , mParent 3 2 ) My question is am I accessing the parent matrix correctly in the example above? I know that opengl uses a different matrix ordering that directx, (row order instead of column order or something), so, should the mParent be accessed as follows instead? glm vec3 vParentPos( mParent 0 3 , mParent 1 3 , mParent 2 3 ) thanks!