Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Crash when compiling/linking/using GLSL shaders in win32?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 DarkHorseKnight   Members   -  Reputation: 143

Like
0Likes
Like

Posted 14 April 2012 - 05:12 AM

Hello I was just trying to use GLSL shaders in win32 but having issues with my function:

//LOAD SHADER FUNCTION
GLuint LoadProgram(const char * vertex_file_path, const char * Fragment_file_path)
{
  GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
  cout << "Vertex Shader Creation" << endl;
  GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
  cout << "Fragment Shader Creation" << endl;
  //READ THE VERTEX SHADER CODE
  string VertexShaderCode;
  ifstream VertexShaderStream(vertex_file_path, std::ios::in);
  cout << "Reading Vertex Shader" << endl;
  if(VertexShaderStream.is_open())
  {
	string Line = "";
	while(getline(VertexShaderStream, Line))
	  VertexShaderCode += "\n" + Line;
	VertexShaderStream.close();
  }
  //READ THE FRAGMENT SHADER CODE
  string FragmentShaderCode;
  ifstream FragmentShaderStream(Fragment_file_path, std::ios::in);
  if(FragmentShaderStream.is_open())
  {
	string Line = "";
	while(getline(FragmentShaderStream, Line))
	  FragmentShaderCode += "\n" + Line;
	FragmentShaderStream.close();
  }
  GLint Result = GL_FALSE;
  int InfoLogLength;
  //Compile Vertex Shader
  printf("Compiling Shader : %s\n", vertex_file_path);
  char const * VertexSourcePointer = VertexShaderCode.c_str();
  glShaderSource(VertexShaderID,  1,  &VertexSourcePointer,  NULL);
  glCompileShader(VertexShaderID);
  //Check Vertex Shader
  glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS,  &Result);
  glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
  vector<char> VertexShaderErrorMessage(InfoLogLength);
  glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
  fprintf(stdout, "%s\n",  &VertexShaderErrorMessage[0]);
  //Compile Fragment Shader
  printf("Compiling Shader : %s\n",  Fragment_file_path);
  char const * FragmentSourcePointer = FragmentShaderCode.c_str();
  glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL);
  glCompileShader(FragmentShaderID);
  //Check Fragment Shader
  glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
  glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
  vector<char> FragmentShaderErrorMessage(InfoLogLength);
  glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
  fprintf(stdout,  "%s\n",  &FragmentShaderErrorMessage[0]);
  fprintf(stdout,  "Linking Program\n");
  GLuint ProgramID = glCreateProgram();
  //Bind Attribute
  glBindAttribLocation(ProgramID, 0, "position");
  glBindAttribLocation(ProgramID, 1, "Texcoord0");
  //Link The Program
  glAttachShader(ProgramID, VertexShaderID);
  glAttachShader(ProgramID, FragmentShaderID);
  glLinkProgram(ProgramID);
  texture1 = glGetUniformLocation(ProgramID, "myTextureSampler");
  matrixuniform =  glGetUniformLocation(ProgramID, "myMatrix");

  //Check The Program
  glGetProgramiv(ProgramID,  GL_LINK_STATUS, &Result);
  glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
  vector<char> ProgramErrorMessage( max(InfoLogLength, int(1)) );
  fprintf(stdout,  "%s\n", &ProgramErrorMessage[0]);
  //Delete Shader
  glDeleteShader(VertexShaderID);
  glDeleteShader(FragmentShaderID);
  glUseProgram(ProgramID);
  //Return ProgramID
  return ProgramID;
}

this function ^^
EDIT: It crashes after that function ^^

not being executed after I call
hRC = wglCreateContext(hDC);

or any other time

I have no idea why? could someone tell me what the common errors are for this function not working in win32? it works in SDL/C++? so why shouldn't it work with this ???.



Thanks in advance

Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 14215

Like
1Likes
Like

Posted 14 April 2012 - 05:25 AM

I don’t understand. Your topic mentions a crash but your post does not. Your post says that function is not executed (called?) after wglCreateContext() or any other time.
Exactly what is the error?


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 DarkHorseKnight   Members   -  Reputation: 143

Like
0Likes
Like

Posted 14 April 2012 - 05:26 AM

it crashes thats why it won't execute should have made that clearer damit lol

#4 thetooth   Members   -  Reputation: 103

Like
2Likes
Like

Posted 14 April 2012 - 09:50 AM

I tested your code and found nothing _wrong_ with what it does, you could lay off the STL a bit but i was able to load a shader and run it, so your crash is being caused by something else.

Posted Image

Also it would help if you posted some more information, im sure your debugger will give you a stack trace, so just follow that and see what the environment looks like at that point in time.

One more thing to note is its not a good idea to delete your shaders after linking, just in case you decide(or more importantly, the driver decides) the shader needs to be recompiled you will have linker problems.

#5 RobinsonUK   Members   -  Reputation: 108

Like
0Likes
Like

Posted 14 April 2012 - 11:19 AM

arghhh. Sorry, edit fail... deleted :-).

#6 DarkHorseKnight   Members   -  Reputation: 143

Like
0Likes
Like

Posted 14 April 2012 - 12:11 PM

I fixed my problem I forgot to use wglMakeCurrent(hDC, hRC); after wglCreateContext(hDC) Stupid error. but now my problem is trying to do texture mapping I need to get a HBITMAP to a glTexImage2D function in OpenGL has any one had any luck with this?.

#7 thetooth   Members   -  Reputation: 103

Like
0Likes
Like

Posted 14 April 2012 - 12:27 PM

http://msdn.microsoft.com/en-us/library/dd183371(v=vs.85).aspx

all of the data needed to handle the image provided for you in that type, just initialise the texture with the contents of bmBits, afaik this is just raw pixel data which is what opengl takes using glTexImage2D, where this gets tricky is if you're trying to use some built in resources or perhaps a strange format, in which case you'll have to pay attention to the encoding of the pixel data other wise you'll end up with garbage or no output.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS