Fragment Shader Not Compiling & glattachShader Crashing

Currently testing code from opengl superbible 7th edition

Fragment Shader doesn’t seem to be compiling since I can compile it with junk source code, and whenever I attach it to the program(correct or not) it crashes. I’m on windows 10, using glew 4_4, with an intel i7 3770k and AMD Radeon 7950.

Vendor: ATI Technologies
Shading Language Version: 4.50
Renderer: AMD Radeon HD 7900
Version: 4.4.13

Can anyone spot what may be the problem ?

shader.h

#pragma once
#include <GL/glew.h>
#include <GLFW\glfw3.h>
#include <GL/freeglut.h>//include this last

GLuint compile_shaders(void);

shader.cpp

#include "shader.h"
#include <iostream>
GLuint compile_shaders(void)
{
	GLuint vertex_shader;
	GLuint fragment_shader = 9999;
	GLuint program;

	GLint success;
	GLchar infoLog[512];

	static const GLchar *vertex_shader_source[] =
	{
		"#version 450 core							
"
		"											
"
		"void main()								
"
		"{											
"
		"	gl_Position = vec4(0.0, 0.5, 0.5, 1.0);	
"
		"}											
"
	};

	static const GLchar *fragment_shader_source[] =
	{
		"#version 450 core					
"
		"									
"
		"out vec4 color;					
"
		"									
"
		"void main(void)					
"
		"{									
"
		" color = vec4(0.0, 0.8, 1.0, 1.0); 
"
		"}									
"
	};	
	
	vertex_shader = glCreateShader(GL_VERTEX_SHADER);
	fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);

	glShaderSource(vertex_shader, 1, vertex_shader_source, nullptr);
	glCompileShader(vertex_shader);

	//create and compile fragment shader	
	glShaderSource = (fragment_shader, 1, fragment_shader_source, nullptr);
	glCompileShader(fragment_shader);

	//Create program, attach shaders to it, and link it
	program = glCreateProgram();
	glAttachShader(program, vertex_shader);
	glAttachShader(program, fragment_shader);
	glLinkProgram(program);

	glGetProgramiv(program, GL_LINK_STATUS, &success);
	if (!success) {
		glGetProgramInfoLog(program, 512, NULL, infoLog);
		std::cerr << "LINKING_FAILED
" << infoLog << std::endl;
	}
	
	//Delete the shaders as the program has them now
	glDeleteShader(vertex_shader);
	glDeleteShader(fragment_shader);

	return 1;
}

Solution:
Turns out I’m an idiot and did this


glShaderSource = (fragment_shader, 1, fragment_shader_source, nullptr);

Fragment Shader doesn’t seem to be compiling since I can compile it with junk source code

Try to get the compilation status and logs back:


GLint Result = GL_FALSE;
GLint InfoLogLength;

glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &Result);
glGetShaderiv(fragment_shader, GL_INFO_LOG_LENGTH, &InfoLogLength);

Can’t get logs to print out. The compile status is always true, and logs are empty. I’ve tried this with two times with junk shader script with no main declaration and with perfectly fine shader scripts. I can’t get any logs to print no matter what the fragment shader code is. Could this be a driver / hardware issue ?


	GLint Result = GL_FALSE;
	GLint InfoLogLength;


	//create and compile fragment shader	
	glShaderSource = (fragment_shader, 1, fragment_shader_source, nullptr);
	glCompileShader(fragment_shader);

	glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &Result);

	if (Result == GL_FALSE)
	{
		glGetShaderiv(fragment_shader, GL_INFO_LOG_LENGTH, &InfoLogLength);
		glGetShaderInfoLog(fragment_shader, InfoLogLength, &InfoLogLength, infoLog);

		std::cout << "FRAGMENT RESULT: " << Result << std::endl;
		std::cout << "FRAGMENT: " << InfoLogLength << std::endl;

		std::vector<GLchar> errorLog(InfoLogLength);
		glGetShaderInfoLog(fragment_shader, InfoLogLength, &InfoLogLength, &errorLog[0]);

		for (std::vector<GLchar>::iterator it = errorLog.begin(); it != errorLog.end(); it++)
		{
			printf("%c", *it);
		}
		printf("
");
	}	


Change this:

void main(void)

To this:

void main()

From the GLSL spec:

The function main is used as the entry point to a shader executable. … This function takes no arguments, returns no value, and must be declared as type void … It is a compile-time or link-time error to declare or define a function main with any other parameters or return type.

(My emphasis)

[QUOTE=mhagain;1284242]Change this:

void main(void)

To this:

void main()

From the GLSL spec:
(My emphasis)[/QUOTE]

I’ve tried removing “void” as a parameter to main, and I’ve also tried typing like a monkey into the fragment shading script. My fragment script will always return compile status 1 and fetching logs returns nothing :/. The vertex shading script works & compiles fine, but attaching the fragment shading script crashes the program no what’s inside of it.

Edit: turns out I’m an idiot doing


glShaderSource = (fragment_shader, 1, fragment_shader_source, nullptr);