Cannot render triangles to an FBO

I have some code that “should” draw a triangle but it doesn’t. I have not found any way to fix it. I can use glBegin() and glEnd() but I would like to use a VBO and VAO.

glGenFramebuffers(1, &fbo_id);
	LOG(fbo_id);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo_id);

	glEnable(GL_TEXTURE_2D);
	glEnable(GL_SCISSOR_TEST);

	glGenTextures(1, &texture);
	glBindTexture(GL_TEXTURE_2D, OpenGL_FBO::texture);

	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, OpenGL_FBO::width, OpenGL_FBO::height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);

	if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
		ASSERT("Error");

	GLenum DrawBuffers[1] = { GL_COLOR_ATTACHMENT0 };
	glDrawBuffers(1, DrawBuffers);

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glBindTexture(GL_TEXTURE_2D, 0);

	if (drawDefault) {
		glBindFramebuffer(GL_FRAMEBUFFER, OpenGL_FBO::fbo_id);

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

		float vertices[] = {
			-0.0f,- 0.0f,
			-0.0f, -0.5f,
			1.0f, 0.0f
		};

		GLuint VBO;

		glGenBuffers(1, &VBO);
		glBindBuffer(GL_ARRAY_BUFFER, VBO);
		glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

		//glActiveTexture(GL_TEXTURE0);

		glViewport(0, 0, OpenGL_FBO::width, OpenGL_FBO::height);
		glScissor(0, 0, OpenGL_FBO::width, OpenGL_FBO::height);
		//glClearColor(1.0f, 0.1f, 0.1f, 1.0f);
		//glClear(GL_COLOR_BUFFER_BIT);

		//glBindBuffer(GL_ARRAY_BUFFER, 0);

		//glBindFramebuffer(GL_FRAMEBUFFER, 0);

		//glBindTexture(GL_TEXTURE_2D, OpenGL_FBO::texture);

		glDrawArrays(GL_TRIANGLES, 0, 3);

		/*glBegin(GL_TRIANGLES);
		glVertex2f(-0.0f, -0.0f);
		glVertex2f(-0.0f, -0.5f);
		glVertex2f(1.0f, 0.0f);
		glEnd();*/

		glBindFramebuffer(GL_FRAMEBUFFER, 0);

		//glBindBuffer(GL_ARRAY_BUFFER, 0);
		glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
		glBindVertexArray(0);
	}
	//glBindTexture(GL_TEXTURE_2D, 0);
	glDisable(GL_TEXTURE_2D);

Those are in the wrong order. Also, you need to call glEnableVertexAttribArray.

1 Like

Thanks! But… is there any way to make the lines smooth?

Edit: I just had to change the height. Thank