Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

126 Neutral

About Ploppz

  • Rank
  1. Thanks for the reply!   Unfortunately, it still doesn't work. I have the following changes: GLfloat triangleArray[] = { 0.0f, 8.0f, -2.0f, -2.0f, 2.0f, -2.0f }; [...] setVertexAttribPointer(shaderProgram, "position", 2, GL_FLOAT, 2*sizeof(GLfloat), 0); The  program compiles and runs without problems, but it's still only black. I did try with normalized triangle coordinates as well .
  2. Hi, I'm trying to create a basic 2D setup, using orthographic projection. I am trying to render a red triangle to screen, but the window is all black. I can't figure out what's wrong, so it would be nice if someone could just look through my files for obvious errors. The main file uses some functions from glwrapper.cpp. I also have glwrapper.h which contains the function declarations for glwrapper.cpp, with the same signatures.   main.cpp:          http://hastebin.com/tejukifije.vala glwrapper.cpp:  http://hastebin.com/odogiruviy.coffee shaders:           http://hastebin.com/begebuvobi.avrasm viewMatrix2D should return a matrix that just translates by center offset of camera. ortho2D should give an orthographic projection matrix assuming that the viewing area is symmetric. The vertex data is given in pixels, and the ortho2D matrix should correctly convert that to NCD given viewport width and height. I also tried without any projection/view, and I tried giving the triangle position using normalized coordinates.   Thanks in advance!
  3. Still doesn't work. Notice though how the quad vertex array is read: first two entries are 2D coordinates, and the next 2 entries are texture coordinates. (if I'm not wrong) glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 4*sizeof(float), 0); glVertexAttribPointer(texcoorAttrib, 2, GL_FLOAT, GL_FALSE, 4*sizeof(float), (void*)(2*sizeof(float))); Edit: Maybe it doesn't matter, but the screen isn't just black; it's not rendered at all; so it contains randomy fragments of other things that has been on my screen, like in this instance mtpaint:   (screenshot of the window that my C++ program runs in)
  4. That didn't do it either. Here's a little update: When I exchange the glDrawElements line with `glDrawArrays(GL_TRIANGLE_FAN, 0, 4);`, then the scene does get drawn correctly. However, it would be nice and maybe necessary to find out exactly what is wrong when trying to draw elements.  
  5. FIxed it (changed the glDrawElements parameter), but unfortunately it still doesn't work.
  6. Thanks for the reply! It should be 6 indices indeed. I know it's better to draw triangle fans, but I want elements to work for now, since I'm learning. The glDrawElements line looks like this now: glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, 0); And after this line: glBindVertexArray(vaoQuad); I put this: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); But it still doesn't work. Here is the current source: http://sprunge.us/CDPR
  7. Hi! I've been struggling with this for quite a while now, mostly in a bit bigger test I had. At first I was rendering a 3D scene directly to screen which worked fine. Then I tried to first render it to an intermediate framebuffer before rendering the framebuffer to screen (as a texture). When I did that, then the scene didn't render to screen anymore. Nothing was rendered to screen. If I would modify the framebuffer texture directly by for example clearing the background to some colour, then that colour would show. Thus, the problem lies in drawing the scene to the framebuffer.   I have now modified my program to be more minimal. I'm simply trying to draw a coloured triangle to screen via a framebuffer. I get the same results: with framebuffer: nothing on screen, without framebuffer: triangle is rendered correctly.   main.cpp: http://sprunge.us/FjAg   Shaders:   For the triangle: Vertex (shaders::vert) #version 150 in vec3 position; in vec3 color; out vec3 Color; void main() { Color = color; gl_Position = vec4(position, 1.0); } Fragment (shaders::frag) #version 150 in vec3 Color; out vec4 outColor; void main() { outColor = vec4(Color, 1.0); } For drawing the framebuffer texture image thing to screen: Vertex (shaders::vert2) #version 150 in vec2 position; in vec2 texcoord; out vec2 Texcoord; void main() { Texcoord = texcoord; gl_Position = vec4(position, 0.0, 1.0); } Fragment (shaders::frag2) #version 150 in vec2 Texcoord; out vec4 outColor; uniform sampler2D texFramebuffer; void main() { outColor = texture(texFramebuffer, Texcoord); } Thanks in advance.  
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!