Jump to content
  • Advertisement
Sign in to follow this  
Rares

OpenGL [OpenGL] Creating a window and including shaders - problem

This topic is 3300 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

Hi, I want programming with shaders in OGL, and I have a some questions. 1. Which libraries I must include to project, if I want use shaders? 2. I have OpenGL 3.1, so what syntax I must use to shaders (ARB or normal syntax, for example: glCreateShader or glCreateShaderObjectARB)? 3. For now, I use this code to creating window and include shaders:
int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(100,100);
	glutInitWindowSize(320,320);
	glutCreateWindow("MM 2004-05");

	glutDisplayFunc(renderScene);
	glutIdleFunc(renderScene);
	glutReshapeFunc(changeSize);
	glutKeyboardFunc(processNormalKeys);

	glEnable(GL_DEPTH_TEST);
	glClearColor(1.0,1.0,1.0,1.0);

	glewInit();
	if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
		printf("Ready for GLSL\n");
	else {
		printf("No GLSL support\n");
		exit(1);
	}

	setShaders();

	glutMainLoop();

	return 0;
}
And it's working. But I want have some more control of program. I want delete glutMainLoop function and put there a:
while(1)
{
 Render();
 ....
}
But if I change it (glutMainLoop) for this while, program isn't working (window with rendered object isn't create). 4. I'm using GLEW library. I can do all things (rendering, creating window) in this library? I want change Glut function for Glew function, but I'm knowing how. 5. I'm learning GLSL from Lighthouse 3D, but I'm searching for some more. Are you knowing some pages with GLSL tutorial? BTW I'm sorry for my english and maybe I do some mistakes, but you must forgive me from this.

Share this post


Link to post
Share on other sites
Advertisement
For some OpenGL ES 2.0 tutorials: (not quite the same, but generally close enough)
http://opengles-book.com/

For everything else:
http://www.opengl.org/wiki/Main_Page

Share this post


Link to post
Share on other sites
Hmm. I have new problem. Look at the code:


#define GLFW_DLL
#include <stdio.h>
#include <GL/glew.h>
#include <GL/glfw.h>
#include <GL/glut.h>
#include <string.h>
#include "ShaderLoader.h"

float LightPosition[] = {1.0f,1.0f,3.0f};

void PrintLog(GLuint obj)
{
int infologLength = 0;
int maxLength = 100;

if(glIsShader(obj))
glGetShaderiv(obj,GL_INFO_LOG_LENGTH,&maxLength);
else
glGetProgramiv(obj,GL_INFO_LOG_LENGTH,&maxLength);

char infoLog[100];

if (glIsShader(obj))
glGetShaderInfoLog(obj, maxLength, &infologLength, infoLog);
else
glGetProgramInfoLog(obj, maxLength, &infologLength, infoLog);

if (infologLength > 0)
printf("%s\n",infoLog);
}

void changeSize(int w, int h)
{
if(h == 0)
h = 1;

float ratio = 1.0* w / h;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glViewport(0, 0, w, h);

gluPerspective(45,ratio,1,1000);
glMatrixMode(GL_MODELVIEW);
}


void renderScene(void) {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0f,1.0f,1.0f,1.0f);
glLoadIdentity();
gluLookAt(0.0,0.0,5.0,
0.0,0.0,-1.0,
0.0f,1.0f,0.0f);
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
glutSolidTeapot(1);
}

void processNormalKeys(unsigned char key, int x, int y) {

if (key == 27)
exit(0);
}

void setShaders()//const char [])
{
const char * vs = NULL;
const char * fs = NULL;

vs = SourceFileRead("toon.vert");
fs = SourceFileRead("toon.frag");

unsigned int vsID;
unsigned int fsID;

vsID = glCreateShader(GL_VERTEX_SHADER);
fsID = glCreateShader(GL_FRAGMENT_SHADER);

glShaderSource(vsID,1,&vs,NULL);
glShaderSource(fsID,1,&fs,NULL);

glCompileShader(vsID);
glCompileShader(fsID);

delete[] vs;
delete[] fs;

//PrintLog(vsID);
//PrintLog(fsID);

unsigned int Program = glCreateProgram();

glAttachShader(Program,vsID);
glAttachShader(Program,fsID);

glLinkProgram(Program);

//PrintLog(Program);

glUseProgram(Program);
}


int main(int argc, char **argv)
{
glfwInit();
glfwOpenWindow(320,320,8,8,8,8,24,0,GLFW_WINDOW );
glewInit();
if(GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader) printf("Ready for GLSL\n");
else
{
printf("No GLSL support\n");
//exit(1);
}
glfwSwapInterval(1);
setShaders();
while(1)
{
renderScene();
glfwSwapBuffers();
}
return 0;
}


Why it isn't working? After compiling, program only start and creating window. The window is white and not showing teapot (I put glutSolidTeapot in rendering function). I think that, code is correct.

Share this post


Link to post
Share on other sites
Anyone can help me?

EDIT: Ok, a problem is solved. I do connect shaders with my program.

[Edited by - Rares on September 12, 2009 6:04:07 AM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!