View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# working my way around OpenGL 3.3 - GLSL 150 problems

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.

### #1DarkHorseKnight  Members

Posted 25 March 2012 - 03:09 AM

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??.

------------------------------------

#version 150

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



---------------------------

#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;\
}\
}\
}

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

////////////////////////////
///////////////////////////
#include "SurfaceStorage.h"
//////////////////////////

GLuint LoadProgram(const char * vertex_file_path, const char * Fragment_file_path){

{
string Line = "";
}

{

string Line = "";

}

GLint Result = GL_FALSE;
int InfoLogLength;

char const * VertexSourcePointer = VertexShaderCode.c_str();

char const * FragmentSourcePointer = FragmentShaderCode.c_str();

GLuint ProgramID = glCreateProgram();
//Bind Attribute
glBindAttribLocation(ProgramID, 0, "position");

//Check The Program
glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
vector<char> ProgramErrorMessage( max(InfoLogLength, int(1)) );
fprintf(stdout,  "%s\n", &ProgramErrorMessage[0]);

glUseProgram(ProgramID);

return ProgramID;

}

void draw (void)
{

//draw array
}

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;

//arrays
{  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);

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

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

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

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

}

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

}


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

### #2Xycaleth  Members

Posted 25 March 2012 - 03:33 AM

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

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.