PDA

View Full Version : Can't even draw a triangle with ATI and GL3



JoshKlint
10-09-2010, 10:20 AM
This demo displays a spinning cube and draws a square onscreen:
http://www.leadwerks.com/post/ddstest.zip

This works fine on NVidia cards. Any ideas why something so simple would only produce a blank screen on ATI cards? No gl errors occur.

This version uses OpenGL 3.1. I tried OpenGL 3.3 with the exact same result.

JoshKlint
10-11-2010, 12:50 PM
I am pretty perplexed. The code below draws a triangle in the center of the screen on my NVidia GEForce 9800. With my ATI Radeon 3870 I just get a blank blue viewport:

glViewport(0,0,GetGraphics()->GetWidth(),GetGraphics()->GetHeight());

//Load a shader
Shader* shader = LoadShader("Shaders/simple.shader");
GLuint program = ((OpenGLShaderReference*)shader->reference)->program;
glUseProgramObjectARB(program);

float vert[9];
vert[0] = 0;
vert[1] = 0;
vert[2] = 0;
vert[3] = 0;
vert[4] = 0.1;
vert[5] = 0;
vert[6] = 0.1;
vert[7] = 0.1;
vert[8] = 0;

glVertexAttribPointer((GLuint)OPENGLSURFACE_POSITI ON,3,GL_FLOAT,GL_FALSE,0,&vert[0]);
glEnableVertexAttribArray((GLuint)OPENGLSURFACE_PO SITION);

glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glClearColor(0,0,1,1);

while (!window->Closed())
{
glClear(GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES,0,3);
window->Flip();
}
Print(String(glGetError()));
return 0;
Vertex program:

#version 330

uniform mat4 projectionmatrix;

in vec3 in_Position;
in vec3 in_Color;
in vec2 in_texcoords0;

out vec3 ex_Color;
out vec2 ex_texcoords0;

//invariant gl_Position;

void main(void)
{
//gl_Position = projectionmatrix * vec4(in_Position, 1.0);
gl_Position = vec4(in_Position, 1.0);
ex_Color = in_Color;
ex_texcoords0 = in_texcoords0;
}
Fragment program:

#version 330

uniform mat4 projectionmatrix;
uniform vec4 materialcolor;
uniform sampler2D texture0;

in vec3 ex_Color;
in vec2 ex_texcoords0;

out vec4 out_Color;

void main(void)
{
out_Color = vec4(1,1,1,1);
}

JoshKlint
10-11-2010, 01:12 PM
I tried switching to VBOs instead of vertex arrays. Same result. It works fine on NVidia, nothing is drawn on ATI:

glViewport(0,0,GetGraphics()->GetWidth(),GetGraphics()->GetHeight());

//Load a shader
Shader* shader = LoadShader("Shaders/simple.shader");
GLuint program = ((OpenGLShaderReference*)shader->reference)->program;
glUseProgram(program);

float vert[9];
vert[0] = 0;
vert[1] = 0;
vert[2] = 0;
vert[3] = 0;
vert[4] = 0.1;
vert[5] = 0;
vert[6] = 0.1;
vert[7] = 0.1;
vert[8] = 0;

GLuint vbo;
glGenBuffers(1,&vbo);
glBindBuffer(GL_ARRAY_BUFFER,vbo);
glBufferData(GL_ARRAY_BUFFER,9*4,&vert[0],GL_STATIC_DRAW);
glVertexAttribPointer((GLuint)OPENGLSURFACE_POSITI ON,3,GL_FLOAT,GL_FALSE,0,NULL);
glEnableVertexAttribArray((GLuint)OPENGLSURFACE_PO SITION);

glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glClearColor(0,0,1,1);

while (!window->Closed())
{
glClear(GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES,0,3);
window->Flip();
}
Print(String(glGetError()));
return 0;

skynet
10-12-2010, 12:58 AM
Did you create and bind an Vertex Array Object (VAO)?
If not, put this somewhere at the beginning of your code:

GLuint vao=0;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);

GL3.x requires it.

Pierre Boudier
10-12-2010, 07:33 AM
glClear(GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT);


I am not sure if that is your issue, but you should try to replace the + with a |

JoshKlint
10-12-2010, 08:55 AM
Did you create and bind an Vertex Array Object (VAO)?
Yes, I tried that, and it made no difference.

aqnuep
10-12-2010, 09:28 AM
Did you create and bind an Vertex Array Object (VAO)?
GL3.x requires it.
No, it doesn't. There is an implicit vertex array object with ID 0 that is used by default.

aqnuep
10-12-2010, 10:56 AM
A few ideas:
1. Make sure OPENGLSURFACE_POSITION is 0. I don't know if it is a problem if you don't use 0 for that constant, but just to make sure it worths a try.
2. I would make sure the viewport is properly set. Can you put some queries there to double check it?

Pierre Boudier
10-12-2010, 11:15 AM
looking more into the samples, I would say that attribute setup may be the culprit; there has been reports of issues when nvidia/amd differed in the sorting of input attributes location (with apps not querying/setting it up)

skynet
10-12-2010, 01:38 PM
No, it doesn't. There is an implicit vertex array object with ID 0 that is used by default.
You are (mostly) wrong in this regard. This is what the GL3.0 specs say in section "E.1 Profiles and Deprecated Features of OpenGL 3.0":

Client vertex arrays - all vertex array attribute pointers must refer to buffer
objects (section 2.9.1). The default vertex array object (the name zero) is
also deprecated. Calling VertexAttribPointer when no buffer object or no
vertex array object is bound will generate an INVALID OPERATION error,
as will calling any array drawing command when no vertex array object is
bound.

So, any GL version >3.0 or a forward compatible GL3.0 will require an application generated VAO.

JoshKlint
10-12-2010, 01:51 PM
I would make sure the viewport is properly set. Can you put some queries there to double check it?
I am pretty sure it's correct, because the NVidia card displays just as I would expect.

somboon
10-12-2010, 07:21 PM
**delete** (due to my misunderstood)

somboon
10-12-2010, 07:24 PM
**delete** (due to my misunderstood)

Alfonse Reinheart
10-12-2010, 08:33 PM
GL3 (may) require this even if you didn't use MRT (only single frag out).

It does not. It specifically states that if there is only one output, it will automatically be bound to location 0. Assuming you don't override it explicitly.

aqnuep
10-13-2010, 09:02 AM
No, it doesn't. There is an implicit vertex array object with ID 0 that is used by default.
You are (mostly) wrong in this regard. This is what the GL3.0 specs say in section "E.1 Profiles and Deprecated Features of OpenGL 3.0":

Client vertex arrays - all vertex array attribute pointers must refer to buffer
objects (section 2.9.1). The default vertex array object (the name zero) is
also deprecated. Calling VertexAttribPointer when no buffer object or no
vertex array object is bound will generate an INVALID OPERATION error,
as will calling any array drawing command when no vertex array object is
bound.

So, any GL version >3.0 or a forward compatible GL3.0 will require an application generated VAO.
Sorry, you are right. My problem was that it is nowhere mentioned in the chapters about vertex array objects and draw commands. I think it should be stated there as well as currently it is listed only in the deprecated feature list.

JoshKlint
10-13-2010, 09:55 AM
Success!

Apparently, wglShareLists() does not share vertex array objects. Therefore you have to call this code for each graphics context you create:

GLuint vao;
glGenVertexArrays(1,&vao);
glBindVertexArray(vao);

aqnuep
10-13-2010, 10:30 AM
Yes, vertex array objects are in fact not shareable.
However, it was not visible from your code that you use multiple contexts.

JoshKlint
10-13-2010, 10:50 AM
Thanks to everyone who offered your suggestions. I'm back in business.

Alfonse Reinheart
10-13-2010, 03:27 PM
Apparently, wglShareLists() does not share vertex array objects.

In general, any "pure state objects" are not shared by share lists. While textures and renderbuffers are shared, actual FBOs are not. The same goes for feedback objects and sampler objects.