Ejemplo n.º 1
0
void init_scene(int width, int height)
{
    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);

    glDisable(GL_DITHER);
    glEnable(GL_CULL_FACE);

    float ratio = width / height;
    glViewport(0, 0, width, height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustumf(-ratio, ratio, -1, 1, 1, 10);

    glMatrixMode(GL_MODELVIEW);

    glLoadIdentity();
    gluLookAt(
            0, 0, 3,  // eye
            0, 0, 0,  // center
            0, 1, 0); // up

    glEnable(GL_TEXTURE_2D);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
Ejemplo n.º 2
0
void Win32OpenGLWindow::enableOpenGL()
{

	PIXELFORMATDESCRIPTOR pfd;
	int format;
	
	// get the device context (DC)
	m_data->m_hDC = GetDC( m_data->m_hWnd );
	
	// set the pixel format for the DC
	ZeroMemory( &pfd, sizeof( pfd ) );
	pfd.nSize = sizeof( pfd );
	pfd.nVersion = 1;
	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 32;
	pfd.cDepthBits = 16;
	pfd.cStencilBits = 1;
	pfd.iLayerType = PFD_MAIN_PLANE;
	format = ChoosePixelFormat( m_data->m_hDC, &pfd );
	SetPixelFormat( m_data->m_hDC, format, &pfd );
	
	// create and enable the render context (RC)
	m_data->m_hRC = wglCreateContext( m_data->m_hDC );
	wglMakeCurrent( m_data->m_hDC, m_data->m_hRC );

	if (sOpenGLVerbose)
	{
		 printGLString("Version", GL_VERSION);
		printGLString("Vendor", GL_VENDOR);
		printGLString("Renderer", GL_RENDERER);
	}
    //printGLString("Extensions", GL_EXTENSIONS);

}
Ejemplo n.º 3
0
JNIEXPORT void JNICALL Java_com_blackicegamesnyc_GameEngine_GameEngineRenderer_nativeInit
  (JNIEnv * env, jclass cls, jstring apkPath) {
  __android_log_print(ANDROID_LOG_DEBUG  , "KRISTOFER", "Native Init Called...\n");
  const char* str;
  jboolean isCopy;
  str = env->GetStringUTFChars(apkPath, &isCopy);
  loadAPK(str);

  int width, height;
  texture = loadTextureFromPNG("assets/sprites/texture.png", width, height);

  printGLString("Version", GL_VERSION);
  printGLString("Vendor", GL_VENDOR);
  printGLString("Renderer", GL_RENDERER);
  printGLString("Extensions", GL_EXTENSIONS);

  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  glEnable(GL_BLEND);
  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_TEXTURE_2D);
  glClearColor(1,0,0,0);
  glColor4f(1,1,1,1);
  glDisable(GL_DEPTH_TEST);
  glDisable(GL_CULL_FACE);
}
Ejemplo n.º 4
0
void g_makeCurrent()
{
    LOGE("g_makeCurrent-->start L:366");
    LOGE("Got bwdisplay %p", bwdisplay);
    LOGE("Got bwsurface %p", bwsurface);
    LOGE("Got bwcontext %p", bwcontext);
    if (!eglMakeCurrent(bwdisplay, bwsurface, bwsurface, bwcontext)) {
        LOGI("eglMakeCurrent() returned error %d", eglGetError());
        g_destroyGL();
    }
    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);
    
    glHint( GL_GENERATE_MIPMAP_HINT, GL_NICEST );
    
    glHint( GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES, GL_NICEST );
    
    glEnable( GL_DEPTH_TEST );
    glEnable( GL_CULL_FACE  );
    glDisable( GL_DITHER );
    glDepthMask( GL_TRUE );
    glDepthFunc( GL_LESS );
    glDepthRangef( 0.0f, 1.0f );
    glClearDepthf( 1.0f );
    glCullFace ( GL_BACK );
    glFrontFace( GL_CCW  );
    glClearStencil( 0 );
    glStencilMask( 0xFFFFFFFF );
}
bool setupGraphics( int w, int h )
{
	LOGI( "setupGraphics(%d, %d)", w, h );

	printGLString( "Version", GL_VERSION );
	printGLString( "Vendor", GL_VENDOR );
	printGLString( "Renderer", GL_RENDERER );
	printGLString( "Extensions", GL_EXTENSIONS );

	glGenBuffers( 1, &g_triangleVBO );
	glBindBuffer( GL_ARRAY_BUFFER, g_triangleVBO );
	glBufferData( GL_ARRAY_BUFFER, vertex_size + texcoord_size, 0, GL_STATIC_DRAW );
	glBufferSubData( GL_ARRAY_BUFFER, 0, vertex_size, g_vertices ); // Start at index 0, to length of vertex_size.
	glBufferSubData( GL_ARRAY_BUFFER, vertex_size, texcoord_size, g_textureCoordinates ); // Append texcoord data to vertex data.

	glGenBuffers( 1, &g_triangleIBO );
	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, g_triangleIBO );
	glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort)*6, g_indices, GL_STATIC_DRAW );

//	glViewport( 0, 0, w, h );
//	checkGlError( "glViewport" );

	g_nowTime = getCurrentTimeInSeconds();
	g_prevTime = g_nowTime;

	return true;
}
Ejemplo n.º 6
0
bool setupGraphics(int w, int h) {
    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);

    gWidth = w;
    gHeight = h;

    glViewport(0, 0, w, h);
    checkGlError("glViewport");

    LOGI("setupGraphics(%d, %d)", w, h);
    gProgram = createProgram(gVertexShader, gFragmentShader);////////////////////////////////1
    if (!gProgram) {
        LOGE("Could not create program.");
        return false;
    }
    checkGlError("createProgram");
    ///////////////////////////////
    positionLoc = glGetAttribLocation(gProgram, "a_position");
    checkGlError("glGetAttribLocation a_position");
    texcoordLoc = glGetAttribLocation(gProgram, "a_texCoord");
    checkGlError("glGetAttribLocation a_texCoord");
    textureLoc = glGetUniformLocation ( gProgram, "s_texture" );
    checkGlError("glGetUniformLocation s_texture");
    ///////////////////////////////

    initForRenderTOrenderBuffer(w, h);
    checkGlError("initForRenderTOrenderBuffer");
    obj = new nativeRecord();
    obj -> init();
    return true;
}
Ejemplo n.º 7
0
JNIEXPORT void JNICALL Java_net_catchball_CatchBallRenderer_nativeInit
  (JNIEnv * env, jclass cls, jstring apkPath) {
  const char* str;
  jboolean isCopy;
  str = env->GetStringUTFChars(apkPath, &isCopy);
  loadAPK(str);

  int width, height;
  texture = loadTextureFromPNG("assets/sprites/texture.png", width, height);
  int bblue = loadTextureFromPNG("assets/sprites/button blue.png", width, height);
  int bred = loadTextureFromPNG("assets/sprites/button red.png", width, height);
//  int houseTexture = loadTextureFromPNG("assets/sprites/house.png", width, height);
  int meteor_b = loadTextureFromPNG("assets/sprites/meteor.png", width, height);
  int meteor_y = loadTextureFromPNG("assets/sprites/meteor-y.png", width, height);
  int meteor_r = loadTextureFromPNG("assets/sprites/meteor-r.png", width, height);
  int meteor_g = loadTextureFromPNG("assets/sprites/meteor-g.png", width, height);
  int ballTexture = loadTextureFromPNG("assets/sprites/ball.png", width, height);

  printGLString("Version", GL_VERSION);
  printGLString("Vendor", GL_VENDOR);
  printGLString("Renderer", GL_RENDERER);
  printGLString("Extensions", GL_EXTENSIONS);

  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  glEnable(GL_BLEND);
  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_TEXTURE_2D);
  glClearColor(0,0,0,0);
  glColor4f(1,1,1,1);
  glDisable(GL_DEPTH_TEST);
  glDisable(GL_CULL_FACE);
  
	Texture texr(RED,meteor_r);
	Texture texg(GREEN,meteor_g);
	Texture texy(YELLOW,meteor_y);
	Texture texb(BRONZE,meteor_b);

LOGI("textures created");
//  house = House(world.getWorld());
//  house.setTexture(houseTexture);
  ball = Ball(world);
  ball.setTexture(ballTexture);
LOGI("Ball created");
  meteors = meteorManager(world.getWorld());
LOGI("Meteors created");
//  meteors.setTexture(meteor);
  meteors.addTexture(texb);
  meteors.addTexture(texr);
  meteors.addTexture(texy);
  meteors.addTexture(texg);
//  buttons.setTextures(bblue, bred);
LOGI("Textures for meteors added");
}
Ejemplo n.º 8
0
bool setupGraphics(int w, int h) {
    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);

    LOGI("setupGraphics(%d, %d)", w, h);
    glViewport(0, 0, w, h);
    checkGlError("glViewport");
    return true;
}
Ejemplo n.º 9
0
extern "C" JNIEXPORT void JNICALL Java_com_android2c_CCJNI_OnSurfaceChanged(JNIEnv *jEnv, jobject jObj, jboolean firstRun, jint jWidth, jint jHeight)
{
	CCJNI::SetJNIEnv( jEnv );

#ifdef DEBUGON
	// Now we can do what we intended
	printGLString( "Version", GL_VERSION );
	printGLString( "Vendor", GL_VENDOR );
	printGLString( "Renderer", GL_RENDERER );
	printGLString( "Extensions", GL_EXTENSIONS );
#endif

	DEBUGLOG( "OnSurfaceChanged" );

	// Get our app manager to create the glView
	if( gView == NULL )
	{
		CCAppManager::Startup();
	}
	gView->resizeView( jWidth, jHeight );

	if( firstRun )
	{
		DEBUGLOG( "OnSurfaceChanged - firstRun" );
		if( gEngine != NULL )
		{
			// Force close any previous web view instances
			CCAppManager::WebViewClose( true );
			CCAppManager::WebJSClose( true );

			delete gEngine;
			gEngine = NULL;
		}
	}

	if( gEngine != NULL )
	{
		DEBUGLOG( "OnSurfaceChanged - resuming %f", gEngine->time.lifetime );
		gEngine->setupRenderer();
	}

	DEBUGLOG( "OnSurfaceChanged - END" );

	usleep( 16 );	// Sleep for 16 ms

#if defined PROFILEON
    CCProfiler::open();
#endif
}
Ejemplo n.º 10
0
bool setupGraphics(struct android_app* state) {

	const EGLint attribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE,
			8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_NONE };
	EGLint contextAttrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };

	EGLint w, h, dummy, format;
	EGLint numConfigs;
	EGLConfig config;

	EGLContext context;

	display = eglGetDisplay(EGL_DEFAULT_DISPLAY );

	eglInitialize(display, 0, 0);

	defaultEGLChooser(display, config);

	//eglChooseConfig(display, attribs, &config, 1, &numConfigs);

	eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);

	context = eglCreateContext(display, config, NULL, contextAttrs);

	ANativeWindow_setBuffersGeometry(state->window, 0, 0, format);

	surface = eglCreateWindowSurface(display, config, state->window, NULL);

	if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
		LOGW("Unable to eglMakeCurrent");
		return -1;
	}

	eglQuerySurface(display, surface, EGL_WIDTH, &w);
	eglQuerySurface(display, surface, EGL_HEIGHT, &h);

	printGLString("Version", GL_VERSION);
	printGLString("Vendor", GL_VENDOR);
	printGLString("Renderer", GL_RENDERER);
	printGLString("Extensions", GL_EXTENSIONS);
	LOGI("setupGraphics(%d, %d)", w, h);
	render->SetPivotPoint(w * 0.5f, h * 0.5f);
	std::string resourcePath("/sdcard");
	render->SetResourcePath(resourcePath);
	render->Initialize(w, h);
	checkGlError("glViewport");
	return true;
}
Ejemplo n.º 11
0
bool App::setupGraphics(int w, int h) {
	this->screenWidth = w;
	this->screenHeight = h;
	LOGD("App", "width: %d, height: %d", w, h);
    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);

    LOGI("App", "setupGraphics(%d, %d)", w, h);
    Director::shared->start();

    glViewport(0, 0, w, h);
    checkGlError("glViewport");

    float half_width = (float) w * 0.5f;
    float half_height = (float) h * 0.5f;
    Director::shared->setMatrixMode(PROJECTION_MATRIX);
    Director::shared->loadIdentity();
	Director::shared->setPerspective(60.0f,
			(float) App::shared->getScreenWidth() / (float) App::shared->getScreenHeight(),
			0.01f,
			3550.0f,
			0.0f);
	glDisable(GL_CULL_FACE);
//    Director::shared->setOrthoGraphic2D(-half_width,
//    							 	 	 half_width,
//    							 	 	-half_height,
//    							 	 	 half_height);
    Director::shared->translate(-half_width, -half_height, 0.0f);
//    vec3 c = {0.0f, 0.0f, 0.0f };	// center
    vec3 c = { 0.0f, 0.0f, 0.0f };	// center
    	vec3 u = { 0.0f, 0.0f, -1.0f };	// up

//    	vec3 e = { 0.0f, 0.001f, 545.0f }; // eye
    	vec3 e = { 0.0f, 0.0001f, 2.2566f * w }; // eye
    //	vec3 c = { App::shared->getScreenWidth() / 2.0f, App::shared->getScreenHeight() / 2.0f, 0.0f };	// center
    //	vec3 u = { 0.0f, 0.0f, 1.0f };	// up
    	Director::shared->lookAt(&e, &c, &u);
//    glDisable(GL_DEPTH_TEST);
//    glDepthMask(GL_FALSE);

    isRenderable = 1;
    glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    return true;
}
Ejemplo n.º 12
0
bool setupGraphics(int w, int h) {



    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);

    LOGI("setupGraphics(%d, %d)", w, h);
    /*gProgram = createProgram(gVertexShader, gFragmentShader);
    if (!gProgram) {
        LOGE("Could not create program.");
        return false;
    }
    gvPositionHandle = glGetAttribLocation(gProgram, "vPosition");
    checkGlError("glGetAttribLocation");
    LOGI("glGetAttribLocation(\"vPosition\") = %d\n",
            gvPositionHandle);
*/
    Effect* effect = Assets::getInstance().CreateEffect("Default");
    sprite.SetEffect(effect);
    effect->SetSource(Assets::DefaultVertexShader, Assets::DefaultFragmentShader);
    effect->CompileAndLink();

    //std::vector<unsigned char> image;
	unsigned long iw=4;
	unsigned long ih;
	h=4;
	std::vector<unsigned char> image(16*4);
	for (int k=0; k< 16; k++)
	{
		for (int j=0; j< 4; j++)
			image[k*4+j] = 0;
		image[k*4] = 255;
		image[k*4+3] = 255;
	}

	Texture* texture = Assets::getInstance().CreateTexture("Default");
	texture->SetImageBuffer(image, 4, 4);
	texture->GPULoad();
	sprite.SetTexture(texture);

    glViewport(0, 0, w, h);
    checkGlError("glViewport");
    return true;
}
Ejemplo n.º 13
0
int GLESApplication::init(int w, int h)
{

    LOGI("+++++++++++++++++++++++++++++++++++++++++++++++");
    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);
    LOGI("+++++++++++++++++++++++++++++++++++++++++++++++");

    this->width = w;
    this->height = h;
    
    positInit();
    
    return 0;
}
Ejemplo n.º 14
0
bool setupGraphics(int w, int h) {
    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);

    LOGI("setupGraphics(%d, %d)", w, h);
    uiWidth = w; uiHeight = h;
    gProgram = createProgram(gVertexShader, gFragmentShader);
    if (!gProgram) {
        LOGE("Could not create program.");
        return false;
    }
    gvPositionHandle = glGetAttribLocation(gProgram, "vPosition");
    checkGlError("glGetAttribLocation");
    LOGI("glGetAttribLocation(\"vPosition\") = %d\n", gvPositionHandle);

    gvColorHandle = glGetAttribLocation(gProgram, "vColor");
    checkGlError("glGetAttribLocation");
    LOGI("glGetAttribLocation(\"vColor\") = %d\n", gvColorHandle);

    gAHandle = glGetUniformLocation(gProgram, "A");
    checkGlError("glGetAttribLocation");
    LOGI("glGetUniformLocation(\"A\") = %d\n", gAHandle);

    gThetaHandle = glGetUniformLocation(gProgram, "theta");
    checkGlError("glGetAttribLocation");
    LOGI("glGetUniformLocation(\"theta\") = %d\n", gThetaHandle);

    gmvP = glGetUniformLocation(gProgram, "mvp");
    checkGlError("glGetUniformLocation");
    LOGI("glGetUniformLocation(\"mvp\") = %d\n", gmvP);

    glViewport(0, 0, w, h);
    checkGlError("glViewport");
#if !USE_MESH
    glEnable(GL_CULL_FACE);
#endif
    glEnable(GL_DEPTH_TEST);

    //create a mesh
    gpMesh = new cMesh;
    gpMesh->buildPlane(2.0,3.4,75,128);
    //gpMesh->computeVerticesNormals();
    return true;
}
Ejemplo n.º 15
0
bool setupGraphics(int _w, int _h) {
    w = _w; h = _h;

    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);

    LOGI("setupGraphics(%d, %d)", w, h);
    vg = nvgCreateGLES2(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG);

    glViewport(0, 0, w, h);
    checkGlError("glViewport");

    glClearColor(r,g,b,a);
    checkGlError("glClearColor");
    return true;
}
Ejemplo n.º 16
0
void GLWidget::initializeGL(){
    printGLString();

    glClearColor(0.0,0.0,0.0,0.0);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    prepareShaders();
    objTest->initBuffers();
}
Ejemplo n.º 17
0
bool setupGraphics(int w, int h) {
	printGLString("Version", GL_VERSION);
	printGLString("Vendor", GL_VENDOR);
	printGLString("Renderer", GL_RENDERER);
	printGLString("Extensions", GL_EXTENSIONS);
	windowSize_h = h; windowSize_w = w;
	LOGI("setupGraphics(%d, %d)", w, h);
	gProgram = createProgram(gVertexShader, gFragmentShader);
	if (!gProgram) {
		LOGE("Could not create program.");
		return false;
	}
	setupHandles();
	//initFrameBuffers();
	EngineStackpush("Engine Ready");

	EngineReady = true;
	return true;
}
Ejemplo n.º 18
0
void ParticleUpsampling::initRendering(void)
{
    printGLString("Version",    GL_VERSION);
    printGLString("Vendor",     GL_VENDOR);
    printGLString("Renderer",   GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);

    GLint depthBits;
    glGetIntegerv(GL_DEPTH_BITS, &depthBits);
    LOGI("depth bits = %d\n", depthBits);

    //glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    NvAssetLoaderAddSearchPath("ParticleUpsampling");

    m_sceneRenderer = new SceneRenderer(requireMinAPIVersion(NvGfxAPIVersionGL4(), false));

    CHECK_GL_ERROR();
}
Ejemplo n.º 19
0
 gl_transient_state(android_app *app) 
 : context_( app ),
   program_(gVertexShader, gFragmentShader ),
   visible_(false)
 {
     
     
     printGLString("Version", GL_VERSION);
     printGLString("Vendor", GL_VENDOR);
     printGLString("Renderer", GL_RENDERER);
     printGLString("Extensions", GL_EXTENSIONS);
     
   
     
     glViewport(0, 0, context_.get_w(), context_.get_h());
     
     
     checkGlError("glViewport");
     LOGI( ">>>>>>>>> engine()\n" );
 }
Ejemplo n.º 20
0
JNIEXPORT void JNICALL Java_com_android2c_CCJNI_onSurfaceChanged(JNIEnv *jEnv, jobject jObj, jint jWidth, jint jHeight)
{	
#ifdef DEBUGON
	// Now we can do what we intended
	printGLString( "Version", GL_VERSION );
	printGLString( "Vendor", GL_VENDOR );
	printGLString( "Renderer", GL_RENDERER );
	printGLString( "Extensions", GL_EXTENSIONS );
#endif
	
	if( windowController != NULL )
	{
		windowController->shutdown();
		delete windowController;
	}
	windowController = new CCWindowController();

	// Get the window controller to create the glView
	windowController->startup();

	// Then feed it in it's appropriate settings here
	gView->jniEnv = jEnv;
	gView->jniObj = jObj;
	gView->resizeView( jWidth, jHeight );

	if( gEngine != NULL )
	{
		delete gEngine;
	}

	gEngine = new CCAppEngine();
	gEngine->setupNativeThread();
	gEngine->setupGameThread();

	gView->runningGame = true;
	gView->gameThreadRunning = true;

#if defined PROFILEON
    CCProfiler::open();
#endif
}
Ejemplo n.º 21
0
bool setupGraphics(int w, int h) {
    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);
    
    LOGI("setupGraphics(%d, %d)", w, h);
    gProgram = createProgram(gVertexShader, gFragmentShader);
    if (!gProgram) {
        LOGE("Could not create program.");
        return false;
    }
    gvPositionHandle = glGetAttribLocation(gProgram, "vPosition");
    checkGlError("glGetAttribLocation");
    LOGI("glGetAttribLocation(\"vPosition\") = %d\n",
         gvPositionHandle);
    
    glViewport(0, 0, w, h);
    checkGlError("glViewport");
    return true;
}
Ejemplo n.º 22
0
///
// Initialize the shader and program object
//
void Origin::init(float width, float height)
{
	Drawable::init(width, height);
    std::string vShaderStr =
      "attribute vec4 av4_position;                \n"
	  "attribute vec4 av4_color;                   \n"
	  "uniform mat4 um4_mvp; 	                   \n"
      "varying vec4 color;                         \n"
      "void main()                                 \n"
      "{                                           \n"
      "   gl_Position = um4_mvp * av4_position;    \n"
	  "   color = av4_color;                       \n"
      "}                                           \n";

    std::string fShaderStr =
      "#ifdef GL_ES                                \n"
      "precision mediump float;                    \n"
      "#endif                                      \n"
	  "varying vec4 color;                         \n"
      "void main()                                 \n"
      "{                                           \n"
      "  gl_FragColor = color;                     \n"
      "}                                           \n";

   // show what we have under the bonet
   printGLString("Version", GL_VERSION);
   printGLString("Vendor", GL_VENDOR);
   printGLString("Renderer", GL_RENDERER);
   printGLString("Extensions", GL_EXTENSIONS);

   // Load the shaders and get a linked program object
   userData.programObject = esCreateProgram(vShaderStr, fShaderStr);

   // Get the attribute locations
   userData.positionLoc = glGetAttribLocation(userData.programObject, "av4_position");
   userData.colorLoc = glGetAttribLocation(userData.programObject, "av4_color");

   // Get the uniform locations
   userData.mvpLoc = glGetUniformLocation(userData.programObject, "um4_mvp");
}
void CascadedShadowMapping::initRendering(void) {
    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);

    GLint depthBits;
    glGetIntegerv(GL_DEPTH_BITS, &depthBits);
    LOGI("depth bits = %d\n", depthBits);

    if (!requireMinAPIVersion(NvGfxAPIVersionGL4_3()))
        return;

    if (!requireExtension("GL_NV_viewport_array2"))
        return;

    if (!requireExtension("GL_NV_geometry_shader_passthrough"))
        return;

    m_renderer->initRendering();

    CHECK_GL_ERROR();
}
Ejemplo n.º 24
0
//	this will Initialize OpenGL ES 2
void TSRGLES2GraphicsSubSystem::InitGraphics( TSRScreenMode& _screenMode )
{
    m_iDefaultFramebuffer = -1;
    GraphicsFactory() = new TSRGLES2GraphicsFactory();
    TSRPrintln( "GLES2 SubSystem successfully Initialized" );
    glEnable( GL_CULL_FACE );
    printGLString( "Version", GL_VERSION );
    printGLString( "Vendor", GL_VENDOR );
   // printGLString( "Renderer", GL_RENDERER );
   // printGLString( "Extensions", GL_EXTENSIONS );
	Resize( _screenMode.m_uiWidth, _screenMode.m_uiHeight );
    
    
    int uiSupportedCompressedTextureFormatsCount = 0;
    
    glGetIntegerv( GL_NUM_COMPRESSED_TEXTURE_FORMATS, &uiSupportedCompressedTextureFormatsCount );

	//TSRPrintln( "Number of compressed formats supported: %d ", uiSupportedCompressedTextureFormatsCount );
    
    int supprtedFormats[ 1024 ];
    
    glGetIntegerv( GL_COMPRESSED_TEXTURE_FORMATS, supprtedFormats );
    
    for ( int i = 0; i < uiSupportedCompressedTextureFormatsCount; i++ )
    {
        m_SupportedCompressedTextureFormats.push_back( supprtedFormats[ i ] );
		//TSRPrintln( "Compressed format: %x ", supprtedFormats[ i ] );
    }
    
    
    GLint iDefaultFramebuffer = 0;
    /// get the default frame buffer
    glGetIntegerv( GL_FRAMEBUFFER_BINDING, &iDefaultFramebuffer );
    
    iDefaultFramebuffer++;
}
///
// Initialize the shader and program object
//
bool setupGraphics(int screenWidth, int screenHeight) 
{

	 glViewport ( 0, 0, screenWidth,screenHeight );

	glEnable(GL_DEPTH_TEST);

    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);

   GLbyte vShaderStr[] =  
	  "uniform mat4 modelMatrix;\n"
	  "uniform mat4 viewMatrix;\n"
	  "uniform mat4 projectionMatrix;\n"
	  "attribute vec4 a_position;   \n"
      "attribute vec2 a_texCoord;   \n"
      "varying vec2 v_texCoord;     \n"
      "void main()                  \n"
      "{                            \n"
	  "   gl_Position = (projectionMatrix*viewMatrix*modelMatrix)*a_position; \n"
      "   v_texCoord = a_texCoord;  \n"
      "}                            \n";
   
   GLbyte fShaderStr[] =  
      "precision mediump float;                            \n"
      "varying vec2 v_texCoord;                            \n"
      "uniform sampler2D s_texture;                        \n"
      "void main()                                         \n"
      "{                                                   \n"
      "  gl_FragColor = texture2D( s_texture, v_texCoord );\n"
      "}                                                   \n";

   // Load the shaders and get a linked program object
   programObject = esLoadProgram ((const char*)vShaderStr, (const char*)fShaderStr );
   
   // Get the attribute locations
   positionLoc = glGetAttribLocation ( programObject, "a_position" );
   texCoordLoc = glGetAttribLocation ( programObject, "a_texCoord" );
   
   // Get the sampler location
   samplerLoc = glGetUniformLocation ( programObject, "s_texture" );

   modelMatrix = glGetUniformLocation ( programObject, "modelMatrix" );
   viewMatrix = glGetUniformLocation ( programObject, "viewMatrix" );
   projectionMatrix = glGetUniformLocation ( programObject, "projectionMatrix" );

   float aspect;
	btVector3 extents;

	if (screenWidth > screenHeight) 
	{
		aspect = screenWidth / (float)screenHeight;
		extents.setValue(aspect * 1.0f, 1.0f,0);
	} else 
	{
		aspect = screenHeight / (float)screenWidth;
		extents.setValue(1.0f, aspect*1.f,0);
	}
	
	float m_frustumZNear=1;
	float m_frustumZFar=1000;

	
	btCreateFrustum(-aspect * m_frustumZNear, aspect * m_frustumZNear, -m_frustumZNear, m_frustumZNear, m_frustumZNear, m_frustumZFar,projMat);

   // Load the texture
   textureId = CreateSimpleTexture2D ();

   glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );


	glinitialized=true;

   return true;
}
Ejemplo n.º 26
0
GLuint SetupGraphics(struct engine * engine){
	
	const char vShader[] =
	"attribute vec3 vPosition;												\n"
	"attribute vec3 vColor;													\n"
	"varying vec4   Color;													\n"	

    "uniform mat4 uMVMatrix;												\n"
    "uniform mat4 uPMatrix;													\n"

    "void main(void) {														\n"
    "	gl_Position = uPMatrix * uMVMatrix * vec4(vPosition, 1.0);			\n"
    "	Color = vec4( vColor, 1.0);											\n"
    "} 																		\n";


	const char fShader[] = 
	"precision mediump float;												\n"
	"varying vec4 Color;													\n"	
	
	"void main() {															\n"
	"  gl_FragColor = Color;												\n"
	"}																		\n";	
		
	LOGI("Init Graphics");
	
	printGLString("Version",	GL_VERSION);
	printGLString("Vendor",		GL_VENDOR);
	printGLString("Renderer",	GL_RENDERER);
	printGLString("Extensions", GL_EXTENSIONS);
	
	LOGI("setupGraphics(%d, %d)", engine->Scr.width, engine->Scr.height);

	engine->GLData.pObject = CreateGLProgram(vShader, fShader);
	
	if(!engine->GLData.pObject) {
		LOGE("Could not create program.");
		return 0;
	}
		
	engine->GLData.gPositionAttribute	= glGetAttribLocation( engine->GLData.pObject, "vPosition");	checkGlError("glGetAttribLocation");
	LOGI("glGetAttribLocation(\"vPosition\") = %d\n", engine->GLData.gPositionAttribute);
	glEnableVertexAttribArray(engine->GLData.gPositionAttribute);										checkGlError("glenableVertexAttribArray");

	engine->GLData.gColorsAttribute		= glGetAttribLocation( engine->GLData.pObject, "vColor");		checkGlError("glGetAttribLocation");
	LOGI("glGetAttribLocation(\"vColor\") = %d\n", engine->GLData.gColorsAttribute);
	glEnableVertexAttribArray(engine->GLData.gColorsAttribute);											checkGlError("glenableVertexAttribArray");

	LOGI("Get Uniform Locations");
    engine->GLData.p_Matrix	= glGetUniformLocation(engine->GLData.pObject, "uPMatrix");					checkGlError("glgetUniformLocation uPMatrix");
    engine->GLData.u_Matrix	= glGetUniformLocation(engine->GLData.pObject, "uMVMatrix");				checkGlError("glgetUniformLocation uMVMatrix");

	LOGI("Uniform modelview at %d\n",  engine->GLData.u_Matrix);
	LOGI("Uniform Projection at %d\n", engine->GLData.p_Matrix);


	glEnable( GL_DEPTH_TEST );
	glDepthFunc( GL_LEQUAL );
	glDepthMask( GL_TRUE );	
	glClearDepthf(1.0f);

	// Load identities 
	LoadIdentity( engine->Matrices.cMatrix); 
	LoadIdentity( engine->Matrices.pMatrix);
	
//~ 1280×800	1.6
//~ 1280x960	1.3333
//~ 1280x1024	1.25
	
	MPerspective( engine->Matrices.pMatrix, 1.25, 1.0f, 1000.0f);	
	glViewport(0, 0, engine->Scr.width, engine->Scr.height);																		checkGlError("glViewport");		
	
	GLfloat _Pose[] = { 0.0, 0.1, 0.0};		
	GLfloat _View[] = { 0.0, 0.0, 5.0};
	GLfloat _UpVx[] = { 0.0, 1.0, 0.0};
	
	LookAtM( engine->Matrices.cMatrix, _Pose, _View, _UpVx);
		
	return 1;
}
Ejemplo n.º 27
0
bool setupGraphics(int w, int h, int backgroundTextureID, int bgW, int bgH, int spriteTexID) {
	srand(time(NULL));
	screenWidth = w;
	screenHeight = h;
	gravity_x = 0.0f;
	gravity_y = 0.9f;

    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);

    LOGI("setupGraphics(%d, %d, %d, %d)", w, h, backgroundTextureID, spriteTexID);

    bgWScale = w * 1.0f / bgW;
    bgHScale = h * 1.0f / bgH;

    textureID = backgroundTextureID;
    spriteTextureID = spriteTexID;

    gProgram = createProgram(gVertexShader, gFragmentShader);
    if (!gProgram) {
        LOGE("Could not create program.");
        return false;
    }

    gStampProgram = createProgram(gStampVertexShader, gFragmentShader);
    if (!gProgram) {
        LOGE("Could not create program.");
        return false;
    }

    gvPositionHandle = glGetAttribLocation(gProgram, "vPosition");
    checkGlError("glGetAttribLocation");
    LOGI("glGetAttribLocation(\"vPosition\") = %d\n",
            gvPositionHandle);

    glViewport(0, 0, w, h);
    checkGlError("glViewport");

    gvTexCoordHandle = glGetAttribLocation(gProgram, "a_texCoord");
    checkGlError("glGetAttribLocation: texCoord");
    gvSamplerHandle = glGetUniformLocation(gProgram, "s_texture");
    checkGlError("glGetAttribLocation: texture");

    LOGI("glGetAttribLocation(\"v_texCoord\") = %d\n",
    		gvTexCoordHandle);

    LOGI("glGetAttribLocation(\"s_texture\") = %d\n",
    		gvSamplerHandle);


    gvStampPositionHandle = glGetAttribLocation(gStampProgram, "vPosition");
    gvStampTexCoordHandle = glGetAttribLocation(gStampProgram, "a_texCoord");
    gvStampGlobalPositionHandle = glGetAttribLocation(gStampProgram, "a_globalPosition");
    gvStampXScaleHandle = glGetUniformLocation(gStampProgram, "u_xscale");
    gvStampYScaleHandle = glGetUniformLocation(gStampProgram, "u_yscale");	
    gvStampTextureHandle = glGetUniformLocation(gStampProgram, "s_texture");
    for (int r = 0; r < 1; r++)
    	for (int c = 0; c < 8; c++) {
    		glSpriteTextureCoords[(r + c) * 12 + 0] = c / 8.0f;
    		glSpriteTextureCoords[(r + c) * 12 + 2] = c / 8.0f;
    		glSpriteTextureCoords[(r + c) * 12 + 4] = (c + 1) / 8.0f;
			
			
    		glSpriteTextureCoords[(r + c) * 12 + 6] = (c + 1) / 8.0f;
    		glSpriteTextureCoords[(r + c) * 12 + 8] = c / 8.0f;
    		glSpriteTextureCoords[(r + c) * 12 + 10] = (c + 1) / 8.0f;
			
    		glSpriteTextureCoords[(r + c) * 12 + 1] = r / 2.0f;
    		glSpriteTextureCoords[(r + c) * 12 + 3] = (r + 1) / 2.0f;
    		glSpriteTextureCoords[(r + c) * 12 + 5] = r / 2.0f;
			
			
    		glSpriteTextureCoords[(r + c) * 12 + 7] = r / 2.0f;
    		glSpriteTextureCoords[(r + c) * 12 + 9] = (r + 1) / 2.0f;					
    		glSpriteTextureCoords[(r + c) * 12 + 11] = (r + 1) / 2.0f;
	
    	}

	LOGI("Ptrs: %d %d %d %d %d %d %d", gvStampPositionHandle, gvStampTexCoordHandle, gvStampGlobalPositionHandle, gvStampXScaleHandle, gvStampYScaleHandle, gvStampRotationHandle, gvStampTextureHandle);

	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	

    return true;
}
 void GLES2Lesson::printVerboseDriverInformation() {
     printGLString("Version", GL_VERSION);
     printGLString("Vendor", GL_VENDOR);
     printGLString("Renderer", GL_RENDERER);
     printGLString("Extensions", GL_EXTENSIONS);
 }
///
// Initialize the shader and program object
//
bool setupGraphics(int screenWidth, int screenHeight) 
{
	m_glutScreenWidth = screenWidth;
	m_glutScreenHeight = screenHeight;


	 glViewport ( 0, 0, screenWidth,screenHeight );

	glEnable(GL_DEPTH_TEST);

    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);

   GLbyte vShaderStr[] =  
	  "uniform mat4 modelMatrix;\n"
	  "uniform mat4 viewMatrix;\n"
	  "uniform mat4 projectionMatrix;\n"
	  "attribute vec4 a_position;   \n"
      "attribute vec2 a_texCoord;   \n"
      "varying vec2 v_texCoord;     \n"
      "void main()                  \n"
      "{                            \n"
	  "   gl_Position = (projectionMatrix*viewMatrix*modelMatrix)*a_position; \n"
      "   v_texCoord = a_texCoord;  \n"
      "}                            \n";
   
   GLbyte fShaderStr[] =  
      "precision mediump float;                            \n"
      "varying vec2 v_texCoord;                            \n"
      "uniform sampler2D s_texture;                        \n"
      "void main()                                         \n"
      "{                                                   \n"
      "  gl_FragColor = texture2D( s_texture, v_texCoord );\n"
      "}                                                   \n";

// for wireframe, use white color
//	  "  gl_FragColor = vec4(1.0,1.0,1.0,1.0);\n"

   // Load the shaders and get a linked program object
#ifdef __native_client__
   programObject = shader_util::CreateProgramFromVertexAndFragmentShaders((const char*)vShaderStr, (const char*)fShaderStr);
#else
	programObject= esLoadProgram ((const char*)vShaderStr, (const char*)fShaderStr );
#endif

   // Get the attribute locations
   positionLoc = glGetAttribLocation ( programObject, "a_position" );
   texCoordLoc = glGetAttribLocation ( programObject, "a_texCoord" );
   
   // Get the sampler location
   samplerLoc = glGetUniformLocation ( programObject, "s_texture" );

   modelMatrix = glGetUniformLocation ( programObject, "modelMatrix" );
   viewMatrix = glGetUniformLocation ( programObject, "viewMatrix" );
   projectionMatrix = glGetUniformLocation ( programObject, "projectionMatrix" );

   // Load the texture
   textureId = 0;//CreateSimpleTexture2D ();

   glClearColor ( 1.2f, 0.2f, 0.2f, 0.2f );

   createWorld();


   return true;
}
Ejemplo n.º 30
0
void g_initGles()
{
    const EGLint attribs[] = {
        EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
        EGL_BLUE_SIZE, 8,
        EGL_GREEN_SIZE, 8,
        EGL_RED_SIZE, 8,
        EGL_NONE
    };
    const EGLint attrs[] = {
        EGL_CONTEXT_CLIENT_VERSION, 2,
        EGL_NONE, };
    bwwindow=GetWindow();
    bwdisplay=GetDisplay();
    LOGE("Got bwdisplay %p", bwdisplay);
    LOGE("Got bwwindow %p", bwwindow);
    LOGI("Initializing context");
    
    if (bwdisplay  != EGL_NO_DISPLAY) {
        LOGI("%d", 2222);
        
    }
    if (!eglInitialize(bwdisplay, 0, 0)) {
        LOGI("eglInitialize() returned error %d", eglGetError());
        
    }
    eglBindAPI(EGL_OPENGL_ES_API);
    
    if (!eglChooseConfig(bwdisplay, attribs, &bwconfig, 1, &bwnumConfigs)) {
        LOGI("eglChooseConfig() returned error %d", eglGetError());
        g_destroyGL();
        
    }
    
    if (!eglGetConfigAttrib(bwdisplay, bwconfig, EGL_NATIVE_VISUAL_ID, &bwformat)) {
        LOGI("eglGetConfigAttrib() returned error %d", eglGetError());
        g_destroyGL();
        
    }
    
    ANativeWindow_setBuffersGeometry(bwwindow, 0, 0, bwformat);
    LOGI("**********pgc1************");
    if (!(bwsurface_copy = eglCreateWindowSurface(bwdisplay, bwconfig, bwwindow, 0))) {
        LOGI("eglCreateWindowSurface() returned error %d", eglGetError());
//        g_destroyGL();
        
    }else{
        bwsurface = bwsurface_copy;
    }
    
    LOGI("**********pgc2************");
    if (!(bwcontext_copy = eglCreateContext(bwdisplay, bwconfig, EGL_NO_CONTEXT, attrs))) {
        LOGI("eglCreateContext() returned error %d", eglGetError());
//        g_destroyGL();
    }else{
        bwcontext = bwcontext_copy;
    }
    
    if (!eglMakeCurrent(bwdisplay, bwsurface, bwsurface, bwcontext)) {
        LOGI("eglMakeCurrent() returned error %d", eglGetError());
//        g_destroyGL();
        
    }
    
    if (!eglQuerySurface(bwdisplay, bwsurface, EGL_WIDTH, &bwwidth) ||
        !eglQuerySurface(bwdisplay, bwsurface, EGL_HEIGHT, &bwheight)) {
        LOGI("eglQuerySurface() returned error %d", eglGetError());
//        g_destroyGL();
        
    }
    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);
    
    glHint( GL_GENERATE_MIPMAP_HINT, GL_NICEST );
    
    glHint( GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES, GL_NICEST );
    
    glEnable( GL_DEPTH_TEST );
    glEnable( GL_CULL_FACE  );
    glDisable( GL_DITHER );
    glDepthMask( GL_TRUE );
    glDepthFunc( GL_LESS );
    glDepthRangef( 0.0f, 1.0f );
    glClearDepthf( 1.0f );
    glCullFace ( GL_BACK );
    glFrontFace( GL_CCW  );
    glClearStencil( 0 );
    glStencilMask( 0xFFFFFFFF );
    //绘制三角形
//    setupGraphics(1232,800);
//    if (bwdisplay) {
//        renderFrame();
//        if (!eglSwapBuffers(bwdisplay, bwsurface)) {
//            LOGE("eglSwapBuffers() returned error %d", eglGetError());
//            g_destroyGL();
//        }
//        
//    }

}