Search Results

Search found 1273 results on 51 pages for 'vertex shader'.

Page 13/51 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • textures and vertex arrays with OpenGL?

    - by user146780
    Basically what I'd like to do is make textured NGONS. I also want to use a tesselator (GLU) to make concave and multicontour objects. I was wondering how the texture comes into play though. I think that the tesselator will return verticies so I will add these to my array, that's fine. But my vertex array will contain more than one polygon object so then how can I tell it when to bind the texture like in immediate mode? Right now I feel stuck with one call to bind. How can this be done? Thanks

    Read the article

  • iPhone and Vertex Buffer Objects

    - by dancer
    I've just started playing around with opengl es on the iphone the past couple of weeks and i'm looking at refactoring some of my code to use Vertex Buffer Objects(VBO). Before I do though I would like to make sure it'll be worth it. The problem is that afaik the only reason you create VBO's is to shift a chunk of data onto the graphics card so that it doesn't need to be retrieved from system ram when it's used. The iPhone however does not have any dedicated ram that I'm aware of so i'm struggling to see why I would benefit at all from using VBO's. I have seen talk around the internet with conflicting opinions and apple certainly want dev's to use it so there's probably still a reason to use them but just wanted to see if anyone on SO had an opinion to add.

    Read the article

  • Help with Pixel Shader effect for brightness and contrast

    - by Hans
    What is a simple pixel shader script effect to apply brightness and contrast? I found this one, but it doesn't seem to be correct: sampler2D input : register(s0); float brightness : register(c0); float contrast : register(c1); float4 main(float2 uv : TEXCOORD) : COLOR { float4 color = tex2D(input, uv); float4 result = color; result = color + brightness; result = result * (1.0+contrast)/1.0; return result; } thanks!

    Read the article

  • Applying a pixel shader effect to a portion of an image

    - by Nick
    I have a ScrollViewer that contains a very large video (16 megapixel @ 10fps) and I want to apply a pixel shader effect to it. Given the size of the images I can't apply the effect directly to the image. So I apply the effect to the ScrollContentPresenter in the control style. Which is great, everything runs nice and fast. However, I'm also rendering annotations inside of the ScrollContentPresenter which I do NOT want effects applied to (but they need to move and scale along with the image). Is there to apply the effect just to the clipped and displayed portion of the image or do I need to build a rather more complex control?

    Read the article

  • OpenGL Vertex Array/Buffer Objects

    - by sadanjon
    Question 1 Do vertex buffer objects created under a certain VAO deleted once that VAO is deleted? An example: glGenBuffers(1, &bufferObject); glGenVertexArrays(1, &VAO); glBindVertexArray(VAO); glBindBuffer(GL_ARRAY_BUFFER, bufferObject); glBufferData(GL_ARRAY_BUFFER, sizeof(someVertices), someVertices, GL_STATIC_DRAW); glEnableVertexAttribArray(positionAttrib); glVertexAttribPointer(positionAttrib, 3, GL_FLOAT, GL_FALSE, 0, NULL); When later calling glDeleteVertexArrays(1, &VAO);, will bufferObject be deleted as well? The reason I'm asking is that I saw a few examples over the web that didn't delete those buffer objects. Question 2 What is the maximum amount of memory that I can allocate for buffer objects? It must be system dependent of course, but I can't seem find an estimation for it. What happens when video RAM isn't big enough? How would I know?

    Read the article

  • How to do geometric projection shadows?

    - by John Murdoch
    I have decided that since my game world is mostly flat I don't need better shadows than geometric projections - at least for now. The only problem is I don't even know how to do those properly - that is to produce a 4x4 matrix which would render shadows for my objects (that is, I guess, project them on a horizontal XZ plane). I would like a light source at infinity (e.g., the sun at some point in the sky) and thus parallel projection. My current code does something that looks almost right for small flying objects, but actually is a very rude approximation, as it doesn't project the objects onto the ground, but simply moves them there (I think). Also it always wrongly assumes the sun is always on the zenith (projecting straight down). Gdx.gl20.glEnable(GL10.GL_BLEND); Gdx.gl20.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); //shells shellTexture.bind(); shader.begin(); for (ShellState state : shellStates.values()) { transform.set(camera.combined); transform.mul(state.transform); shader.setUniformMatrix("u_worldView", transform); shader.setUniformi("u_texture", 0); shellMesh.render(shader, GL10.GL_TRIANGLES); } shader.end(); // shadows shader.begin(); for (ShellState state : shellStates.values()) { transform.set(camera.combined); m4.set(state.transform); state.transform.getTranslation(v3); m4.translate(0, -v3.y + 0.5f, 0); // TODO HACK: + 0.5f is a hack to ensure the shadow appears above the ground; this is overall a hack as we are just moving the shell to the surface instead of projecting it on the surface! transform.mul(m4); shader.setUniformMatrix("u_worldView", transform); shader.setUniformi("u_texture", 0); // TODO: make shadow black somehow shellMesh.render(shader, GL10.GL_TRIANGLES); } shader.end(); Gdx.gl.glDisable(GL10.GL_BLEND); So my questions are: a) What is the proper way to produce a Matrix4 to pass to openGL which would render the shadows for my objects? b) I am supposed to use another fragment shader for the shadows which would paint them in semi-transparent grey, correct? c) The limitation of this simplistic approach is that whenever there is some object on the ground (it is not flat) the shadows will not be drawn, correct? d) Do I need to add something very small to the y (up) coordinate to avoid z-fighting with ground textures? Or is the fact they will be semi-transparent enough to resolve that problem?

    Read the article

  • GLSL: How to get pixel x,y,z world position?

    - by Rookie
    I want to adjust the colors depending on which xyz position they are in the world. I tried this in my fragment shader: vec4 pos = vec4(gl_FragCoord); // get pixel position but it seems that the z-coord is always towards my camera... how do i make the coords independent from my camera position/angle? Edit: if it matters, heres my vertex shader: gl_Position = ftransform(); Edit2: changed title, so i want world coords, not screen coords!

    Read the article

  • Qt 5.3 OpenGL - vertex buffer object drawing using the core profile

    - by user3700881
    Im using Qt 5.3 to create a QWindow to do some basic rendering stuff. The QWindow is declared like this: class OpenGLWindow : public QWindow, protected QOpenGLFunctions_3_3_Core { Q_OBJECT ... } It is initialized in the constructor: OpenGLWindow::OpenGLWindow(QWindow *parent) : QWindow(parent) { QSurfaceFormat format; format.setVersion(3,3); format.setProfile(QSurfaceFormat::CoreProfile); this->setSurfaceType(OpenGLSurface); this->setFormat(format); this->create(); _context = new QOpenGLContext; _context->setFormat(format); _context->create(); _context->makeCurrent(this); this->initializeOpenGLFunctions(); ... } And that's the rendering code: void OpenGLWindow::render() { if(!isExposed()) return; _context->makeCurrent(this); glClear(GL_COLOR_BUFFER_BIT); glUseProgram(_shaderProgram); glBindBuffer(GL_ARRAY_BUFFER, _positionBufferObject); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0); glDrawArrays(GL_TRIANGLES, 0, 3); glDisableVertexAttribArray(0); glUseProgram(0); _context->swapBuffers(this); } I am trying to draw a simple triangle using a vertex and fragment shader. The problem is that the triangle is not showing up when the core profile is set. Only when I set the OpenGL version to 2.0 or when I use the compatibility profile, it shows up. From my point of view that doesn't make any sense because I am not using fixed functionality at all. What am I missing?

    Read the article

  • Need guidelines for optimizing WebGL performance by minimizing shader changes

    - by brainjam
    I'm trying to get an idea of the practicality of WebGL for rendering large architectural interior scenes, consisting of 100K's of triangles. These triangles are distributed over many objects, and there are many materials in the scene. On the other hand, there are no moving parts. And the materials tend to be fairly simple, mostly based on texture maps. There is a lot of texture map sharing .. for example all the chairs in scene will share a common map. There is also some multitexturing - up to three textures overlaid in a material. I've been doing a little experimentation and reading, and gather that frequently switching materials during a rendering pass will slow things down. For example, a scene with 200K triangles will have significant performance differences, depending on whether there are 10 or 1000 objects, assuming that each time an object is displayed a new material is set up. So it seems that if performance is important the scene should be sorted by materials so as to minimize material switching. What I'm looking for is guidelines on how to think of the overhead of various state changes, and where do I get the biggest bang for the buck. For example, what are the relative performance costs of, say, gl.useProgram(), gl.uniformMatrix4fv(), gl.drawElements() should I try to write ubershaders to minimize shader switching? should I try to aggregate geometry to minimize the number of gl.drawElements() calls I realize that mileage may vary depending on browser, OS, and graphics hardware. And I'm also not looking for heroic measures. Just some guidelines from people who have already had some experience in making scenes fast. I'll add that while I've had some experience with fixed-pipeline OpenGL programming in the past, I'm rather new to the WebGL/OpenGL ES 2.0 way of doing things.

    Read the article

  • opengl shader make color "disappear"

    - by JFoulkes
    hi, I'm new to opengl and shaders. I'm trying to do some augmented reality on the iphone and messing about with shaders to alter a feed from the camera. What I'm trying to achieve is the appearance that an object in a picture has disappeared by setting the color to match the surrounding colour. I have a yellow rectangle and in it is a small red circle. I want to give the impressed the red circle has disappeared by setting the colour to be yellow. It won't always be solid colours but I'm just trying to get the basics down first. Currently I have a simple shader which will make a red colour lighter but this isn't ideal because it doesn't get close to the surrounding colour and I want this to work for different coloured objects and different coloured surrounding. I'm not even 100% shaders are what I need to be looking at or even opengl. I'm using it because of the performance it gives on the iPhone. I'm basically asking if: Anyone has done or seen anything similar Am I barking up the wrong tree using opengl es and opengl sl? Is this even possible? Cheers.

    Read the article

  • Why don't I need to bind my vertex buffer object before calling glDrawArrays?

    - by valmo
    I'm a bit confused why this still renders. I thought you need to bind a vertex buffer object so that glDrawArrays knows which vertex buffer to use. Here is my initialisation code.. // Create and bind vertex array to store vertex attribute states. glGenVertexArraysOES(NUM_VERTEX_ARRAYS, &m_vertexArray); glBindVertexArrayOES(m_vertexArray); // Create and bind vertex buffer to store vertex data. glGenBuffers(NUM_VERTEX_BUFFERS, &m_vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * 36, &m_vertices[0], GL_STATIC_DRAW); glEnableVertexAttribArray(VertexAttribPosition); glVertexAttribPointer(VertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0)); glEnableVertexAttribArray(VertexAttribNormal); glVertexAttribPointer(VertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12)); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArrayOES(0); Here is my render code. I'm confused why glDrawArrays still works when I bind 0 to GL_ARRAY_BUFFER. glBindVertexArrayOES(m_vertexArray); glBindBuffer(GL_ARRAY_BUFFER, 0); glDrawArrays(GL_TRIANGLES, 0, 36); glBindVertexArrayOES(0);

    Read the article

  • How do i use GraphMLReader2 in Jung?

    - by askus
    I want to use class GraphMLReader to read a Undirected Graph from graphML with JUNG2.0. The code is as follow: import edu.uci.ics.jung.io.*; import edu.uci.ics.jung.io.graphml.*; import java.io.*; import java.util.*; import org.apache.commons.collections15.Transformer; import edu.uci.ics.jung.graph.*; class Vertex{ int id; String type; String value; } class Edge{ int id ; String type; String value; } public class Loader{ static String src = "test.xsl"; public static void Main( String[] args){ Reader reader = new FileReader(src ); Transformer<NodeMetadata, Vertex> vtrans = new Transformer<NodeMetadata,Vertex>(){ public Vertex transform(NodeMetadata nmd ){ Vertex v = new Vertex() ; v.type = nmd.getProperty("type"); v.value = nmd.getProperty("value"); v.id = Integer.valueOf( nmd.getId() ); return v; } }; Transformer<EdgeMetadata, Edge> etrans = new Transformer<EdgeMetadata,Edge>(){ public Edge transform( EdgeMetadata emd ){ Edge e = new Edge() ; e.type = emd.getProperty("type"); e.value = emd.getProperty("value"); e.id = Integer.valueOf( emd.getId() ); return e; } }; Transformer<HyperEdgeMetadata, Edge> hetrans = new Transformer<HyperEdgeMetadata,Edge>(){ public Edge transform( HyperEdgeMetadata emd ){ Edge e = new Edge() ; e.type = emd.getProperty("type"); e.value = emd.getProperty("value"); e.id = Integer.valueOf( emd.getId() ); return e; } }; Transformer< GraphMetadata , UndirectedSparseGraph> gtrans = new Transformer<GraphMetadata,UndirectedSparseGraph>(){ public UndirectedSparseGraph<Vertex,Edge> transform( GraphMetadata gmd ){ return new UndirectedSparseGraph<Vertex,Edge>(); } }; GraphMLReader2< UndirectedSparseGraph<Vertex,Edge> , Vertex , Edge> gmlr = new GraphMLReader2< UndirectedSparseGraph<Vertex,Edge> ,Vertex, Edge>( reader, gtrans, vtrans, etrans, hetrans); UndirectedSparseGraph<Vertex,Edge> g = gmlr.readGraph(); return ; } } However, compiler alert that: Loader.java:60: cannot find symbol symbol : constructor GraphMLReader2(java.io.Reader,org.apache.commons.collections15.Transformer<edu.uci.ics.jung.io.graphml.GraphMetadata,edu.uci.ics.jung.graph.UndirectedSparseGraph>,org.apache.commons.collections15.Transformer<edu.uci.ics.jung.io.graphml.NodeMetadata,Vertex>,org.apache.commons.collections15.Transformer<edu.uci.ics.jung.io.graphml.EdgeMetadata,Edge>) location: class edu.uci.ics.jung.io.graphml.GraphMLReader2<edu.uci.ics.jung.graph.UndirectedSparseGraph<Vertex,Edge>,Vertex,Edge> new GraphMLReader2< UndirectedSparseGraph<Vertex,Edge> ,Vertex, Edge>( ^ 1 error How can i solve this problem? Thanks.

    Read the article

  • iPad GLSL. From within a fragment shader how do I get the surface - not vertex - normal

    - by dugla
    Is it possible to access the surface normal - the normal associated with the plane of a fragment - from within a fragment shader? Or perhaps this can be done in the vertex shader? Is all knowledge of the associated geometry lost when we go down the shader pipeline or is there some clever way of recovering that information in either the vertex of fragment shader? Thanks in advance. Cheers, Doug twitter: @dugla

    Read the article

  • Do GLSL geometry shaders work on the GMA X3100 under OSX

    - by GameFreak
    I am trying to use a trivial geometry shader but when run in Shader Builder on a laptop with a GMA X3100 it falls back and uses the software render. According this document the GMA X3100 does support EXT_geometry_shader4. The input is POINTS and the output is LINE_STRIP. What would be required to get it to run on the GPU (if possible) uniform vec2 offset; void main() { gl_Position = gl_PositionIn[0]; EmitVertex(); gl_Position = gl_PositionIn[0] + vec4(offset.x,offset.y,0,0); EmitVertex(); EndPrimitive(); }

    Read the article

  • WebGL transparent black.

    - by Catalin Dumitru
    I have a strange problem that I can't figure out when trying to do blending in WebGL. Black is rendered fully transparent , and everything with shades of grey in it is rendered also semi transparent. I have set it to use the alpha channel as the source for transparency, and in some respect it works, every thing that isn't black/grey is rendered differently when changing the alpha value. but even when I set the alpha to 1, black is still displayed transparent. This is how I enable transparency: this.gl.blendFunc(this.gl.SRC_ALPHA, this.gl.ONE); this.gl.enable(this.gl.BLEND); this.gl.disable(this.gl.DEPTH_TEST); And the part of the shader that does transparency: gl_FragColor = vec4(texColor.rgb * vLightWeight, texColor.a * uAlpha); where texColor is the texture color that is being sampled, vLightWeight is the shadowing that is being calculated in the vertex shader, and uAlpha the uniform which I use for transparency.

    Read the article

  • Number range for color in GLSL

    - by kotoko
    I'm figuring out how to set a colour in a Fragment Shader. This statement gl_FragColor = (0.1,0.6,1,1); gives me white regardless of what I enter in the first 3 values. I was expecting to either give it values between 0 and 255 or 0 and 1 but neither seems to work. I can change how bright it is with values from 0 to 1 in the fourth value, but nothing for colour. Can anybody tell me if: gl_FragColor is the right variable to set. What is the range of values for the first three values. What am I currently making the Shader do.

    Read the article

  • glutPostRedisplay() does not update display

    - by A D
    I am currently drawing a rectangle to the screen and would like to move it by using the arrow keys. However, when I press an arrow key the vertex data changes but the display does refresh to reflect these changes, even though I am calling glutPostRedisplay(). Is there something else that I must do? My code: #include <GL/glew.h> #include <GL/freeglut.h> #include <GL/freeglut_ext.h> #include <iostream> #include "Shaders.h" using namespace std; const int NUM_VERTICES = 6; const GLfloat POS_Y = -0.1; const GLfloat NEG_Y = -0.01; struct Vertex { GLfloat x; GLfloat y; Vertex() : x(0), y(0) {} Vertex(GLfloat givenX, GLfloat givenY) : x(givenX), y(givenY) {} }; Vertex left_paddle[NUM_VERTICES]; void init() { glClearColor(1.0f, 1.0f, 1.0f, 0.0f); left_paddle[0] = Vertex(-0.95f, 0.95f); left_paddle[1] = Vertex(-0.95f, 0.0f); left_paddle[2] = Vertex(-0.85f, 0.95f); left_paddle[3] = Vertex(-0.85f, 0.95f); left_paddle[4] = Vertex(-0.95f, 0.0f); left_paddle[5] = Vertex(-0.85f, 0.0f); GLuint vao; glGenVertexArrays( 1, &vao ); glBindVertexArray( vao ); GLuint buffer; glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(left_paddle), NULL, GL_STATIC_DRAW); GLuint program = init_shaders( "vshader.glsl", "fshader.glsl" ); glUseProgram( program ); GLuint loc = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( loc ); glVertexAttribPointer( loc, 2, GL_FLOAT, GL_FALSE, 0, 0); glBindVertexArray(vao); } void movePaddle(Vertex* array, GLfloat change) { for(int i = 0; i < NUM_VERTICES; i++) { array[i].y = array[i].y + change; } glutPostRedisplay(); } void special( int key, int x, int y ) { switch ( key ) { case GLUT_KEY_DOWN: movePaddle(left_paddle, NEG_Y); break; } } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDrawArrays(GL_TRIANGLES, 0, 6); glutSwapBuffers(); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(500,500); glutCreateWindow("Rectangle"); glewInit(); init(); glutDisplayFunc(display); glutSpecialFunc(special); glutMainLoop(); return 0; }

    Read the article

  • How to code a 4x shader/filter which emulates arcade crt display behavior?

    - by Arthur Wulf White
    I want to write a shader/filer probably in adobe Pixel Bender that will do the best job possible in emulating the fill of an oldskul monochromatic arcade CRT screen. Much like this here: http://filthypants.blogspot.com/2012/07/customizing-cgwgs-crt-pixel-shader.html Here are some attributes I know will exist in this filter: It will take in a low res image 160 x 120 and return a medium res image 640 x 480. It will add scanlines It will blur the color channels to create that color bleeding effect It will distort the shape of the image from a perfect rectangle into a rounder shape. The question is, could you please provide any other attributes that are beneficial to emulating an arcade CRT feel and links and resources on coding these effects. Thanks

    Read the article

  • GLSL Shader Effects: How to do motion blur, etc?

    - by DevilWithin
    I am not sure how right it is to ask this question, but still here it goes. I have a full 2D environment, with sprites going around as landscape, characters, etc And to make it more state-of-art looking, i want to implement a motion blur effect, similar to modern FPS's (i.e. crysis) blur when moving fast the camera. In a sidescroller, the desired effect is having this slight blur appearing to give the idea of fast movement, when the camera is moving. If anyone could give me some tips on doing this, im assuming in a pixel shader, i'd be grate. Also, if anyone has other good tips on cool pixel shader effects for 2D games it would be awesome, like some stylizing post fx, such as previous Prince of Persia illustrative style. Thanks

    Read the article

  • XNA Diffuse Shader Issue. Edge lighting problem. Image Attached

    - by adtither
    As you can see in this image the diffuse shading is working correctly in some places but in other places such as the the bottom of the sphere you can see the squares/triangles of the mesh. Any idea what would be causing this? Let me know if you need anymore information related to code. I can upload my normals calculations and shader effect if required. EDIT: Here's a link to the shader I'm using http://pastebin.com/gymVc7CP Link to normals calculations: http://pastebin.com/KnMGdzHP Seems to be an issue with edge lighting. Can't seem to see where I'm going wrong with the normals calculations though.

    Read the article

  • What is the difference between Constant Vertex Attributes and Uniforms?

    - by Samaursa
    According to the OpenGL ES 2.0 Programming Guide: A constant vertex attribute is the same for all vertices of a primitive, and therefore only one value needs to be specified for all the vertices of a primitive. For uniforms the book states: ...any parameter to a shader that is constant across either all vertices or fragments (but that is not known at compile time) should be passed in as a uniform. I've always used uniforms for data that is constant for a primitive but now it appears that attributes can also be used in the same way. Is there more to constant vertex attribute than simply 'they are the same as uniforms'?

    Read the article

  • How to implement Fog Of War with an shader?

    - by Cambrano
    Okay, I'm creating a RTS game and want to implement an AgeOfEmpires-like Fog Of War(FOW). That means a tile(or pixel) can be: 0% transparent (unexplored) 50% transparent black (explored but not in viewrange) 100% transparent(explored and in viewrange) RTS means I'll have many explorers (NPCs, buildings, ...). Okay, so I have an 2d array of bytes byte[,] explored. The byte value correlates the transparency. The question is, how do I pass this array to my shader? Well I think it is not possible to pass an entire array. So: what technique shall I use to let my shader know if a pixel/tile is visible or not?

    Read the article

  • How do I pass vertex and color positions to OpenGL shaders?

    - by smoth190
    I've been trying to get this to work for the past two days, telling myself I wouldn't ask for help. I think you can see where that got me... I thought I'd try my hand at a little OpenGL, because DirectX is complex and depressing. I picked OpenGL 3.x, because even with my OpenGL 4 graphics card, all my friends don't have that, and I like to let them use my programs. There aren't really any great tutorials for OpenGL 3, most are just "type this and this will happen--the end". I'm trying to just draw a simple triangle, and so far, all I have is a blank screen with my clear color (when I set the draw type to GL_POINTS I just get a black dot). I have no idea what the problem is, so I'll just slap down the code: Here is the function that creates the triangle: void CEntityRenderable::CreateBuffers() { m_vertices = new Vertex3D[3]; m_vertexCount = 3; m_vertices[0].x = -1.0f; m_vertices[0].y = -1.0f; m_vertices[0].z = -5.0f; m_vertices[0].r = 1.0f; m_vertices[0].g = 0.0f; m_vertices[0].b = 0.0f; m_vertices[0].a = 1.0f; m_vertices[1].x = 1.0f; m_vertices[1].y = -1.0f; m_vertices[1].z = -5.0f; m_vertices[1].r = 1.0f; m_vertices[1].g = 0.0f; m_vertices[1].b = 0.0f; m_vertices[1].a = 1.0f; m_vertices[2].x = 0.0f; m_vertices[2].y = 1.0f; m_vertices[2].z = -5.0f; m_vertices[2].r = 1.0f; m_vertices[2].g = 0.0f; m_vertices[2].b = 0.0f; m_vertices[2].a = 1.0f; //Create the VAO glGenVertexArrays(1, &m_vaoID); //Bind the VAO glBindVertexArray(m_vaoID); //Create a vertex buffer glGenBuffers(1, &m_vboID); //Bind the buffer glBindBuffer(GL_ARRAY_BUFFER, m_vboID); //Set the buffers data glBufferData(GL_ARRAY_BUFFER, sizeof(m_vertices), m_vertices, GL_STATIC_DRAW); //Set its usage glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex3D), 0); glVertexAttribPointer(1, 4, GL_FLOAT, GL_TRUE, sizeof(Vertex3D), (void*)(3*sizeof(float))); //Enable glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); //Check for errors if(glGetError() != GL_NO_ERROR) { Error("Failed to create VBO: %s", gluErrorString(glGetError())); } //Unbind... glBindVertexArray(0); } The Vertex3D struct is as such... struct Vertex3D { Vertex3D() : x(0), y(0), z(0), r(0), g(0), b(0), a(1) {} float x, y, z; float r, g, b, a; }; And finally the render function: void CEntityRenderable::RenderEntity() { //Render... glBindVertexArray(m_vaoID); //Use our attribs glDrawArrays(GL_POINTS, 0, m_vertexCount); glBindVertexArray(0); //unbind OnRender(); } (And yes, I am binding and unbinding the shader. That is just in a different place) I think my problem is that I haven't fully wrapped my mind around this whole VertexAttribArray thing (the only thing I like better in DirectX was input layouts D:). This is my vertex shader: #version 330 //Matrices uniform mat4 projectionMatrix; uniform mat4 viewMatrix; uniform mat4 modelMatrix; //In values layout(location = 0) in vec3 position; layout(location = 1) in vec3 color; //Out values out vec3 frag_color; //Main shader void main(void) { //Position in world gl_Position = vec4(position, 1.0); //gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(in_Position, 1.0); //No color changes frag_color = color; } As you can see, I've disable the matrices, because that just makes debugging this thing so much harder. I tried to debug using glslDevil, but my program just crashes right before the shaders are created... so I gave up with that. This is my first shot at OpenGL since the good old days of LWJGL, but that was when I didn't even know what a shader was. Thanks for your help :)

    Read the article

  • How can I read from multiple textures in an OpenGL ES 2 shader?

    - by Peyman Tahghighi
    How can I enable more than one texture in OpenGL ES 2 so that I can sample from all of them in my shader? For example, I'm trying to read from two different textures in my shader for the player's car. This is how I'm currently dealing with the texture for my car: glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, this->texture2DObj); glUniform1i(1, 0); glBindBuffer(GL_ARRAY_BUFFER, this->vertexBuffer); glEnableVertexAttribArray(0); int offset = 0; glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, this->vertexBufferSize,(const void *)offset); offset += 3 * sizeof(GLfloat); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, this->vertexBufferSize, (const void*)offset); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->indexBuffer); glDrawElements(GL_TRIANGLES, this->indexBufferSize, GL_UNSIGNED_SHORT, 0); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1);

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >