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
|
#include "inc/primitivesRenderers.h"
#include "inc/shaderManager.h"
void key_callback(GLFWwindow* window,int key,int scancode,int action,int mode);
GLfloat vertices[] = {
// Positions // Colors // Texture Coords
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // Top Right
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // Bottom Right
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // Bottom Left
-0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f // Top Left
};
using namespace std;
int main(){
if(!glfwInit()){
std::cout<<"error: failed to init glfw"<<std::endl;
return -1;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
GLFWwindow* window = glfwCreateWindow(800,600,"streater",nullptr,nullptr);
glfwSetKeyCallback(window,key_callback);
if(window == nullptr){
std::cout<<"Failed to create GLFW window"<<std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
if(glewInit() != GLEW_OK){
std::cout<<"failed to initilize glew"<<std::endl;
return -1;
}
glViewport(0,0,800,600);
shader myshaderobject = shader("vshader.txt","fshader.txt");
myshaderobject.load();
// after load method i see the myshaderobject.VertShaderCode and myshaderobject.FragShaderCode as i planned to in shader::load()
myshaderobject.compile();
//after compile method i cant see the myshaderobject.VertShaderCode and myshaderobject.FragShaderCode as i planned to in shder::compile() and as expected some openGL shader compilation errores
//also here i think contain no data
cout<<myshaderobject.getFragShaderCode()<<endl;
cout<<myshaderobject.getVertShaderCode()<<endl;
model mdl = model(vertices);
while(!glfwWindowShouldClose(window)){
glfwPollEvents();
//rendering command here
//myshaderobject.use(); but its not compiled
mdl.draw();
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glfwSwapBuffers(window);
}
glfwTerminate();
return 0;
}
void key_callback(GLFWwindow* window,int key,int scancode,int action,int mode){
if(key == GLFW_KEY_ESCAPE && action==GLFW_PRESS)
glfwSetWindowShouldClose(window,GL_TRUE);
}
|