"void main not found" OpenGL

I cannot not for the life of me figure out, what the problem is. I have tried for the past week, but I've had no luck.

Apparently, when compiling; the shader compiler cannot find the void main. The error message is
 
ERROR: Definition for "void main" not found 


According to google, this error message usually occurs when glshadersource does not load the source code properly. But from my code, I don't see how I could have loaded the shader source incorrectly. I have implemented compile error messages but they come up with nothing. In addition, I get the following error, in the command prompts:

1
2
An internal OpenGL call failed in RenderTarget.cpp (61): GL_INVALID_OPERATION, 
the specified operation is not allowed in its current state.

The following error occurs when an invalid parameter is placed in the built-in OpenGL functions. Problem is, there does not seem to be a mistake in the code.
I need a second eye.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
GLuint compiler_shader()
{

	static const GLchar * vertex_shader_source[] =
	{
		"#version 400 core 													\n",
		"																	\n",
		"layout (location = 0) in vec3 position;						    \n",
		"																	\n",
		"layout (location = 1) in vec4 color;								\n",
		"out vec4 FS_color;													\n",
		"																	\n",
		"void main(void)													\n",
		"{																	\n",
		"			                                                        \n",
		"  FS_color = color;		                                        \n",
		"  gl_Position = vec4(position.x, position.y, position.z, 1.0f);	\n",
		"			                                                        \n",
		"}			                                                        \n"
	

	};

	static const GLchar * fragment_shader_source[] =
	{
		"#version 400 core               \n",
	    "                                \n",
		"in vec4 FS_color;               \n",
		"out vec4 color_output;          \n",
		"                                \n",
		"void main(void)                 \n",
		"{                               \n",
		"  color_output = FS_color;      \n",
		"                                \n",
		"                                \n",
		"}                               \n"
		
	};


	GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
	glShaderSource(vertex_shader, 1, vertex_shader_source, nullptr);
	glCompileShader(vertex_shader);

	GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
	glShaderSource(fragment_shader, 1, fragment_shader_source, nullptr);
	glCompileShader(fragment_shader);

        GLint success1;
	GLchar info1[512];
	glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &success1);

	if(!success1)
	{
			glGetShaderInfoLog(vertex_shader, 512, nullptr, info1);
		
			for(int i = 0; i < 512; i++)
				cout << info1;

	}

	GLint success2;
	GLchar info2[512];
	glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &success2);

	if(!success2)
	{
			glGetShaderInfoLog(fragment_shader, 512, nullptr, info2);
		
			for(int i = 0; i < 512; i++)
				cout << info2;

	}




	GLuint shaderProgram = glCreateProgram();
	
	glAttachShader(shaderProgram, vertex_shader);
	glAttachShader(shaderProgram, fragment_shader);
	glLinkProgram(shaderProgram);

	GLint success3;
	GLchar info3[512];
	glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success3);

	if(!success3)
	{
		glGetProgramInfoLog(shaderProgram, 512, nullptr, info3);
		cout << "Error, Program linkage" << endl;
		for(int i = 0; i < 512; i++)
			cout << info3 ;
	}

	glDetachShader(shaderProgram, vertex_shader);
	glDetachShader(shaderProgram, fragment_shader);

	glDeleteShader(vertex_shader);
	glDeleteShader(fragment_shader);

	return shaderProgram;
}


Below is my main function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
int main()
{
	const unsigned WindowWidth = 800;
	const unsigned WindowHeight = 600;
	sf::RenderWindow Window(sf::VideoMode(WindowWidth, WindowHeight), "OpenGL VAO and VBO");

	if(GLEW_OK != glewInit())
		cout << "Error! Could not initialize Glew" << endl;


	const GLfloat vertices[] = 
	{
		 0.00f,    0.00f,    0.00f, 
		-0.50f,   -0.50f,    0.00f,
	     0.50f,   -0.50f,    0.00f
	};

	const GLfloat redColor[] = 
	{
		1.0f, 0.0f, 0.0f, 1.0f
	};
	
	GLuint Program = compiler_shader();
	

	GLuint VAO_1;
	glGenVertexArrays(1, &VAO_1);
	glBindVertexArray(VAO_1);
	    
	    
	    GLuint VBO_1;
		glGenBuffers(1, &VBO_1);     
		glBindBuffer(GL_ARRAY_BUFFER, VBO_1); 
		glBufferData(GL_ARRAY_BUFFER,  sizeof(vertices), vertices, GL_STATIC_DRAW); 
		
		glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
		glEnableVertexAttribArray(0);


		GLuint VBO_2;
		glGenBuffers(1, &VBO_2);
		glBindBuffer(GL_ARRAY_BUFFER, VBO_2);
		glBufferData(GL_ARRAY_BUFFER,  sizeof(redColor), redColor, GL_STATIC_DRAW);

		glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
		glEnableVertexAttribArray(1);


	glBindVertexArray(0);



	while(Window.isOpen())
	{
		Window.clear();

		sf::Event Event;
		while(Window.pollEvent(Event))
		{
			switch(Event.type)
			{
				case sf::Event::KeyPressed:
					if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
						Window.close();
					break;

				case sf::Event::Closed:
					Window.close();
					break;
			}

		}

		glUseProgram(Program);
		glBindVertexArray(VAO_1);
		glDrawArrays(GL_TRIANGLES, 0, 3);
		glBindVertexArray(0);

		Window.display();
	}

	glDeleteVertexArrays(1, &VAO_1);
	glDeleteBuffers(1, &VBO_1);
	glDeleteBuffers(1, &VBO_2);
	glDeleteProgram(Program);

	system("Pause");
	return 0;
}


Does anyone see the problem?



Last edited on
Maybe it's because you have an extra comma at the end of the vertex shader src string?

Anyway, you should invest in writing the code to load the shader src from a file.
Last edited on
I tried removing the comma, I still get the same problem. Could it be because I'm unbinding the VAO?

Is there an advantage of switching to files, other than it is just an alternative option. Just curious.
You are using an array with multiple dimensions to feed to glShaderSource. While that is perfectly acceptable, you must adjust the arguments to glShaderSource to reflect the nature of your array. The second argument to glShaderSource is the number of elements in the array, which you say is 1. See any problem with that?

Why are you using a multi-dimensional array anyway?
Wait never mind I see what you are saying. Thanks for the help cire, can't believe I missed that this all entire time. Wow, that was a silly mistake. Thanks again cire and htirwin for the help.
Last edited on
Topic archived. No new replies allowed.