Jump to content
  • Advertisement
Sign in to follow this  
DominicHughes

OpenGL working my way around OpenGL 3.3 - GLSL 150 problems

This topic is 2457 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all Just trying to get a quad on the screen whilst trying to understand the order of functions to use to get the job done and I'm having issues getting a simple quad onto the screen.

I've tried making a projection matrix and multiplying it to the position x y z cordinates but I'm getting a silly "} parse error" have no idea why??.


Here is my shaders

Fragment Shader
------------------------------------

#version 150


//Main Entry Point
void main(void)
{
//Set Fragment Colors to Red
gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0);
}




Vertex Shader
---------------------------

#version 150
//Position Container
in vec3 position;

//TO USE A DIFFERENT COORDINATE SYSTEM JUST MULTIPLY THE MATRIX YOU WANT
mat4 Projection;

mat4 Projection{
vec4 (1.0, 0.0, 0.0, 0.0),
vec4 (0.0, 1.0, 0.0, 0.0),
vec4 (0.0, 0.0, 1.0, 0.0),
vec4 (0.0, 0.0, 0.0, 1.0)};

//Main Entry Point
void main(void)
{

//Translations and w Cordinates stuff
gl_Position = vec4(Projection * position.xyz, 1.0);
}


and here is my main.cpp

Main.cpp


//////////////////////////////
//Main Libary
/////////////////////////////
#define NO_SDL_GLEXT
#include <glew.h>
#include "SDL/SDL.H"
#include "SDL/SDL_IMAGE.H"
#include "SDL/SDL_OPENGL.H"
#undef main
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <boost/iostreams/stream.hpp>
#include <libs/iostreams/example/container_device.hpp>
#include <boost/filesystem.hpp>
#include <boost/iostreams/categories.hpp>
#include <boost/algorithm/string.hpp>
#include <vector>
#include <fstream>
#include "GL/glu.h"
////////////////////////////
using namespace std;
///////////////////////////
//DEFINES
///////////////////////////
#define SCREEN_WIDTH 1240
#define SCREEN_HEIGHT 960
#define BPP 32
#define GL_GLEXT_PROTOTYPES
#define GetError( )\
{\
for ( GLenum Error = glGetError( ); ( GL_NO_ERROR != Error ); Error = glGetError( ) )\
{\
switch ( Error )\
{\
case GL_INVALID_ENUM: printf( "\n%s\n\n", "GL_INVALID_ENUM" ); assert( 0 ); break;\
case GL_INVALID_VALUE: printf( "\n%s\n\n", "GL_INVALID_VALUE" ); assert( 0 ); break;\
case GL_INVALID_OPERATION: printf( "\n%s\n\n", "GL_INVALID_OPERATION" ); assert( 0 ); break;\
case GL_OUT_OF_MEMORY: printf( "\n%s\n\n", "GL_OUT_OF_MEMORY" ); assert( 0 ); break;\
default: break;\
}\
}\
}

///////////////////////////


////////////////////////////
//Other Header Files
///////////////////////////
#include "SurfaceStorage.h"
//////////////////////////


//Load Shader Function
GLuint LoadProgram(const char * vertex_file_path, const char * Fragment_file_path){

GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

//READ THE VERTEX SHADER CODE
string VertexShaderCode;
ifstream VertexShaderStream(vertex_file_path, std::ios::in);
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");

//Link The Program

glAttachShader(ProgramID, VertexShaderID);
glAttachShader(ProgramID, FragmentShaderID);
glLinkProgram(ProgramID);

//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;


}


void draw (void)
{

//draw array
glDrawArrays(GL_QUADS, 0, 4);
}





int main(int argc , char *argv[])
{


SDL_Init(SDL_INIT_EVERYTHING);


//Screen Position
SDL_putenv("SDL_VIDEO_CENTERED=center");


//Screen Setup
Screen = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,BPP,SDL_OPENGL|SDL_DOUBLEBUF);



//glew setup
GLenum err = glewInit();
glGetError();
if (GLEW_OK != err)
{
/* Problem: glewInit failed, something is seriously wrong. */
fprintf(stderr, "Error: %s\n", glewGetErrorString(err));

}
fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));






//On and Off Switch for Application
bool done = false;

//SDL Event
SDL_Event event;
//Global Variables

//Container for Virtual Array Object
GLuint vao;

//Container for Virtual Buffer Object
GLuint vbo;

//Top File Menu <Top ToolBar>
SDL_Surface *TopFileMenuSurf = NULL;

TopFileMenuSurf = IMG_Load("GUI/FileMenu.png");


//arrays
GLfloat FileMenuVerts[] =
{ 1.0f, 1.0f, 0.0f, 1.0f, 1.0f ,
0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f, 1.0f, 0.0f};
////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////
// OpenGL - Viewport Setup
/////////////////////////////


//Clear Color
glClearColor(0.0,0.0,0.0,0.0);

//View Port Setup
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

////////////////////////////////////////////////////////////////////////////////////////////////////

//Load Shader Program
LoadProgram("graphicaluserinterface.v", "graphicaluserinterface.f");
////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////
// Vertex Array Object <SETUP>
//////////////////////////////////
//Generate Virtual Array Object
glGenVertexArrays(1, &vao);

//Bind Vertex Array Object as the current used object
glBindVertexArray(vao);
////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////
// Vertex Buffer Object <SETUP>
//////////////////////////////////
//Generate Virtual Buffer Object
glGenBuffers(1, &vbo);

//Bind array buffer to Vertex Buffer Object
glBindBuffer(GL_ARRAY_BUFFER, vbo);

//Give data to Vertex Buffer Object
glBufferData(GL_ARRAY_BUFFER, sizeof(FileMenuVerts), FileMenuVerts, GL_STATIC_DRAW);
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////
// Attribute <SETUP>
//////////////////////////////////

//<INDEX GOES UP FOR EACH ATTRIBUTE THATS ONE MORE INDEX TO ADD TO CURRENT INDEX COUNT >//
//Set up Attribute for "index 0"
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(FileMenuVerts), 0);
//Enable Attribute for "index 0"
glEnableVertexAttribArray(0);

////////////////////////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////

//Disable Attribute for "index 0"
glDisableVertexAttribArray(0);

//////////////////
//IMAGE LOADING
/////////////////







//Main While Loop
while(!done)
{



//Clear
glClear(GL_COLOR_BUFFER_BIT);


//Logic



//draw
draw();


while(SDL_PollEvent(&event))
{
switch(event.type)
{

case SDL_QUIT:
return 0;
break;
}


}


//Update
SDL_GL_SwapBuffers();


}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


}




Thanks in Advance!



Once I can get a quad on the screen by myself I want to figure out texture mapping so smile.png

Share this post


Link to post
Share on other sites
Advertisement
In your vertex shader, you're initializing the 'Projection' matrix incorrectly. It should be:
mat4 Projection = mat4 (
vec4 (1.0, 0.0, 0.0, 0.0),
vec4 (0.0, 1.0, 0.0, 0.0),
vec4 (0.0, 0.0, 1.0, 0.0),
vec4 (0.0, 0.0, 0.0, 1.0));

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!