1 Replies - 1426 Views - Last Post: 01 November 2013 - 09:47 PM Rate Topic: -----

#1 ghillieLEAD  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 208
  • Joined: 08-March 10

OpenGL 3.2 - Draw a Fullscreen Quad

Posted 29 October 2013 - 02:07 PM

I'm trying to draw a quad that fills the window using OpenGL 3.2. I believe the method I am using should work, but it is not. My program runs, but the quad is not displayed. Shaders are compiling fine, program is linking fine. I need help spotting what the issue is here.

EDIT: After glDrawArrays(GL_QUADS, 0, 4);, glGetError() returns 1280 (GL_INVALID_ENUM). Not sure why.
EDIT: Switching to glDrawArrays(GL_TRIAGNLES, 0, 6) and altering the vertices array accordingly renders correctly.

Settings up the shader program:
	std::string _monitor_vert_source = readFile("monitor.vert");
	std::string _monitor_frag_source = readFile("monitor.frag");

	const char* monitor_vert_source = _monitor_vert_source.c_str();
	const char* monitor_frag_source = _monitor_frag_source.c_str();

	GLuint monitor_vert_shader = glCreateShader(GL_VERTEX_SHADER);
	GLuint monitor_frag_shader = glCreateShader(GL_FRAGMENT_SHADER);

	glShaderSource(monitor_vert_shader, 1, &monitor_vert_source, NULL);
	glShaderSource(monitor_frag_shader, 1, &monitor_frag_source, NULL);

	GLint shaderStatus;

	glCompileShader(monitor_vert_shader);
	glGetShaderiv(monitor_vert_shader, GL_COMPILE_STATUS, &shaderStatus);
	if (!shaderStatus == GL_TRUE)
	{
		std::cerr << "vertex shader failed to compile" << std::endl;
	}

	glCompileShader(monitor_frag_shader);
	glGetShaderiv(monitor_frag_shader, GL_COMPILE_STATUS, &shaderStatus);
	if (!shaderStatus == GL_TRUE)
	{
		std::cerr << "fragment shader failed to compile" << std::endl;
	}

	GLuint monitor_program = glCreateProgram();
	glAttachShader(monitor_program, monitor_vert_shader);
	glAttachShader(monitor_program, monitor_frag_shader);
	glLinkProgram(monitor_program);

	GLint programStatus;

	glGetProgramiv(monitor_program, GL_LINK_STATUS, &programStatus);

	if (programStatus == GL_FALSE)
	{
		std::cout << "monitor shader program failed to link" << std::endl;
	}

	glDeleteShader(monitor_vert_shader);
	glDeleteShader(monitor_frag_shader);

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

	GLuint vbo;
	glGenBuffers(1, &vbo);

	GLfloat vertices[] = {
		-1.0f, -1.0f,
		 1.0f, -1.0f,
		 1.0f,  1.0f,
		-1.0f,  1.0f
	};

	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

	GLuint position_attribute = glGetAttribLocation(monitor_program, "position");
	glVertexAttribPointer(position_attribute, 2, GL_FLOAT, GL_FALSE, 0, 0);
	glEnableVertexAttribArray(position_attribute);

	glBindVertexArray(0);



render:
	glClear(GL_COLOR_BUFFER_BIT);

	glUseProgram(monitor_program);
	glBindVertexArray(vao);
	glDrawArrays(GL_QUADS, 0, 4);

	glfwSwapBuffers(window);



vertex shader:
#version 150 core

in vec2 position;

void main()
{
	gl_Position = vec4(position, 0.0, 1.0);
}



fragment shader:
#version 150 core

void main()
{
	gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}


This post has been edited by ghillieLEAD: 29 October 2013 - 04:39 PM


Is This A Good Question/Topic? 0
  • +

Replies To: OpenGL 3.2 - Draw a Fullscreen Quad

#2 Mr_Fraggs  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 89
  • Joined: 17-June 12

Re: OpenGL 3.2 - Draw a Fullscreen Quad

Posted 01 November 2013 - 09:47 PM

If I'm going by the right versions, which I believe 3.2 is when you NEED to create your own shaders, then I don't think GL_QUADS is used really anymore. You're much better off using an element/index array, and use the values for four vertices, like it seems you were originally. Instead of GL_QUADS, you would use GL_TRIANGLES.

This post has been edited by Mr_Fraggs: 01 November 2013 - 09:48 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1