コード例 #1
0
ファイル: gfx_gl_log.c プロジェクト: Peanhua/diamond-girl
void gfx_gl_error(char * fmt, ...)
{
  if(globals.opengl)
    {
      GLenum err;
  
      err = glGetError();
      if(err != GL_NO_ERROR)
        {
          va_list ap;
          char buf[1024];
      
          va_start(ap, fmt);
          vsnprintf(buf, sizeof buf, fmt, ap);
          va_end(ap);
          fprintf(stderr, "OpenGL error %d: %s\n%s\n", (int) err, gluErrorString(err), buf);
        }
      assert(err == GL_NO_ERROR);
    }
}
コード例 #2
0
ファイル: geometry.cpp プロジェクト: srlzcc/GridTree
void ExitOnGLError(const char* error_message)
{
	const GLenum ErrorValue = glGetError();

	if (ErrorValue != GL_NO_ERROR)
	{
		const char* APPEND_DETAIL_STRING = ": %s\n";
		const size_t APPEND_LENGTH = strlen(APPEND_DETAIL_STRING) + 1;
		const size_t message_length = strlen(error_message);
		char* display_message = (char*)malloc(message_length + APPEND_LENGTH);

		memcpy(display_message, error_message, message_length);
		memcpy(&display_message[message_length], APPEND_DETAIL_STRING, APPEND_LENGTH);

		fprintf(stderr, display_message, gluErrorString(ErrorValue));

		free(display_message);
		exit(EXIT_FAILURE);
	}
}
コード例 #3
0
ファイル: main.cpp プロジェクト: remis/chai3d
void draw(void)
{
    // set the background color of the world
    cColorf color = camera->getParentWorld()->getBackgroundColor();
    glClearColor(color.getR(), color.getG(), color.getB(), color.getA());

    // clear the color and depth buffers
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // render world in the window display
    camera->renderView(width, height);

    // check for any OpenGL errors
    GLenum err;
    err = glGetError();
    if (err != GL_NO_ERROR) printf("Error:  %s\n", gluErrorString(err));

    // Swap buffers
    glutSwapBuffers();
}
コード例 #4
0
ファイル: SimText3D.cpp プロジェクト: hksonngan/astrocytes
void SimText3D::transferToTexture(GLuint texID) 
{
	if(texID==-1)texID=texture;
    glBindTexture(texture_target, texID);

	static PFNGLTEXIMAGE3DPROC glTexImage3D = (PFNGLTEXIMAGE3DPROC) wglGetProcAddress("glTexImage3D");
	static PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D = (PFNGLTEXSUBIMAGE3DPROC) wglGetProcAddress("glTexSubImage3D");
	
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

//To copy texels from the framebuffer, use glCopyTexSubImage2D. 
//glBindTexture(GL_TEXTURE_2D, textureID);    //A texture you have already created with glTexImage2D
//glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height);   //Copy back buffer to texture


//Then came the programmable GPU. There aren't texture units anymore. Today, you have texture samplers. These are also called texture image units (TIU) which you can get with 
//int MaxTextureImageUnits;
//glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &MaxTextureImageUnits);

//For texture coordinates, you can get the max with 
//int MaxTextureCoords;
//glGetIntegerv(GL_MAX_TEXTURE_COORDS, &MaxTextureCoords);

	if(dim_num==1)glTexImage1D(texture_target,0,internal_format,width,0,texture_format,t_type,arr);
	if(dim_num==2)glTexImage2D(texture_target,0,internal_format,width,height,0,texture_format,t_type,arr);
	if(dim_num==3)
	{
		glTexImage3D(texture_target,0,internal_format,width,height,depth,0,texture_format,t_type,0);

		glTexSubImage3D(texture_target,0,0,0,0,width,height,depth,texture_format,t_type,arr);
	}
	GLenum errCode;
	const GLubyte *errString;
	 errCode=glGetError();
	if (errCode!=GL_NO_ERROR)
	{
		  errString=gluErrorString(errCode);
//		  std::cout<<ln((char*)errString);
	}
	
}
コード例 #5
0
void draw(void)
{
    GLenum err;
    GLdouble secs, degrees;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    /* one revolution every 10 seconds... */
    secs = get_secs();
    secs = secs - 10.*trunc(secs / 10.);
    degrees = (secs/10.) * (360.);

    draw_room();

    glEnable(GL_BLEND);
    glEnable(GL_CULL_FACE);
    if (degrees < 180) {
      /* sphere behind cone */
      glCullFace(GL_FRONT);
      draw_sphere(degrees);
      draw_cone();
      glCullFace(GL_BACK);
      draw_sphere(degrees);
      draw_cone();
    } else {
      /* cone behind sphere */
      glCullFace(GL_FRONT);
      draw_cone();
      draw_sphere(degrees);
      glCullFace(GL_BACK);
      draw_cone();
      draw_sphere(degrees);
    }
    glDisable(GL_CULL_FACE);
    glDisable(GL_BLEND);

    err = glGetError();
    if (err != GL_NO_ERROR) printf("Error:  %s\n", gluErrorString(err));

    glutSwapBuffers();
}
コード例 #6
0
ファイル: 01-devices.cpp プロジェクト: jateeq/FYDP
void updateGraphics(void)
{
    // update content of position label
    for (int i=0; i<numHapticDevices; i++)
    {
        // read position of device an convert into millimeters
        cVector3d pos;
        hapticDevices[i]->getPosition(pos);
        pos.mul(1000);

        // create a string that concatenates the device number and its position.
        string strID;
        cStr(strID, i);
        string strLabel = "#" + strID + "  x: ";

        cStr(strLabel, pos.x, 2);
        strLabel = strLabel + "   y: ";
        cStr(strLabel, pos.y, 2);
        strLabel = strLabel + "  z: ";
        cStr(strLabel, pos.z, 2);

        labels[i]->m_string = strLabel;
    }

    // render world
    camera->renderView(displayW, displayH);

    // Swap buffers
    glutSwapBuffers();

    // check for any OpenGL errors
    GLenum err;
    err = glGetError();
    if (err != GL_NO_ERROR) printf("Error:  %s\n", gluErrorString(err));

    // inform the GLUT window to call updateGraphics again (next frame)
    if (simulationRunning)
    {
        glutPostRedisplay();
    }
}
コード例 #7
0
ファイル: main.cpp プロジェクト: mudusun/VRspaceshooter2016
void display()
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  float startFps = glutGet(GLUT_ELAPSED_TIME);
  float deltaFps = startFps - oldfps;
  oldfps = startFps;
  gm->update(1/deltaFps*1000);
  gm->render();

  /* check for errors that may occur in OpenGL */
  GLenum err = glGetError();
  if (err != GL_NO_ERROR)
	 std::cout << "OpenGL error: " << gluErrorString(err) << std::endl;
  std::cout.flush();

 


  if(keyPressed[KEY_ID_W]==true)      gm->getCam()->moveForward();
  if(keyPressed[KEY_ID_A]==true)      gm->getCam()->moveLeft();
  if(keyPressed[KEY_ID_D]==true)      gm->getCam()->moveRight();
  if(keyPressed[KEY_ID_S]==true)      gm->getCam()->moveBackward();
  if(keyPressed[KEY_ID_X]==true)      gm->getCam()->moveUp();
  if(keyPressed[KEY_ID_C]==true)      gm->getCam()->moveDown();


  if (keyPressed[KEY_ID_RIGHT] == true)  gm->getShip()->moveRight();
  if (keyPressed[KEY_ID_LEFT] == true)   gm->getShip()->moveLeft();
  if (keyPressed[KEY_ID_UP] == true)     gm->getShip()->moveUp();
  if (keyPressed[KEY_ID_DOWN] == true)   gm->getShip()->moveDown();
  if ((keyPressed[KEY_ID_SPACE] == true)&& (gm->getShip()->getLife() > 0))
  {
	  gm->addBulletPlayer();
	  keyPressed[KEY_ID_SPACE] = false;
  }  

  glutSwapBuffers();
  glutPostRedisplay();

}
コード例 #8
0
ファイル: interp.c プロジェクト: AlexGreulich/HRTFVR
void draw(void)
{
    GLenum err;
    GLfloat s, absx, abs1minusx;

    glClear(GL_COLOR_BUFFER_BIT | GL_ACCUM_BUFFER_BIT);
    glRasterPos2i(0, 0);
    glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, in0);

    absx = fabs(x);
    abs1minusx = fabs(1.-x);
    s = absx > abs1minusx ? absx : abs1minusx;

    if (!isIR) {
	glAccum(GL_ACCUM, (1. - x) / s);
	glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, in1);
	glAccum(GL_ACCUM, x/s);
	glAccum(GL_RETURN, s);
    } else {
	if (fabs(x) < 1. && fabs(1. - x) < 1) {
	    glAccum(GL_ACCUM, 1. - x);
	    glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, in1);
	    glAccum(GL_ACCUM, x);
	    glAccum(GL_RETURN, 1);	
	} else {
	    absx = fabs(x);
	    abs1minusx = fabs(1.-x);
	    s = absx > abs1minusx ? absx : abs1minusx;

	    glAccum(GL_ACCUM, .8 * ((1. - x) / s));
	    glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, in1);
	    glAccum(GL_ACCUM, .8 * x/s);
	    glAccum(GL_RETURN, 1.2 * s);
	}
    }

    err = glGetError();
    if (err != GL_NO_ERROR) printf("Error:  %s\n", gluErrorString(err));

    glutSwapBuffers();
}
コード例 #9
0
ファイル: screendoor.c プロジェクト: AlexGreulich/HRTFVR
void draw(void)
{
    GLenum err;
    GLdouble secs;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    draw_room();
    draw_cone();
    secs = get_secs();

    /* draw the transparent object... */
    glEnable(GL_POLYGON_STIPPLE);
    draw_sphere(secs * 360. / 10.);
    glDisable(GL_POLYGON_STIPPLE);

    err = glGetError();
    if (err != GL_NO_ERROR) printf("Error:  %s\n", gluErrorString(err));

    glutSwapBuffers();
}
コード例 #10
0
ファイル: chptthree.2.c プロジェクト: juantresde/opengl
void DestroyShaders (void)
{
  GLenum ErrorCheckValue = glGetError ();
  glUseProgram (0);

  glDetachShader (ProgramId, VertexShaderId);
  glDetachShader (ProgramId, FragmentShaderId);

  glDeleteShader (FragmentShaderId);
  glDeleteShader (VertexShaderId);

  glDeleteProgram (ProgramId);

  ErrorCheckValue = glGetError ();
  if (ErrorCheckValue != GL_NO_ERROR) {
    fprintf (stderr, "ERROR: Could not destroy the shaders: %s \n",
	     gluErrorString (ErrorCheckValue)
	     );
    exit (EXIT_FAILURE);
  }
}
コード例 #11
0
/*
 * DO NOT call this function before the gl context has initialized.  It will make an infinite loop.
 * This is because glGetError always returns GL_INVALID_OPERATION before there exists a context. There's
 * code in here to catch the loop and stop, but it will still produce unnecessary scary output.
 */
void checkGlError(int line /*= -1*/) {
    GLenum glErr = glGetError();
    if (glErr != GL_NO_ERROR) {
        OUTSTREAM << "<!>    GL error(s) detected";
        if (line > 0) {
            OUTSTREAM << " at line " << line;
        }
        OUTSTREAM << ":\n";
        int loopGuard = 0;
        while (glErr != GL_NO_ERROR) {
            if (++loopGuard <= 10) {
                OUTSTREAM << "\t\t\t" << gluErrorString(glErr) << std::endl;
                glErr = glGetError();
            }
            else {
                OUTSTREAM << "\t\t\t<!> Suppressing further errors...\n";
                break;
            }
        }
    }
}
コード例 #12
0
int CheckGLError(char *file, int line)
{
	//return 0;
	GLenum glErr,glErr2;
	int retCode = 0;

	glErr = glErr2 = glGetError();
	while (glErr != GL_NO_ERROR) 
	{
	   char* str1 = (char*)gluErrorString(glErr);
	   if (str1)
			cout << "GL Error #" << glErr << "(" << str1 << ") " << " in File " << file << " at line: " << line << endl;
	   else
			cout << "GL Error #" << glErr << " in File " << file << " at line: " << line << endl;
		retCode = 1;
		glErr = glGetError();
	}
	if (glErr2 != GL_NO_ERROR) while(1)Sleep(100);;

	return 0;
}
コード例 #13
0
void updateGraphics(void)
{
    int px;

    // update haptic rate label
    labelHapticRate->setString ("haptic rate: "+cStr(frequencyCounter.getFrequency(), 0) + " [Hz]");

    px = (int)(0.5 * (displayW - labelHapticRate->getWidth()));
    labelHapticRate->setLocalPos(px, 15);

    // render world
    camera->renderView(displayW, displayH);

    // swap buffers
    glutSwapBuffers();

    // check for any OpenGL errors
    GLenum err;
    err = glGetError();
    if (err != GL_NO_ERROR) printf("Error:  %s\n", gluErrorString(err));
}
コード例 #14
0
ファイル: gpu_utils.c プロジェクト: slash-dev-null/gsoc
/**
 * Checks for OpenGL errors.
 * Extremely useful debugging function: When developing, 
 * make sure to call this after almost every GL call.
 */
void checkGLErrors (const char *label) {
    GLenum errCode;
    const GLubyte *errStr;
    
    if ((errCode = glGetError()) != GL_NO_ERROR) {
	errStr = gluErrorString(errCode);
	printf("OpenGL ERROR: ");
	printf((char*)errStr);
	printf("(Label: ");
	printf(label);
	printf(")\n");
    }
    else {
      printf("[ OK ]");
      printf((char*)errStr);
      printf("(Label: ");
      printf(label);
      printf(")\n");
    }
      
}
コード例 #15
0
/* Fonction callback par defaut appelee lors d'un rafraichissement de fenetre */
static void fonctionAffichage(void)
{
#ifdef DEBUG_MODE
	GLenum erreur;
#endif
//	glLoadIdentity();

	/* On appelle tout simplement la fonction generique de gestion des evenements */
	gestionEvenement(Affichage);
	glutSwapBuffers();

#ifdef DEBUG_MODE
	/* Afficher une erreur OpenGL si celle-ci a eu lieu */
	if
	   ((erreur = glGetError()) != GL_NO_ERROR)
	{
		printf("Erreur OpenGL %d : ", (int)erreur);
		puts((const char *)gluErrorString(erreur));
	}
#endif
}
コード例 #16
0
bool initGL()
{

  c2x= new float[animalgridsize*animalgridsize];
  c2y= new float[animalgridsize*animalgridsize];
  Centro2x= new float[animalgridsize*animalgridsize];
  Centro2y= new float[animalgridsize*animalgridsize];
  



  glutSetWindow(1);
  //Initialize Projection Matrix
  glMatrixMode( GL_PROJECTION );
  glLoadIdentity();

  double auxborder=border*territorialidad;
  
  glOrtho( -auxborder-0.5, auxborder, -auxborder-0.5, auxborder, 1.0, -1.0 );
  
  
  //Initialize Modelview Matrix
  glMatrixMode( GL_MODELVIEW );
  glLoadIdentity();
  //Initialize clear color
  glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
  // rojo, verde, azul y alfa. 
  //Valore entre 0 y 1 punto flotante.
  

  //Check for error
  GLenum error = glGetError();
  if( error != GL_NO_ERROR )
    {
      printf( "Muere, no pude inicializar OpenGL!! %s\n", gluErrorString( error ) );
      return false;
    };
  
  return true;
};
コード例 #17
0
ファイル: terrain.c プロジェクト: astrofimov/vgallium
static void
loadpic(void)
{
   GLubyte bufferter[256 * 256], terrainpic[256 * 256];
   FILE *FilePic;
   int i, tmp;
   GLenum gluerr;

   if ((FilePic = fopen("terrain.dat", "r")) == NULL) {
      fprintf(stderr, "Error loading terrain.dat\n");
      exit(-1);
   }
   fread(bufferter, 256 * 256, 1, FilePic);
   fclose(FilePic);

   for (i = 0; i < (256 * 256); i++) {
      terrain[i] = (bufferter[i] * (heightMnt / 255.0f));
      calccolor((GLfloat) bufferter[i], terraincolor[i]);
      tmp = (((int) bufferter[i]) + 96);
      terrainpic[i] = (tmp > 255) ? 255 : tmp;
   }

   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   if ((gluerr = gluBuild2DMipmaps(GL_TEXTURE_2D, 1, 256, 256, GL_LUMINANCE,
				   GL_UNSIGNED_BYTE,
				   (GLvoid *) (&terrainpic[0])))) {
      fprintf(stderr, "GLULib%s\n", (char *) gluErrorString(gluerr));
      exit(-1);
   }

   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
		   GL_LINEAR_MIPMAP_LINEAR);
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   glEnable(GL_TEXTURE_2D);
}
コード例 #18
0
ファイル: FFT.cpp プロジェクト: hominidclint/cl-gl-benchmark
static int
SetupGLProgram()
{
	GLenum error_check_value = glGetError();

	if(VertexShaderID)
		glDeleteShader(VertexShaderID);
	VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
	glShaderSource(VertexShaderID, 1, &VertexShaderSource, NULL);
	glCompileShader(VertexShaderID);

	if(FragShaderID)
		glDeleteShader(FragShaderID);
	FragShaderID = glCreateShader(GL_FRAGMENT_SHADER);
	glShaderSource(FragShaderID, 1, &FragShaderSource, NULL);
	glCompileShader(FragShaderID);

	if (GLProgramID)
	{
		glUseProgram(0);
		glDeleteProgram(GLProgramID);
	}
	GLProgramID = glCreateProgram();
	glAttachShader(GLProgramID, VertexShaderID);
	glAttachShader(GLProgramID, FragShaderID);

	glLinkProgram(GLProgramID);
	glUseProgram(GLProgramID);

	error_check_value = glGetError();
	if (error_check_value != GL_NO_ERROR)
	{
		fprintf(stderr, "error: %s: %s\n",
				__FUNCTION__,
				gluErrorString(error_check_value));
		exit(1);
	}

	return 1;
}
コード例 #19
0
ファイル: 20-map.cpp プロジェクト: jateeq/FYDP
void updateGraphics(void)
{
    // update object normals
    object->computeAllNormals(true);

    // render world
    camera->renderView(displayW, displayH);

    // Swap buffers
    glutSwapBuffers();

    // check for any OpenGL errors
    GLenum err;
    err = glGetError();
    if (err != GL_NO_ERROR) printf("Error:  %s\n", gluErrorString(err));

    // inform the GLUT window to call updateGraphics again (next frame)
    if (simulationRunning)
    {
        glutPostRedisplay();
    }
}
コード例 #20
0
ファイル: Chapter 2.4.c プロジェクト: kovacsrobert/ScratchPad
void CreateVBO(void)
{
	Vertex Vertices[] =
	{
		{ { -0.8f, -0.8f, 0.0f, 1.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } },
		{ {  0.0f,  0.8f, 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } },
		{ {  0.8f, -0.8f, 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } }
	};

	GLenum ErrorCheckValue = glGetError();
	const size_t BufferSize = sizeof(Vertices);
	const size_t VertexSize = sizeof(Vertices[0]);
	const size_t RgbOffset = sizeof(Vertices[0].XYZW);
	
	glGenVertexArrays(1, &VaoId);
	glBindVertexArray(VaoId);

	glGenBuffers(1, &BufferId);
	glBindBuffer(GL_ARRAY_BUFFER, BufferId);
	glBufferData(GL_ARRAY_BUFFER, BufferSize, Vertices, GL_STATIC_DRAW);

	glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, VertexSize, 0);
	glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, VertexSize, (GLvoid*)RgbOffset);

	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);

	ErrorCheckValue = glGetError();
	if (ErrorCheckValue != GL_NO_ERROR)
	{
		fprintf(
			stderr,
			"ERROR: Could not create a VBO: %s \n",
			gluErrorString(ErrorCheckValue)
		);

		exit(-1);
	}
}
コード例 #21
0
ファイル: sphere.c プロジェクト: alyssaBiasi/render_modes
/*****************************************************************************************
  VBO Functions
*****************************************************************************************/
void setSphereBuffers() {
    /* Passing data to buffers */
	glBindBuffer(GL_ARRAY_BUFFER, sphereObj.buffers[VERTEX]);
	glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*sphereObj.numVerts, sphereObj.vertArray, GL_DYNAMIC_DRAW);
	
	glBindBuffer(GL_ARRAY_BUFFER, sphereObj.buffers[NORMAL]);
	glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*sphereObj.numVerts, sphereObj.normArray, GL_DYNAMIC_DRAW);
	
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, sphereObj.buffers[INDEX]);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int)*sphereObj.numIndices, sphereObj.indexArray, GL_DYNAMIC_DRAW);
	               
    int error = glGetError();
    if(error != 0) {
        printf("\nint:%d string:%s\n", error, gluErrorString(error));
    }
    
    /* Unbind buffers */
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

	sphereObj.bufferUpdate = false;
}
コード例 #22
0
	void GLError(const char* file, int line)
	{
		GLenum errorCode = glGetError();

		std::stringstream errorSS;
		while(errorCode != GL_NO_ERROR)
		{
			const GLubyte* errorString = gluErrorString(errorCode);

			errorSS << file << "(" << line << ")" << std::endl
                    << "    " << " GL ERROR " << errorCode << ": " << "(" << errorString << ")\n";

			errorCode = glGetError();
		}

		if(!errorSS.str().empty())
		{
			trace("\n***********OpengGL Error*************")
			trace(errorSS.str())
			DebugBreak();
		}
	}
コード例 #23
0
ファイル: shader.cpp プロジェクト: jeando/vision
/**
 * @brief Enables the shader. This will effectively replace the render pipeline functions by
 * the program shader
 * In case the geometry shader fails
 * - Check whether the input geometry primitive type sent by the draw call is
 *   the same as the shader's
 */
void Shader::enable() {
    // Validate the program
    /**
     * XXX: do only during developpement to avoid this overhead in release
     **/
	static int i=0;
	if(i==0)
	{
    	glValidateProgram(mProgramHandle);
		i++;
	}
	else
	{
//		std::cout << "aezfgbfvdnjk"<<std::endl;
	}
    GLenum errCode;

    if ((errCode = glGetError()) != GL_NO_ERROR) {
        std::cerr << "Shader::enable: Error: " << std::endl;
        const GLubyte *errString;
        errString = gluErrorString(errCode);
        std::cerr<< "OpenGL Error (" << errCode << "): "<< errString << std::endl;
        if(errCode = GL_INVALID_OPERATION)  {
            std::cerr << "GL_INVALID_OPERATION is generated if a geometry shader is active and mode is incompatible with the input primitive type of the geometry shader in the currently installed program object."<< std::endl
                << "GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to an enabled array or the element array and the buffer object's data store is currently mapped." << std::endl;
            exit(1);
        }
    }

    // Enable the program
    glUseProgram(mProgramHandle);

    // Bind the textures
    bindTextures();
	if(vao)
	{
		glBindVertexArray(vao);
	}
}
コード例 #24
0
	void onResize(int w, int h)
	{
		glViewport(0, 0, w, h);

		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 1.0, 20.0);
		
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt(
			0.0, 0.0, 5.0, 
			0.0, 0.0, 0.0,
			0.0, 1.0, 0.0
			);

		GLenum err = glGetError();
		if (err != GL_NO_ERROR)
		{
			printf("onResize() ERROR: %s\n", gluErrorString(err));
		}
	}
コード例 #25
0
ファイル: cText.cpp プロジェクト: alexgg-developer/3d_vj2014
bool Text::init()
{
  bool success = true;
  if(mProgramID==0) {
    mProgramID = glCreateProgram();
    mVertexShader.init(GLShader::VERTEX, mProgramID);
    success = mVertexShader.compile();
    mFragmentShader.init(GLShader::FRAGMENT, mProgramID);
    success = mFragmentShader.compile();
    success = GLShader::linkProgram(mProgramID);

    GLfloat vertexData[] =
    {
      -0.5f, -0.5f,
      0.5f, -0.5f,
      0.5f, 0.5f,
      -0.5f, 0.5f
    };

    GLuint indexData[] = { 0, 1, 2, 3 };

    glGenBuffers(1, &mVBO);
    glBindBuffer(GL_ARRAY_BUFFER, mVBO);
    glBufferData(GL_ARRAY_BUFFER, 2 * 4 * sizeof(GLfloat), vertexData, GL_STATIC_DRAW);

    glGenBuffers(1, &mIBO);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIBO);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, 4 * sizeof(GLuint), indexData, GL_STATIC_DRAW);

    glBindBuffer(GL_ARRAY_BUFFER, NULL); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL);
  }
  GLenum error = glGetError();
  if (error != GL_NO_ERROR) {
    std::cout << "Error initializing App!" << gluErrorString(error) << std::endl;
    success = false;
  }

  return success;
}
コード例 #26
0
ファイル: usespheremap.c プロジェクト: arnelh/Examples
void draw(void)
{
    GLenum err;
    GLdouble secs, degrees;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    /* one revolution every 10 seconds... */
    secs = get_secs();
    secs = secs - 10.*trunc(secs / 10.);
    degrees = (secs/10.) * (360.);

#if 0
    draw_room();
#endif
    draw_torus(degrees);

    err = glGetError();
    if (err != GL_NO_ERROR) printf("Error:  %s\n", gluErrorString(err));

    glutSwapBuffers();
}
コード例 #27
0
ファイル: gltexture.c プロジェクト: dhmunro/yorick-gl
int isExtensionSupported(const char *extension)
{
  /* This function is based on the example in Mark Kilgard's
     article about openGL extensions.
     WARNING!!! an OpenGL context must be established before
     calling this function!!! */
  const GLubyte *extensions= NULL;
  const GLubyte *start;
  GLubyte *where, *terminator;
  const GLubyte *errstr;
  GLenum err;

  /* Extension names should not have spaces,
	   so return "not supported" if the name is malformed. */
  where= (GLubyte *) strchr(extension, ' ');
  if(where || *extension == '\0') return 0;

  extensions= glGetString(GL_EXTENSIONS);
  err= glGetError();
  errstr= gluErrorString(err);
  if(!extensions) return 0;

	/* Parsing OpenGL extension strings is tricky. 
	   handle sub-strings etc. */
  start= extensions;
  for( ; ; ) {
    where= (GLubyte *) strstr((const char *) start, extension);
    if(!where) break;
    terminator= where+strlen(extension);
    if(where == start || *(where-1) == ' ') {
      if(*terminator == ' ' || *terminator == '\0') {
        return 1;
      }
    }
    start= terminator;
  }
  return 0;
}
コード例 #28
0
ファイル: lesson36.cpp プロジェクト: scyptnex/computing
bool initGL()
{
    //Initialize Projection Matrix
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();

    //Initialize Modelview Matrix
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    //Initialize clear color
    glClearColor( 0.f, 0.f, 0.f, 1.f );

    //Check for error
    GLenum error = glGetError();
    if( error != GL_NO_ERROR )
    {
        printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) );
        return false;
    }

    return true;
}
コード例 #29
0
void updateGraphics(void)
{
    // render world
    camera->renderView(displayW, displayH);

    // Swap buffers
    glutSwapBuffers();

    // check for any OpenGL errors
    GLenum err;
    err = glGetError();
    if (err != GL_NO_ERROR) printf("Error:  %s\n", gluErrorString(err));

    // inform the GLUT window to call updateGraphics again (next frame)
    if (simulationRunning)
    {
        glutPostRedisplay();
    }

    // rotate the following objcts to create some animation
    object1->rotate(cVector3d(0,0,1),  0.02);
    object3->rotate(cVector3d(1,1,1), -0.01);
}
コード例 #30
0
/** 
 * Create renderbuffer.
 * @param [in] size    Renderbuffer size.
 * @param [in] format  Renderbuffer format.
 * @param [in] samples Samples count (default=-0).
 * @return true if the renderbuffer was succesfully created.
 */
bool Renderbuffer::create(const glm::ivec2& size, Texture::PixelFormat format, size_t samples)
{
    if(_id)
    {
        destroy();
    }
    glGenRenderbuffers(1, &_id);

    _format  = format;
    _size    = size;
    _samples = samples;
    
    glBindRenderbuffer(GL_RENDERBUFFER, _id);
    glRenderbufferStorageMultisample(GL_RENDERBUFFER, _samples, _format.internalFormat(), _size.x, _size.y);
    GLenum err = glGetError();
    bool ret = (GL_NO_ERROR == err);
    if(!ret)
    {
        Log_Error(Dumb::Module::Render, "Failed to create renderbuffer: %s", gluErrorString (err));
    }
    glBindRenderbuffer(GL_RENDERBUFFER, 0);
    return ret;
}