int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowSize(width, height);
	glutCreateWindow("Image Processing");
	glewInit();
	GLenum err = glewInit();
	if (GLEW_OK != err)
	{
		/* Problem: glewInit failed, something is seriously wrong. */
		std::cout << "glewInit failed, aborting." << std::endl;
		exit (1);
	}
	std::cout << "Status: Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;
	std::cout << "OpenGL version " << glGetString(GL_VERSION) << " supported" << std::endl;

	initVAO();
    initTextures();
	passthroughProgram = initShader("passthroughVS.glsl", "passthroughFS.glsl");
	boxBlurProgram = initShader("passthroughVS.glsl", "boxBlurFS.glsl");

	glutDisplayFunc(display);
	glutReshapeFunc(reshape);	
    glutKeyboardFunc(keyboard);

    glUseProgram(passthroughProgram);
    glActiveTexture(GL_TEXTURE0);

	glutMainLoop();
	return 0;
}
Example #2
0
GLuint initGLSLProgram(char *vertexShaderFilename, char *fragmentShaderFilename)
{
	GLuint shaderProgram;
	GLuint vertexShader,fragmentShader;
	vertexShader = initShader(vertexShaderFilename,GL_VERTEX_SHADER);
	fragmentShader = initShader(fragmentShaderFilename,GL_FRAGMENT_SHADER);
	shaderProgram = glCreateProgram();
	glAttachShader(shaderProgram,vertexShader);
	glAttachShader(shaderProgram,fragmentShader);
	glLinkProgram(shaderProgram);
	glUseProgram(shaderProgram);
	return shaderProgram;
}
Example #3
0
void TMIP::initializeResources() {
    auto volumes = inport_.getData();

    int numVolumes = static_cast<int>(volumes->size());
    auto samplers = std::min(maxSamplers_, numVolumes);

    initShader(shader_, samplers);

    if (numVolumes > maxSamplers_) {
        samplers = (numVolumes - maxSamplers_) % (maxSamplers_ - 1) + 1;
        initShader(shaderLast_, samplers);
    }
}
Example #4
0
unsigned int
SampleUtils::createProgramFromBuffer(const char* vertexShaderBuffer,
                                     const char* fragmentShaderBuffer)
{
#ifdef USE_OPENGL_ES_2_0    

    GLuint vertexShader = initShader(GL_VERTEX_SHADER, vertexShaderBuffer);
    if (!vertexShader)
        return 0;    

    GLuint fragmentShader = initShader(GL_FRAGMENT_SHADER,
                                        fragmentShaderBuffer);
    if (!fragmentShader)
        return 0;

    GLuint program = glCreateProgram();
    if (program)
    {
        glAttachShader(program, vertexShader);
        checkGlError("glAttachShader");
        
        glAttachShader(program, fragmentShader);
        checkGlError("glAttachShader");
        
        glLinkProgram(program);
        GLint linkStatus = GL_FALSE;
        glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
        
        if (linkStatus != GL_TRUE)
        {
            GLint bufLength = 0;
            glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength);
            if (bufLength)
            {
                char* buf = (char*) malloc(bufLength);
                if (buf)
                {
                    glGetProgramInfoLog(program, bufLength, NULL, buf);
                    LOG("Could not link program: %s", buf);
                    free(buf);
                }
            }
            glDeleteProgram(program);
            program = 0;
        }
    }
    return program;
#else
    return 0;
#endif
}
CoordSystemRenderer::CoordSystemRenderer(float length):
    _length(length)
{
    
    initShader();
    initVBO();
}
Example #6
0
void init(SDL_Surface* screen)
{
  const unsigned char* version = glGetString(GL_VERSION);
  std::cout << "OpenGL version: " << version << std::endl;

  GLint maxTex;
  glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTex);
  std::cout << "Maximum texture units: " << maxTex << std::endl;

  glClearColor(0.0, 0.0, 0.0, 1.0);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(45, static_cast<float>(screen->w)/static_cast<float>(screen->h), 1.0, 500.0);
  glMatrixMode(GL_MODELVIEW);
  glShadeModel(GL_SMOOTH); // This is the default setting anyways.

  glEnable(GL_DEPTH_TEST);

  cam = new Camera(0.0, 0.0, 0.0, 0.0, 0.0);

  initShader("shader/lighting.vs", "shader/lighting.frag", prog, vert, frag);

  monkey = obj.load("model/obj/stapler.obj");

  return;
}
Example #7
0
void LevelOneScreen::onEntry(){
	
	//Initialize SpriteFont
	_spriteFont.init("Fonts/shangri-la.ttf", 32);

	//Initialize spriteBatch
	_spriteBatch.init();

	//Initialize the shader
	initShader();

	//Initialize GUI
	initUI();

	//Initialize audio engine
	_audioEngine.init();

	loadMusic();

	//Initialize Level
	initLevel();

	_screenSize = glm::vec2(_window->getScreenWidth(), _window->getScreenHeight());

	//initialize camera
	_camera.init(_window->getScreenWidth(), _window->getScreenHeight());
	//For Debuging
	_camera.setScale(1.3);

}
Example #8
0
int main(int argc, char** argv)
{
    loadTerrain();

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA | GLUT_DOUBLE | GLUT_MULTISAMPLE);
    glutInitWindowSize(s_width, s_height);
    glutInitWindowPosition(0, 0);
    glutCreateWindow("Terrain");

    glewInit();
    initVertexBufferObject();
    initTexture();
    initShader();

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

    glutDisplayFunc(on_display);
    glutReshapeFunc(on_reshape);
    glutKeyboardFunc(on_keyboard);
    glutTimerFunc(1, on_timer, 1);
    
    glutMainLoop();

    return 0;
}
int main( int argc, char *argv[] )
{
	XVisualInfo			 *xvVisualInfo;
	Colormap			  cmColorMap;
	XSetWindowAttributes  winAttr;
	GLXContext  		  glXContext;
	int Attr[] = { GLX_RGBA,
				   GLX_RED_SIZE, 1,
				   GLX_GREEN_SIZE, 1,
				   GLX_BLUE_SIZE, 1,
				   GLX_DEPTH_SIZE, 16,
				   GLX_DOUBLEBUFFER,
				   None };
	
	// Connect to X Server
	dpy = XOpenDisplay(NULL);
	if(dpy == NULL) return 0; // Could not open display
	// GLX extension is supported?
	if(!glXQueryExtension(dpy, NULL, NULL)) return 0; // Return, if X server haven't GLX
	// Find visual
	xvVisualInfo = glXChooseVisual(dpy, DefaultScreen(dpy), Attr);
	if(xvVisualInfo == NULL) return 0; // If Visual info can't be shoosed
	// Create new colormap for our window
	cmColorMap = XCreateColormap(dpy, RootWindow(dpy, xvVisualInfo->screen), xvVisualInfo->visual, AllocNone);
	winAttr.colormap = cmColorMap;
	winAttr.border_pixel = 0;
	winAttr.background_pixel = 0;
	winAttr.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask | KeyPressMask;
	
	// Create window
	win = XCreateWindow(dpy, RootWindow(dpy, xvVisualInfo->screen),
						0, 0, 640, 480, 0,
						xvVisualInfo->depth,
						InputOutput,
						xvVisualInfo->visual,
						CWBorderPixel | CWColormap | CWEventMask,
						&winAttr);
	
	// Create OpenGL rendering context
	glXContext = glXCreateContext(dpy, xvVisualInfo, None, True);
	if(glXContext == NULL) return 0; // Can't create rendering context
	// Make it current	
	glXMakeCurrent(dpy, win, glXContext);
	// Map window on the display
	XMapWindow(dpy, win);
	
	initShader();
	loadTextures();
	
	// Enter to the main X loop
	event_loop();
	
	glDeleteTextures( 1, &datatexID );
	
	glDeleteObjectARB( g_vertexShader );
	glDeleteObjectARB( g_fragmentShader );
	glDeleteObjectARB( g_programObj );
	
	return 0;
}
void TripleChannelRaycaster::initContext(GLContextData& contextData) const
	{
	/* Create a new data item: */
	DataItem* dataItem=new DataItem;
	contextData.addDataItem(this,dataItem);
	
	/* Initialize the data item: */
	initDataItem(dataItem);
	
	try
		{
		/* Load and compile the vertex program: */
		std::string vertexShaderName=VISUALIZER_SHADERDIR;
		vertexShaderName.append("/TripleChannelRaycaster.vs");
		dataItem->shader.compileVertexShader(vertexShaderName.c_str());
		std::string fragmentShaderName=VISUALIZER_SHADERDIR;
		fragmentShaderName.append("/TripleChannelRaycaster.fs");
		dataItem->shader.compileFragmentShader(fragmentShaderName.c_str());
		dataItem->shader.linkShader();
		
		/* Initialize the raycasting shader: */
		initShader(dataItem);
		}
	catch(std::runtime_error err)
		{
		/* Print an error message, but continue: */
		std::cerr<<"TripleChannelRaycaster::initContext: Caught exception "<<err.what()<<std::endl;
		}
	}
Example #11
0
PlaneMesh::PlaneMesh():
		shader(initShader()),
		vao(initVAO(shader, vertex_attrib_idx, uniform)),
		mode(GL_TRIANGLES),
		first_idx(0), count(6) {

}
Example #12
0
File: Grid.cpp Project: PennTao/GPU
int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowSize(1027, 768);
	glutCreateWindow("Meshes with Shaders");
	glewInit();
	GLenum err = glewInit();
	if (GLEW_OK != err)
	{
		/* Problem: glewInit failed, something is seriously wrong. */
		std::cout << "glewInit failed, aborting." << std::endl;
		exit (1);
	}
	std::cout << "Status: Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;
	std::cout << "OpenGL version " << glGetString(GL_VERSION) << " supported" << std::endl;
    
    init();
	initGrid();
    initShader();
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);	
    glutKeyboardFunc(keyboard);
	
	
	glutMainLoop();
	return 0;
}
int main(int argc, char* argv[]){
	
	srand ( time(NULL) );
  
	int val=0;
		
	glutInit(&argc,argv);
	
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB );
	glutInitWindowPosition( 5, 20);
	glutInitWindowSize(300, 300);
	glutCreateWindow("OpenGL Swizzle Test on 4D Points");

	glutReshapeFunc( resize );
	glutIdleFunc( idle );
	glutDisplayFunc( draw );
	glClearColor(0.0,0.0,0.0,0.0);
	glClear(GL_COLOR_BUFFER_BIT);
	
	glewInit();
	if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
		printf("Ready for GLSL\n");
	else {
		printf("Not totally ready   \n");
		exit(1);
	}
	initPoints();
	initShader();
	glutMainLoop( );

	return(0);
}
Example #14
0
int intro_init( void )
{
    if( !EXT_Init() )
        return( 0 );
    initShader( &pid, vsh_2d, fsh_rayt );
    return 1;
}
Example #15
0
int main(int argc, char* argv[])
{
   glutInit(&argc, argv);
   glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
   glutInitWindowSize(sWidth,sHeight);
   glutCreateWindow( "FrameBuffer Objects!" );

   // Setup GLEW
   GLenum err = glewInit();
   if (err != GLEW_OK || !glewIsSupported("GL_VERSION_2_0"))
   {
      printf("OpenGL 2.0 not supported. No shaders!\n");
      printf("%s\n", glewGetErrorString(err));
      printf("%s\n", (char*)glGetString(GL_VERSION));
      return 0;
   }
   printf("OpenGL 2.0 supported.\n");

   init();
   initShader();

   glutDisplayFunc( display );
   glutReshapeFunc( reshape );
   glutKeyboardFunc( keyboard );
   glutIdleFunc( idle );
   glutMainLoop();

   return 0;
}
CoordSystem::CoordSystem(float length):
    _length(length)
{
    
    initShader();
    initVBO();
}
Example #17
0
void init(void) 
{
   initExtensionEntries ();
   initBuffer ();
   initShader ();
   initRendering ();
}
Example #18
0
int main(int argc, char** argv)
{
    int i,j;

    /* flat mesh */ 

    for(i=0;i<N;i++) for(j=0;j<N;j++) data[i][j]=0.0;

    glutInit(&argc, argv);
#ifndef __APPLE__
glewInit();
#endif
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutInitWindowSize(512, 512);
    glutCreateWindow("Simple GLSL example");
    glutDisplayFunc(draw);
    glutReshapeFunc(reshape);
    glutKeyboardFunc(keyboard);
    glutIdleFunc(idle);
    glutMouseFunc(mouseButton);
    glutMotionFunc(mouseMotion);

    init();
    initShader("vmesh.glsl", "fPassthrough.glsl");

    glutMainLoop();
    return 0 ; /* to keep compiler from complaining */
}
Example #19
0
File: glut.c Project: ifbe/tool
int main(int argc,char** argv)  
{
	int err;
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	glutInitWindowSize(512, 512);
	glutInitWindowPosition(256, 256);
	glutCreateWindow("GLSL Test : Draw a triangle");

	err = glewInit();
	if( GLEW_OK != err )printf("glewinit: %s\n", glewGetErrorString(err));  

	glViewport(0, 0, 512, 512);
	glEnable(GL_DEPTH_TEST);
	initShader();
	initVBO();  

	glutDisplayFunc(display);
	glutKeyboardFunc(keyboard);
	glutReshapeFunc(callback_reshape);
	glutMouseFunc(callback_mouse);
	glutMotionFunc(callback_move); 
      
	glutMainLoop();

	glDeleteShader(vShader);
	glUseProgram(0);
	return 0;  
}
int initGL()
{
	//初始化GLFW
	if (!glfwInit())
		return -1;

	//创建窗口
	window = glfwCreateWindow(640, 480, "Magic Cube", NULL, NULL);

	if (!window)
	{
		glfwTerminate();
		return -2;
	}

	//让窗体环境正确
	glfwMakeContextCurrent(window);

	//初始化GLEW
	if (glewInit() != GLEW_OK)
		return -3;

	initShader();
	initCallBack();

	//初始化Opengl的一些东西
	glEnable(GL_CULL_FACE);
	glCullFace(GL_FRONT);

	glfwSetWindowSize(window, 870, 512);
	
	return true;
}
int main(){
  //Change this line to use your name!
  yourName = "Karl Li";

  // Needed in OSX to force use of OpenGL3.2 
  glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
  glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
  glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

  init();
  initCuda();
  CUT_CHECK_ERROR_GL();
  initVAO();
  initTextures();

  GLuint passthroughProgram;
  passthroughProgram = initShader("shaders/passthroughVS.glsl", "shaders/passthroughFS.glsl");

  glUseProgram(passthroughProgram);
  glActiveTexture(GL_TEXTURE0);

  // send into GLFW main loop
  while(1){
    display();
    if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS || !glfwGetWindowParam( GLFW_OPENED )){
            exit(0);
    }
  }

  glfwTerminate();
  return 0;
}
Example #22
0
 void
 PhysicsDebugDrawer::init
 ()
 {
     initShader();
     initVaoVbo();
 }
Example #23
0
	bool MiniMap::init()
	{
		size = 200;

		GLuint tmpHandle;
		glGenTextures(1, &tmpHandle);
		mmTexture = TextureManager::shared().createTextureFromHandle("minimap", tmpHandle);

		if(!initShader()) {
			LOG_ERROR("Could not initialize mini-map shaders");
			return false;
		}
		if(!initFBO()) {
			LOG_ERROR("Could not initialize mini-map fbo");
		   	return false;
		}
		if(!initVAOs()) {
			LOG_ERROR("Could not initialize mini-map vao");
			return false;
		}

		mmWindow = new Window(
				vec2(-1.0, -1.0), vec2(0.0, 0.0), vec2(size),
				mmTexture, WINDOW_DRAGGABLE, "Minimap");
		Interface::shared().makeActive(mmWindow);

		return true;
	}
		void Vision::initialize(std::uint16_t & width, std::uint16_t & height)
		{
			// Firstly, let the decorated renderer (most likely the window) perform its initialization.
			//
			m_decoratedRenderer->initialize(width, height);

			m_vao.create();
			m_vao.bind();

			m_verticesPositions.create();
			m_verticesPositions.setUsagePattern(QOpenGLBuffer::StaticDraw);
			m_verticesPositions.bind();
			m_verticesPositions.allocate(verticesPositionData.constData(), verticesPositionData.size() * sizeof(QVector3D));
			m_verticesPositions.release();

			initShader();

			m_shader.bind();

			m_verticesPositions.bind();
			m_shader.enableAttributeArray(m_vertexPositionAttribute);
			m_shader.setAttributeBuffer(m_vertexPositionAttribute, GL_FLOAT, 0, 3);
			m_verticesPositions.release();

			m_shader.release();
			m_vao.release();
		}
Example #25
0
int glInit(void){
	if(debugmode) printf("DEBUG -- Initialising OpenGL \n");


	GLenum glewError = glewInit();
	if( glewError != GLEW_OK ){
		printf( "Error initializing GLEW! %s\n", glewGetErrorString( glewError ) );
		return FALSE;
	}
	glDisable(GL_DEPTH_TEST);
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);

	glEnable(GL_TEXTURE_2D);

	//todo move this stuff

	glViewport(0, 0, playwidth, playheight);
	glMatrixMode(GL_PROJECTION);// Select The Projection Matrix
	glLoadIdentity();// Reset The Projection Matrix
	glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, 0.1f, 100.0f); //maybe change
	glMatrixMode(GL_MODELVIEW);                     // Select The Modelview Matrix
	glLoadIdentity();                           // Reset The Modelview Matrix

	glColor3f(1.0f, 1.0f, 1.0f); //wont need this much longer


	//todo error checkelecking
	if(!initShader()) return FALSE;
	if(!initFB())	return FALSE;
//	glUseProgram(programobject);
	initVBO();

	return TRUE;
}
GLColoredBox::GLColoredBox(float size_x, float size_y, float size_z):
    _size_x(size_x),_size_y(size_y),_size_z(size_z)
{

    initShader();
    initVBO();
}
Example #27
0
int main(int argc, char** argv)
{
	
	readArguments(argc, argv);
	volume = new Volume();

	if(!strcmp(pathExtension, "tif"))
		volume->loadTIFData(path, firstSlice, lastSlice);
	else if(!strcmp(pathExtension, "pgm"))
		volume->loadPGMData(path, firstSlice, lastSlice);
	else
		volume->loadRAWData(path, firstSlice, firstSlice, lastSlice);

	//triCubicInterpolationPreFilter = new TriCubicInterpolationPreFilter();
	//triCubicInterpolationPreFilter->applyPreFilterForAccurateCubicBSplineInterpolation(volume->getData(), volume->getWidth(), volume->getHeight(), volume->getDepth());

	minMaxOctree = new MinMaxOctree(volume->getWidth(), volume->getHeight(), volume->getDepth());
	minMaxOctree->build(volume->getData(), volume->getWidth(), volume->getHeight(), volume->getDepth());
	
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_ALPHA);
	glutInitWindowSize(windowWidth, windowHeight);
	glutCreateWindow("Volume Rendering");

	glutReshapeFunc(reshape);
	glutDisplayFunc(display);
	glutIdleFunc(idle);
	glutKeyboardFunc(keyboard);
	glutSpecialFunc(specialKeyboard);
	glutMouseFunc(mouse);

	glewInit();
	initGL();
	
	initShader("Shaders/VRBlendRaycasting", VOLUME_RENDERING_SHADER);
	initShader("Shaders/VRContextPreservingPreIntegrationRaycasting", CONTEXT_PRESERVING_VOLUME_RENDERING_SHADER);
	initShader("Shaders/VRPreIntegrationRaycasting", PRE_INTEGRATION_TRANSFER_FUNCTION_SHADER);
	initShader("Shaders/VRLocalIlluminationPreIntegrationRaycasting", LOCAL_ILLUMINATION_SHADER);
	initShader("Shaders/VRNonPolygonalRaycasting", NON_POLYGONAL_SHADER);
	initShader("Shaders/FCNormalEstimation", FC_NORMAL_ESTIMATION_SHADER);
	initShader("Shaders/FCCurvatureEstimation", FC_CURVATURE_ESTIMATION_SHADER);
	initShader("Shaders/FCFinalRendering", FC_FINAL_RENDERING_SHADER);

	glUseProgram(0);

	glutMainLoop();
	
	delete volume;
	delete minMaxOctree;
	delete myGLImageViewer;
	delete myGLCloudViewer;
	delete transferFunction;
	delete triCubicInterpolationPreFilter;
	
	return 0;
	
}
Example #28
0
void GLWidget::resizeGL(int w, int h)
{
    // TODO:
    m_windowWidth = w;
    m_windowHeight = h;

    initShader();
}
Example #29
0
bool Self::initWithTexture(cocos2d::Texture2D* texture,
                           const cocos2d::Rect& rect, bool rotated) {
    if (not Super::initWithTexture(texture, rect, rotated)) {
        return false;
    }
    initShader();
    return true;
}
/*!
 Init the geometry object
 */
void GLObjectObjFl::init(void)
{
    if(_file_ok)
    {
        initShader();
        initVBO();
    }
}