Exemple #1
0
void MainWidget::initializeGL()
{
    drawState = 0;

    initializeGLFunctions();

    qglClearColor(Qt::white);

    qDebug() << "Initializing shaders...";
    initShaders();

    qDebug() << "Initializing textures...";
    initTextures();

//! [2]
    // Enable depth buffer
    glEnable(GL_DEPTH_TEST);

    // Enable back face culling
    //glEnable(GL_CULL_FACE);
//! [2]

    qDebug() << "Initializing geometries...";
    FSController::getInstance()->geometries->init();

    // using QBasicTimer because its faster that QTimer
    timer->start(12, this);
}
AppWindow::AppWindow ( const char* label, int x, int y, int w, int h )
    : GlutWindow ( label, x, y, w, h )
{
    addMenuEntry ( "Option 0", evOption0 );
    addMenuEntry ( "Option 1", evOption1 );

    _viewaxis = true;
    _fovy = GS_TORAD(60.0f);
    _rotx = gspi/8.0f;
    _roty = gspi/4.0f;
    _w = w;
    _h = h;

    rt = 0.25f;
    rb = 0.25f;
    numfaces = 16;
    textureChoice = false;
    blendFactor = 0.75f;
    
    _lasttime = gs_time();
    _animateinc = 0.1f;
    _animate = true;
    _normals = false;
    _flatn = true;
    _phong = false;

    initPrograms ();
    initTextures ();
}
void init(int argc, char* argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowSize(width, height);
    glutCreateWindow("565 NBody sim");

    // Init GLEW
    glewInit();
    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        /* Problem: glewInit failed, something is seriously wrong. */
        std::cout << "glewInit failed, aborting." << std::endl;
        exit (1);
    }

	if (argc > 1)
	{
		if (!strcmp (argv [1], "true"))
			customSimulation = true;
		if (argc > 2)
			if (!strcmp (argv [2], "prefetch"))
				prefetchEnabled = true;
	}			

    initVAO();
    initTextures();
}
void init(){
    if (glfwInit() != GL_TRUE){
        shut_down(1);      
    }

    // 16 bit color, no depth, alpha or stencil buffers, windowed
    if (glfwOpenWindow(width, height, 5, 6, 5, 0, 0, 0, GLFW_WINDOW) != GL_TRUE){
        shut_down(1);
    }

    // Set window title to "Student Name: GPU Name"
    string deviceName;
    cudaDeviceProp deviceProp; 
    int gpudevice = 0;
    int device_count = 0;
    int device;
    cudaGetDeviceCount( &device_count); 
    if (gpudevice > device_count) 
    { 
      printf("Error: GPU device number is greater than the number of devices! Perhaps a CUDA-capable GPU is not installed?\n"); 
      exit(1); 
    } 
    cudaError_t cudareturn; 
    cudaGetDeviceProperties(&deviceProp,  gpudevice); 
    deviceName = deviceProp.name;
    deviceName = yourName + ": " + deviceProp.name;
    major = deviceProp.major;
    minor = deviceProp.minor;
    glfwSetWindowTitle(deviceName.c_str());

    // Set up vertex array object, texture stuff
    initVAO();
    initTextures();
}
Exemple #5
0
void MainWidget::initializeGL()
{
    initializeOpenGLFunctions();



    connect(this, SIGNAL(frameSwapped()), this, SLOT(update()));

    //animationTimer.setSingleShot(true);
    //connect(&animationTimer, SIGNAL(timeout()), this, SLOT(animate()));

    distance = -4;
    trackball = TrackBall(0.0f, QVector3D(0, 1, 0), TrackBall::Sphere);

    glClearColor(0.05, 0.05, 0.05, 1);

    // Enable depth buffer
    glEnable(GL_DEPTH_TEST);

    // Enable back face culling
    glEnable(GL_CULL_FACE);
    glFrontFace(GL_CCW);
    glCullFace(GL_BACK);

    initShaders();
    initTextures();

    geometries = new GeometryEngine(&programearth, &programearthnobump);
    gshhs = new gshhsData(&programgshhs);
    skybox = new SkyBox(&programskybox);

 }
BlockBasic::BlockBasic(int blockId, const std::string& assetName) :
	Block(assetName, blockId, assetName, Material::mMaterials[3]) {
	setDestroyTime(1.0F);
	setExplodeable(15.0F);
	creativeCategory = 0;
	initTextures();
}
void SurfaceGraph::initializeGL()
{
    initializeOpenGLFunctions();

    glClearColor(0, 0, 0, 1);


    initShaders();
    initTextures();

    // Enable depth buffer
    glEnable(GL_DEPTH_TEST);

    // Enable back face culling
    glEnable(GL_CULL_FACE);

    // Change znear - zfar
    double fovy = 45.0f;
    double aspect = 1.333f;
    double zNear = 0.1f;
    double zFar = 100.0f;

    GLdouble xmin, xmax, ymin, ymax;
    ymax = zNear * tan( fovy * M_PI / 360.0 );
    ymin = -ymax;
    xmin = ymin * aspect;
    xmax = ymax * aspect;

    glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );

    geometries = new GeometryEngine;

    // Use QBasicTimer because its faster than QTimer
    timer.start(12, this);
}
void Init(){

	glClearColor(0.5, 0.5, 0.5, 1);
	glClearDepth(1);
	glEnable(GL_DEPTH_TEST);

	for (size_t i = 0; i < 256; i++)
	{
		vecSpecialKeyPressed[i] = false;
		vecKeyPressed[i] = false;
	}

	initShaders();

	initTextures();

	initMouseMovements();

	initVectors();

	initCubeMap();

	initTerrain();

	initVegetation();

	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	GLint MaxPatchVertices = 0;
	glGetIntegerv(GL_MAX_PATCH_VERTICES, &MaxPatchVertices);
	printf("Max supported patch vertices %d\n", MaxPatchVertices);
}
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;
}
Exemple #10
0
void MainWidget::initializeGL()
{
    initializeGLFunctions();

    qglClearColor(Qt::black);

    qDebug() << "Initializing shaders...";
    initShaders();

    qDebug() << "Initializing textures...";
    initTextures();

//! [2]
    // Enable depth buffer
    glEnable(GL_DEPTH_TEST);

    // Enable back face culling
    glEnable(GL_CULL_FACE);
//! [2]

    qDebug() << "Initializing geometries...";
    geometries->init();

    // using QBasicTimer because its faster that QTimer
    timer->start(12, this);
}
Exemple #11
0
void initEditor(void)
{
	lcdMainOnBottom();
	videoSetMode(MODE_5_3D);
	videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);
	
	vramSetPrimaryBanks(VRAM_A_TEXTURE,VRAM_B_TEXTURE,VRAM_C_SUB_BG,VRAM_D_TEXTURE);	
	
	glInit();
	
	glEnable(GL_TEXTURE_2D);
	// glEnable(GL_ANTIALIAS);
	glEnable(GL_BLEND);
	glEnable(GL_OUTLINE);
	
	glClearPolyID(63);
	glClearDepth(0x7FFF);
	glViewport(0,0,255,191);
	
	initVramBanks(1);
	initTextures();
	
	initRoomEdition();
	NOGBA("START mem free : %dko (%do)",getMemFree()/1024,getMemFree());

	fadeIn();
}
Exemple #12
0
// Your initialization code goes here.
void InitializeMyStuff()
{
  gRat.setMaze(&gMaze);
  gFirstPerson = true;

  initTextures();
}
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;
}
Exemple #14
0
bool WaterObject::onAdd()
{
   if ( !Parent::onAdd() )
      return false;

   Con::NotifyDelegate clbk( this, &WaterObject::_onDisableTrueRelfections );   
   Con::addVariableNotify( "$pref::Water::disableTrueReflections", clbk );

   if ( isClientObject() )
   {
      GFXStateBlockDesc desc;
      desc.blendDefined = true;
      desc.blendEnable = true;
      desc.blendSrc = GFXBlendSrcAlpha;
      desc.blendDest = GFXBlendInvSrcAlpha;
      desc.zDefined = true;
      desc.zEnable = false;
      desc.cullDefined = true;
      desc.cullMode = GFXCullNone;
      mUnderwaterSB = GFX->createStateBlock( desc );

      initTextures();
      
      if ( mFullReflect && !smDisableTrueReflections )
         mPlaneReflector.registerReflector( this, &mReflectorDesc );
   }

   return true;
}
CardinalStick::CardinalStick(short itemId) : Item("cardinalStick", itemId - 0x100) {
	creativeCategory = CreativeItemCategory::ITEMS;
	setMaxStackSize(6);
	setStackedByData(true);
	Item::mItems[itemId] = this;
	
	initTextures();
}
Exemple #16
0
int main() {
	init();
	storeData();
	initTextures();
	startLoop();

	return 1;
}
Exemple #17
0
void initMenu(void)
{
	lcdMainOnTop();
	videoSetMode(MODE_5_3D);
	videoSetModeSub(MODE_5_2D);
	
	vramSetPrimaryBanks(VRAM_A_TEXTURE,VRAM_B_TEXTURE,VRAM_C_SUB_BG,VRAM_D_TEXTURE);	
	
	initD3D();

	glInit();
	
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_ANTIALIAS);
	glEnable(GL_BLEND);
	glEnable(GL_OUTLINE);
	
	glClearPolyID(63);
	glClearDepth(0x7FFF);
	glViewport(0,0,255,191);
	
	initVramBanks(2);
	initTextures();

	initMenuScene();

	initMenuButtons();

	//TEMP
	glLight(0, RGB15(31,31,31), cosLerp(4096), 0, sinLerp(4096));

	glMaterialf(GL_AMBIENT, RGB15(8,8,8));
	glMaterialf(GL_DIFFUSE, RGB15(24,24,24));
	glMaterialf(GL_SPECULAR, RGB15(0,0,0));
	glMaterialf(GL_EMISSION, RGB15(0,0,0));

	glSetToonTableRange(0, 15, RGB15(8,8,8)); //TEMP?
	glSetToonTableRange(16, 31, RGB15(24,24,24)); //TEMP?

	applyCameraState(&menuCamera,&cameraStates[4]);
	tempState=cameraStates[4];
	testTransition=startCameraTransition(&cameraStates[1],&cameraStates[4],64);

	setupMenuPage(startMenuPage, startMenuPageLength);

	logoMain=createTexture("logo.pcx", "menu");
	logoRotate=createTexture("rotate_logo.pcx", "menu");
	logoAlpha=31;

	glSetOutlineColor(0,RGB15(0,0,0)); //TEMP?
	glSetOutlineColor(1,RGB15(0,0,0)); //TEMP?
	glSetOutlineColor(7,RGB15(0,0,0)); //TEMP?

	NOGBA("END mem free : %dko (%do)",getMemFree()/1024,getMemFree());
	fadeIn();
}
Exemple #18
0
// Initialize variables and call initalizations for the window, openGL, and textures
void init() {
	clockwise = true;
	rotVel = 0.5;
	negRotVel = rotVel * -1.0;

	initFaces();
	initWindow();
	initOpenGL();
	initTextures();
}
/**
 * Initialization of CUDA and GLFW.
 */
bool init(int argc, char **argv) {
    // Set window title to "Student Name: [SM 2.0] GPU Name"
    std::string deviceName;
    cudaDeviceProp deviceProp;
    int gpuDevice = 0;
    int device_count = 0;
    cudaGetDeviceCount(&device_count);
    if (gpuDevice > device_count) {
        std::cout << "Error: GPU device number is greater than the number of devices!" <<
                  "Perhaps a CUDA-capable GPU is not installed?" << std::endl;
        return false;
    }
    cudaGetDeviceProperties(&deviceProp, gpuDevice);
    m_major = deviceProp.major;
    m_minor = deviceProp.minor;

    std::ostringstream ss;
    ss << m_yourName << ": [SM " << m_major << "." << m_minor << "] " << deviceProp.name;
    deviceName = ss.str();

    // Window setup stuff
    glfwSetErrorCallback(errorCallback);

    if (!glfwInit()) {
        return false;
    }
    m_width = 800;
    m_height = 800;
    m_window = glfwCreateWindow(m_width, m_height, deviceName.c_str(), NULL, NULL);
    if (!m_window) {
        glfwTerminate();
        return false;
    }
    glfwMakeContextCurrent(m_window);
    glfwSetKeyCallback(m_window, keyCallback);

    glewExperimental = GL_TRUE;
    if (glewInit() != GLEW_OK) {
        return false;
    }

    // init all of the things
    initVAO();
    initTextures();
    initCUDA();
    initPBO(&m_pbo);

    GLuint passthroughProgram;
    passthroughProgram = initShader();
    glUseProgram(passthroughProgram);
    glActiveTexture(GL_TEXTURE0);

    return true;
}
Exemple #20
0
void GLWidgetRendererPrivate::updateTexturesIfNeeded()
{
    const VideoFormat &fmt = video_frame.format();
    bool update_textures = false;
    if (fmt != video_format) {
        update_textures = true;
        qDebug("pixel format changed: %s => %s", qPrintable(video_format.name()), qPrintable(fmt.name()));
        // http://forum.doom9.org/archive/index.php/t-160211.html
        ColorTransform::ColorSpace cs = ColorTransform::BT601;
        if (video_frame.width() >= 1280 || video_frame.height() > 576) //values from mpv
            cs = ColorTransform::BT709;
        if (!prepareShaderProgram(fmt, cs)) {
            qWarning("shader program create error...");
            return;
        } else {
            qDebug("shader program created!!!");
        }
    }
    // effective size may change even if plane size not changed
    if (update_textures
            || video_frame.bytesPerLine(0) != plane0Size.width() || video_frame.height() != plane0Size.height()
            || (plane1_linesize > 0 && video_frame.bytesPerLine(1) != plane1_linesize)) { // no need to check hieght if plane 0 sizes are equal?
        update_textures = true;
        //qDebug("---------------------update texture: %dx%d, %s", video_frame.width(), video_frame.height(), video_frame.format().name().toUtf8().constData());
        const int nb_planes = fmt.planeCount();
        texture_size.resize(nb_planes);
        texture_upload_size.resize(nb_planes);
        effective_tex_width.resize(nb_planes);
        for (int i = 0; i < nb_planes; ++i) {
            qDebug("plane linesize %d: padded = %d, effective = %d", i, video_frame.bytesPerLine(i), video_frame.effectiveBytesPerLine(i));
            qDebug("plane width %d: effective = %d", video_frame.planeWidth(i), video_frame.effectivePlaneWidth(i));
            qDebug("planeHeight %d = %d", i, video_frame.planeHeight(i));
            // we have to consider size of opengl format. set bytesPerLine here and change to width later
            texture_size[i] = QSize(video_frame.bytesPerLine(i), video_frame.planeHeight(i));
            texture_upload_size[i] = texture_size[i];
            effective_tex_width[i] = video_frame.effectiveBytesPerLine(i); //store bytes here, modify as width later
            // TODO: ratio count the GL_UNPACK_ALIGN?
            //effective_tex_width_ratio = qMin((qreal)1.0, (qreal)video_frame.effectiveBytesPerLine(i)/(qreal)video_frame.bytesPerLine(i));
        }
        plane1_linesize = 0;
        if (nb_planes > 1) {
            texture_size[0].setWidth(texture_size[1].width() * effective_tex_width[0]/effective_tex_width[1]);
            // height? how about odd?
            plane1_linesize = video_frame.bytesPerLine(1);
        }
        effective_tex_width_ratio = (qreal)video_frame.effectiveBytesPerLine(nb_planes-1)/(qreal)video_frame.bytesPerLine(nb_planes-1);
        qDebug("effective_tex_width_ratio=%f", effective_tex_width_ratio);
        plane0Size.setWidth(video_frame.bytesPerLine(0));
        plane0Size.setHeight(video_frame.height());
    }
    if (update_textures) {
        initTextures(fmt);
    }
}
// Assumes that arguments are powers of 2, and that
// grids_per_edge / grids_per_patch_edge = power of 2 
void LLSurface::create(const S32 grids_per_edge,
					   const S32 grids_per_patch_edge,
					   const LLVector3d &origin_global,
					   const F32 width) 
{
	// Initialize various constants for the surface
	mGridsPerEdge = grids_per_edge + 1;  // Add 1 for the east and north buffer
	mOOGridsPerEdge = 1.f / mGridsPerEdge;
	mGridsPerPatchEdge = grids_per_patch_edge;
	mPatchesPerEdge = (mGridsPerEdge - 1) / mGridsPerPatchEdge;
	mNumberOfPatches = mPatchesPerEdge * mPatchesPerEdge;
	mMetersPerGrid = width / ((F32)(mGridsPerEdge - 1));
	mMetersPerEdge = mMetersPerGrid * (mGridsPerEdge - 1);
// <FS:CR> Aurora Sim
	sTextureSize = width;
// </FS:CR> Aurora Sim

	mOriginGlobal.setVec(origin_global);

	mPVArray.create(mGridsPerEdge, mGridsPerPatchEdge, LLWorld::getInstance()->getRegionScale());

	S32 number_of_grids = mGridsPerEdge * mGridsPerEdge;

	/////////////////////////////////////
	//
	// Initialize data arrays for surface
	///
	mSurfaceZ = new F32[number_of_grids];
	mNorm = new LLVector3[number_of_grids];

	// Reset the surface to be a flat square grid
	for(S32 i=0; i < number_of_grids; i++) 
	{
		// Surface is flat and zero
		// Normals all point up
		mSurfaceZ[i] = 0.0f;
		mNorm[i].setVec(0.f, 0.f, 1.f);
	}


	mVisiblePatchCount = 0;


	///////////////////////
	//
	// Initialize textures
	//

	initTextures();

	// Has to be done after texture initialization
	createPatchData();
}
Exemple #22
0
void MainWidget::initializeGL()
{
  initializeGLFunctions();
  qglClearColor(Qt::black);
  initShaders();
  initTextures();

  glEnable(GL_DEPTH_TEST);
  glEnable(GL_CULL_FACE);

  geometries.init(imageRatio);
}
Exemple #23
0
Texture::Texture() {
	m_numTex = NUM_TEX;
	m_texID = new GLuint[m_numTex];

	for (int i = 0; i < m_numTex; i++) {
		m_texID[i] = 0;
	}

	glGenTextures(m_numTex, m_texID);
	if (glGetError()) cout << "[Texture.cpp] ERROR : could not glGenTextures in ctor!";

	initTextures();
}
Exemple #24
0
bool App::OnInit() {
	_frame = new GLFrame( "Hello World", wxPoint(50, 50), wxSize(1024, 768) );
	_frame->Show( true );
	initShader("E:/Vault/glmanv2/vir.json");
	initUniforms();
	initModels();
	initTextures();
	ControlFrame* controlFrame = new ControlFrame();
	controlFrame->Show( true );
	_eventTimer = new wxTimer(this, kEventTimerId);
	_eventTimer->Start(1, wxTIMER_CONTINUOUS);
	return true;
}
int	createGNSWindow()
{
    int res = 0;

    XPLMCreateWindow_t win;
    win.structSize = sizeof(XPLMCreateWindow_t);
    win.left = g_pos_x;
    win.top = g_pos_y + (int)(gpGNSIntf->bezel_height*g_zoom);
    win.right = g_pos_x+(int)(gpGNSIntf->bezel_width*g_zoom);
    win.bottom = g_pos_y;
    win.visible = true;
    win.drawWindowFunc = myDrawWindowCallback;
    win.handleMouseClickFunc = myHandleMouseClickCallback;
    win.handleKeyFunc = myHandleKeyCallback;
    win.handleCursorFunc = myHandleCursorCallback;
    win.handleMouseWheelFunc = myHandleMouseWheelFunc;
    win.refcon = NULL;



    //Register the Draw Window
    // Create a windows for displaying the projection info
    gWindow = XPLMCreateWindowEx(&win);

    logMessageEx("--- GNS Window created");

    initTextures();
    logMessageEx("--- Textures created");

    /// Register so that our gauge is drawing during the Xplane gauge phase
    XPLMRegisterDrawCallback(myDrawGNSCallback, xplm_Phase_Window, 1, NULL); // before window draw
    logMessageEx("--- DrawCallback registered");

    //Register the callback for gUpdateInterval.  Positive intervals
    //are in seconds, negative are the negative of sim frames.  Zero
    //registers but does not schedule a callback for time.
    XPLMRegisterFlightLoopCallback(myFlightLoopCallback, gUpdateInterval, NULL);
    logMessageEx("--- FlightLoopCallback registered");

    //Set the initial values of the COM and NAV
    gGNSx30Proxy.setCOMActiveFrequency(XPLMGetDatai(g_com1_active_ref)*10);
    gGNSx30Proxy.setCOMStandbyFrequency(XPLMGetDatai(g_com1_standby_ref)*10);
    gGNSx30Proxy.setNAVActiveFrequency(XPLMGetDatai(g_nav1_active_ref)*10);
    gGNSx30Proxy.setNAVStandbyFrequency(XPLMGetDatai(g_nav1_standby_ref)*10);


    gnsOpened = true;

    return res;
}
Exemple #26
0
// Initialize variables and call initalizations for the window, openGL, and textures
void init() {
	rotX = rotY = rotZ = 0;
	rotAmt = 0.5;

	// Each axis will have no rotation when first initalized.
	AxisRotation tmp = {false, false};
	for( int i = 0; i < 3; i++ ) {
		movingRotation[i] = tmp;
	}
	
	initWindow();
	initOpenGL();
	initTextures();
}
Exemple #27
0
  void init(){

    if (glfwInit() != GL_TRUE){
      shut_down(1);      
    }

    // 16 bit color, no depth, alpha or stencil buffers, windowed
    if (glfwOpenWindow(width, height, 5, 6, 5, 0, 0, 0, GLFW_WINDOW) != GL_TRUE){
      shut_down(1);
    }

    // Set up vertex array object, texture stuff
    initVAO();
    initTextures();
  }
bool PhGraphicTexturedRect::createTextureFromBGRABuffer(void *data, int width, int height)
{
    swapTextures();

    glEnable( GL_TEXTURE_2D );

    if(!initTextures()) {
        return false;
    }

    if((width != _textureWidth) || (height != _textureHeight)) {
        _textureWidth = width;
        _textureHeight = height;

//		PHDEBUG << QString("%1x%2").arg(width).arg(height);

        // Bind the texture object
        glBindTexture( GL_TEXTURE_2D, _previousTexture );

        // Edit the texture object's image data using the information SDL_Surface gives us
        // Note: Store internally in GL_RGBA8, and upload from our buffer which is
        // GL_BGRA/GL_UNSIGNED_INT_8_8_8_8_REV.
        // This combination is supposed to be optimal on Windows with both nVidia and AMD,
        // avoiding all	CPU-based conversion and allowing direct DMA to video card
        // See: http://www.opengl.org/wiki/Common_Mistakes#Slow_pixel_transfer_performance
        // Also see: http://www.opengl.org/wiki/Common_Mistakes#Image_precision
        // It is also optimal for MacOS. See 'Optimal Data Formats and Types' in:
        // https://developer.apple.com/library/mac/documentation/graphicsimaging/conceptual/opengl-macprogguide/opengl_texturedata/opengl_texturedata.html#//apple_ref/doc/uid/TP40001987-CH407-SW1
        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0,
                      GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);

        // Bind the texture object
        glBindTexture( GL_TEXTURE_2D, _currentTexture );

        // Edit the texture object's image data using the information SDL_Surface gives us
        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0,
                      GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
    }
    else {
        // Bind the texture object
        glBindTexture( GL_TEXTURE_2D, _currentTexture );
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
    }

    applyTextureSettings();

    return true;
}
Exemple #29
0
int main (int argc, char **argv) {
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitContextVersion(3,3);
	glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
	glutInitContextProfile(GLUT_CORE_PROFILE);

	windowWidth = 512;
	windowHeight = 512;
	glutInitWindowSize(windowWidth, windowHeight);
	glutInitWindowPosition(100, 100);
	glutCreateWindow("Exercise 07 - Textures");

	glutDisplayFunc(updateGL);
	glutIdleFunc(idle);
	glutKeyboardFunc(keyboardEvent);
	glutMouseFunc(mouseEvent);
	glutMotionFunc(mouseMoveEvent);

	glewExperimental = GL_TRUE;
	GLenum err = glewInit();
	if (GLEW_OK != err) {
		std::cout << "(glewInit) - Error: " << glewGetErrorString(err) << std::endl;
	}
	std::cout << "(glewInit) - Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;

	// init stuff //
	initGL();

	// init matrix stacks with identity //
	glm_ProjectionMatrix.push(glm::mat4(1));
	glm_ModelViewMatrix.push(glm::mat4(1));

	initShader();
	initScene();
	initTextures();

	// start render loop //
	if (enableShader()) {
		glutMainLoop();
		disableShader();

		// clean up allocated data //
		deleteShader();
	}

	return 0;
}
void main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(10,10);
	glutInitWindowSize(512,512);

	glutCreateWindow("LinePrimitives Demo");
	glutDisplayFunc(renderScene);
	glutIdleFunc(renderScene);

	glutReshapeFunc(changeSize);

	glutKeyboardFunc(processNormalKeys);
	glutMouseFunc(processMouse);
	glutMotionFunc(processMouseActiveMotion);

	glEnable(GL_DEPTH_FUNC);

	if (glewInit() == GLEW_OK)
	{
		if (!GLEW_ARB_multitexture)
			return;

		// load shader
		lineShader = new CShader();
		lineShader->InitShaders("VertexShader.glsl", "FragmentShader.glsl");

		lineShader->TurnOn();
		profile = lineShader->GetVariable("profile");
		texture = lineShader->GetVariable("texture");
		haloColor = lineShader->GetVariable("haloColor");

		lineShader->TurnOff();

		initStructure();
		initTextures();

		glutMainLoop();

		lineShader->Release();
		delete lineShader;
	}
	else
	{
		printf("This sucks.");
	}
}