Example #1
0
//--------------------------------------------------------------
void testApp::draw() {
    //ofBackground(ofColor(ofColor::white));
	ofSetColor(255);
	if(m_bDrawKeyboard){
        drawKeyboard();
	}

/*
	// draw the last recieved message contents to the screen
	text << "Received: " << ofxMidiMessage::getStatusString(midiMessage.status);
	ofDrawBitmapString(text.str(), 20, 20);
	text.str(""); // clear

	text << "channel: " << midiMessage.channel;
	ofDrawBitmapString(text.str(), 20, 34);
	text.str(""); // clear

	text << "pitch: " << midiMessage.pitch;
	ofDrawBitmapString(text.str(), 20, 48);
	text.str(""); // clear
	ofRect(20, 58, ofMap(midiMessage.pitch, 0, 127, 0, ofGetWidth()-40), 20);

	text << "velocity: " << midiMessage.velocity;
	ofDrawBitmapString(text.str(), 20, 96);
	text.str(""); // clear
	ofRect(20, 105, ofMap(midiMessage.velocity, 0, 127, 0, ofGetWidth()-40), 20);

	text << "control: " << midiMessage.control;
	ofDrawBitmapString(text.str(), 20, 144);
	text.str(""); // clear
	ofRect(20, 154, ofMap(midiMessage.control, 0, 127, 0, ofGetWidth()-40), 20);

	text << "value: " << midiMessage.value;
	ofDrawBitmapString(text.str(), 20, 192);
	text.str(""); // clear
	if(midiMessage.status == MIDI_PITCH_BEND) {
		ofRect(20, 202, ofMap(midiMessage.value, 0, MIDI_MAX_BEND, 0, ofGetWidth()-40), 20);
	}
	else {
		ofRect(20, 202, ofMap(midiMessage.value, 0, 127, 0, ofGetWidth()-40), 20);
	}

	text << "delta: " << midiMessage.deltatime;
	ofDrawBitmapString(text.str(), 20, 240);
	text.str(""); // clear

*/
}
Example #2
0
void KMidChannel::paintEvent( QPaintEvent * )
{

    QPainter *qpaint=new QPainter(this);

    char tmp[110];
    sprintf(tmp,"%s %d",i18n("Channel"),channel);
    qpaint->setFont(*qcvfont);
    qpaint->setPen(*penB);
    qpaint->drawText(2,20,tmp);
    qpaint->setPen(*penW);
    qpaint->drawText(0,18,tmp);

    drawKeyboard(qpaint);
    drawPressedKeys(qpaint);
    
    delete qpaint;
};
Example #3
0
// this code will render to the selection buffer and then process hits to figure out which key was clicked
// some of this code is from http://content.gpwiki.org/index.php/OpenGL:Tutorials:Picking
// and http://www.lighthouse3d.com/opengl/picking/index.php3?openglway3
void doSelection (int x, int y)
{
	GLuint buf[64] = {0};
	GLint hits, view[4];
	int id;
	glSelectBuffer(64, buf);
	glGetIntegerv(GL_VIEWPORT, view);
	glRenderMode (GL_SELECT);
	glInitNames();
	glPushName(0);

	glMatrixMode (GL_PROJECTION);
	glLoadIdentity();
	gluPickMatrix (x, y, 1.0, 1.0, view);
	gluPerspective (45, (float)view[2]/(float)view[3], 1.0, 1000.0);

	drawKeyboard();

	hits = glRenderMode (GL_RENDER);

	// if no hits then we are done here
	if (hits == 0)
		return;

	// find hit with max MinZ
	int max = 0, closest = 0;
	GLuint * ptr = NULL;
	for (int i = 0; i < hits; ++i)
	{
		if ((GLubyte)buf[i * 4 + 1] > max)
		{
			max = (GLubyte)buf[i * 4 + 1];
			closest = i;
		}
	}
	unsigned char c = buf[closest*4 + 3];

	// flip bit
	g_keysdown_arr[c] = !g_keysdown_arr[c];

	// add letter to text vector
	g_text.push_back((char)c);
}
Example #4
0
//Begins Text Input
void getText(char *buffer)
{
	int FINISHED = 0;
	clearScreen();
	setupInterrupts();
	initializeSprites();
	drawKeyboard();
	playBG = TRUE;	
	while(!FINISHED)
	{
		if(playBG && !BGplaying)
        {
            // play the bg music
            DMA[2].cnt |= DMA_ON;
            REG_TM1CNT |= TM_ON;
            startBG = vblankcount;
            BGplaying = TRUE;
            DMA[2].src = flute;
        }
		checkMovement();
		//Check Input and End Function if finished
		if(!endInput)
		{
			checkSelection(buffer);
			copyShadow();
			waitForVblank();
			moveSpriteToMem();
		}
		else
		{
			DMA[2].cnt &= ~DMA_ON;
            REG_TM1CNT &= ~TM_ON;
			playBG = FALSE;
			waitForVblank();
			FINISHED = 1;
			resetVariables();
			endInput = 0;
			resetCursor();
		}
		
	}
	clearScreen();
}
Example #5
0
//Begins Text Input
void getText(char *buffer)
{
	setRegister();
	setupInterrupts();
	initializeTiles();
	initializeSprites();
	drawKeyboard();
	playBG = TRUE;	
	while(1)
	{
		if(playBG && !BGplaying)
        {
            // play the bg music
            DMA[2].cnt |= DMA_ON;
            REG_TM1CNT |= TM_ON;
            startBG = vblankcount;
            BGplaying = TRUE;
            DMA[2].src = flute;
        }
		checkMovement();
		if(!endInput)
		{
			checkSelection(buffer);
		}
		else
		{
			DMA[2].cnt &= ~DMA_ON;
            REG_TM1CNT &= ~TM_ON;
			playBG = FALSE;
			waitForVblank();
		}
		copyShadow();
		waitForVblank();
		moveSpriteToMem();
	}
}
Example #6
0
// the main function
int main (int argc, char **argv) 
{
	Init();

	SetupCubeMap();

	// load our shaders and compile them.. create a program and link it
	GLuint glShaderV = glCreateShader(GL_VERTEX_SHADER);
	GLuint glShaderF = glCreateShader(GL_FRAGMENT_SHADER);
	const GLchar* vShaderSource = loadFile("skybox.vert.hlsl");
	const GLchar* fShaderSource = loadFile("skybox.frag.hlsl");
	glShaderSource(glShaderV, 1, &vShaderSource, NULL);
	glShaderSource(glShaderF, 1, &fShaderSource, NULL);
	glCompileShader(glShaderV);
	CheckShaderCompilation(glShaderV);
	glCompileShader(glShaderF);
	CheckShaderCompilation(glShaderF);
	delete[] vShaderSource;
	delete[] fShaderSource;

	GLuint cubeMapProg = glCreateProgram();
	glAttachShader(cubeMapProg, glShaderV);
	glAttachShader(cubeMapProg, glShaderF);
	glLinkProgram(cubeMapProg);
	glUseProgram(cubeMapProg);
	int  vlength,    flength;
	char vlog[2048], flog[2048];
	glGetShaderInfoLog(glShaderV, 2048, &vlength, vlog);
	glGetShaderInfoLog(glShaderF, 2048, &flength, flog);
	std::cout << vlog << std::endl << std::endl << flog << std::endl << std::endl;
	
	// load shaders for the keyboard geometry
	glShaderV = glCreateShader (GL_VERTEX_SHADER);
	glShaderF = glCreateShader (GL_FRAGMENT_SHADER);
	const GLchar * mVSource = loadFile ("model.vert.hlsl");
	const GLchar * mFSource = loadFile ("model.frag.hlsl");
	glShaderSource(glShaderV, 1, &mVSource, NULL);
	glShaderSource(glShaderF, 1, &mFSource, NULL);
	delete [] mVSource;
	delete [] mFSource;
	glCompileShader(glShaderV);
	CheckShaderCompilation(glShaderV);
	glCompileShader(glShaderF);
	CheckShaderCompilation(glShaderF);
	GLuint modelProg = glCreateProgram();
	glAttachShader(modelProg, glShaderV);
	glAttachShader(modelProg, glShaderF);
	glLinkProgram(modelProg);
	glUseProgram(modelProg);
	glGetShaderInfoLog(glShaderV, 2048, &vlength, vlog);
	glGetShaderInfoLog(glShaderF, 2048, &flength, flog);
	std::cout << vlog << std::endl << std::endl << flog << std::endl << std::endl;

	// load texture with letters on keyboard
	SDL_Surface *keySurface = IMG_Load ("keys.png"); // I made this image with GIMP
	GLuint keys_texture;
	glActiveTexture (GL_TEXTURE0);
	glEnable (GL_TEXTURE_2D);
	glGenTextures (1, &keys_texture);
	glBindTexture (GL_TEXTURE_2D, keys_texture);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
	glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, keySurface->w, keySurface->h, 0, keySurface->format->BytesPerPixel == 4? GL_RGBA: GL_RGB, GL_UNSIGNED_BYTE, keySurface->pixels);
	glBindTexture (GL_TEXTURE_2D, 0);
	SDL_FreeSurface (keySurface);
	GLint uniform_keys = glGetUniformLocation (modelProg, "keys");

	// load premade bitmap font
	// http://www.amanithvg.com/testsuite/amanithvg_sre/data/font_bitmap.png
	SDL_Surface *bmf = IMG_Load ("font_bitmap.png");
	GLuint bmf_texture;
	glActiveTexture(GL_TEXTURE0);
	glEnable (GL_TEXTURE_2D);
	glGenTextures (1, &bmf_texture);
	glBindTexture (GL_TEXTURE_2D, bmf_texture);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
	glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, bmf->w, bmf->h, 0, bmf->format->BytesPerPixel == 4? GL_RGBA: GL_RGB, GL_UNSIGNED_BYTE, bmf->pixels);
	glBindTexture (GL_TEXTURE_2D, 0);
	SDL_FreeSurface (bmf);

	// grab the pvm matrix and vertex location from our shader program
	GLint PVM    = glGetUniformLocation(cubeMapProg, "PVM");
	GLint vertex = glGetAttribLocation(cubeMapProg, "vertex");

	// these won't change for now
	glm::mat4 Projection = glm::perspective(45.0f, (float)WIDTH / (float)HEIGHT, 0.1f, 100.0f); 
	glm::mat4 View       = glm::mat4(1.0f);
	glm::mat4 Model      = glm::scale(glm::mat4(1.0f),glm::vec3(50,50,50));

	// cube vertices for vertex buffer object
	GLfloat cube_vertices[] = {
		-1.0,  1.0,  1.0,
		-1.0, -1.0,  1.0,
		1.0, -1.0,  1.0,
		1.0,  1.0,  1.0,
		-1.0,  1.0, -1.0,
		-1.0, -1.0, -1.0,
		1.0, -1.0, -1.0,
		1.0,  1.0, -1.0,
	};

	// vertex array buffer
	GLuint vbo_cube_vertices;
	glGenBuffers(1, &vbo_cube_vertices);
	glBindBuffer(GL_ARRAY_BUFFER, vbo_cube_vertices);
	glBufferData(GL_ARRAY_BUFFER, sizeof(cube_vertices), cube_vertices, GL_STATIC_DRAW);
	glEnableVertexAttribArray(vertex);
	glVertexAttribPointer(vertex, 3, GL_FLOAT, GL_FALSE, 0, 0);

	// cube indices for index buffer object
	GLushort cube_indices[] = {
		0, 1, 2, 3,
		3, 2, 6, 7,
		7, 6, 5, 4,
		4, 5, 1, 0,
		0, 3, 7, 4,
		1, 2, 6, 5,
	};

	// index array buffer
	GLuint ibo_cube_indices;
	glGenBuffers(1, &ibo_cube_indices);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_cube_indices);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cube_indices), cube_indices, GL_STATIC_DRAW);

	// vars
	float alpha = 0.f, beta = 0.f, gamma = 50.f;
	int locX = 0, locY = 0, pressedX = 0, pressedY = 0;
	float origX = 0.f, origY = 0.f;
	bool done = false;
	bool mouse_down = false;
	char * ch = NULL;
	unsigned int num_ticks = 0;

	// for handling events
	SDL_Event event;

	// the game loop
	while(!done)
	{		
		// get the current time... might be useful.
		num_ticks = SDL_GetTicks();

		// process inputs
		while (SDL_PollEvent(&event)) {
			switch (event.type) {
			case SDL_QUIT:
				done = true;
				break;
			case SDL_MOUSEMOTION:
				locX = event.motion.x;
				locY = event.motion.y;
				break;
			case SDL_MOUSEBUTTONDOWN:
				mouse_down = true;
				pressedX = event.button.x;
				pressedY = event.button.y;
				switch (event.button.button)
				{
				case SDL_BUTTON_LEFT:
					doSelection(event.button.x, HEIGHT - event.button.y);
					break;
				}
				break;
			case SDL_MOUSEBUTTONUP:
				if (mouse_down)
				{
					mouse_down = false;
					origY = alpha;
					origX = beta;
				}
				switch (event.button.button)
				{
				case SDL_BUTTON_WHEELUP:
					gamma += 10.0;
					break;
				case SDL_BUTTON_WHEELDOWN:
					gamma -= 10.0;
					if (gamma < 10.0) gamma = 10.0;
					break;
				case SDL_BUTTON_LEFT:
					//just set all keys back to up
					for (int i = 0; i < KEYDOWN_ARRAY_SIZE; ++i) g_keysdown_arr[i] = false;
					break;
				}
				break;
			case SDL_KEYDOWN:
				ch = SDL_GetKeyName(event.key.keysym.sym);
				g_keysdown_arr[(unsigned char)*ch] = true;
				g_text.push_back(*ch);
				break;
			case SDL_KEYUP:
				ch = SDL_GetKeyName(event.key.keysym.sym);
				g_keysdown_arr[(unsigned char)*ch] = false;
				break;
			default:
				break;
			}
		}

		// do updates
		if (mouse_down)
		{
			alpha = origY + locY - pressedY;
			beta = origX + locX - pressedX;
		}

		// this should add a subtle sensation of movement to the scene
		//alpha += .005*sin(0.0005*(double)num_ticks);
		//beta += .005*cos(0.0005*(double)num_ticks);

		// this marks the start of the code that draws
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		// set the program for the cubemap
		glUseProgram(cubeMapProg);

		// uniforms for sky box include the sampler and the MVP matrix
		glActiveTexture(GL_TEXTURE0);
		glEnable(GL_TEXTURE_CUBE_MAP);
		glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap_texture);

		// set up the ModelViewProj matrix for the cube map
		glm::mat4 RotateX = glm::rotate(glm::mat4(1.0f), alpha, glm::vec3(-1.0f, 0.0f, 0.0f));
		glm::mat4 RotateY = glm::rotate(RotateX, beta, glm::vec3(0.0f, 1.0f, 0.0f));
		glm::mat4 M = Projection * View * Model * RotateY;
		glUniformMatrix4fv(PVM, 1, GL_FALSE, glm::value_ptr(M));

		// bind vertex array and index array
		glBindBuffer(GL_ARRAY_BUFFER, vbo_cube_vertices);
		glEnableVertexAttribArray(vertex);
		glVertexAttribPointer(vertex, 3, GL_FLOAT, GL_FALSE, 0, 0);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_cube_indices);

		// draw cubemap
		glDrawElements(GL_QUADS, sizeof(cube_indices)/sizeof(GLushort), GL_UNSIGNED_SHORT, 0);

		// clean up OpenGL state for cubemap
		glDisable (GL_TEXTURE_CUBE_MAP);
		glDisableVertexAttribArray (vertex);

		// clear depth buffer because sky box is infinitely far away
		glClear (GL_DEPTH_BUFFER_BIT);

		// use program for rendering keyboard
		glUseProgram(modelProg);

		// enable blending for translucency
		glEnable (GL_BLEND);
		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		// enable back face culling to make translucent keys look better
		glEnable (GL_CULL_FACE);
		glCullFace (GL_BACK);

		// set up projection matrix for keyboard
		glMatrixMode (GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(45.0, (float)WIDTH/(float)HEIGHT, 0.1, 1000.0);

		// set up modelview matrix for keyboard
		glMatrixMode (GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt (0.f, 0.f, gamma, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f);
		glRotatef (-alpha, 1, 0, 0);
		glRotatef (beta, 0, 1, 0);

		// set the texture for the keys
		glActiveTexture (GL_TEXTURE0);
		glEnable (GL_TEXTURE_2D);
		glBindTexture (GL_TEXTURE_2D, keys_texture);
		glUniform1i (uniform_keys, 0);

		// draw the keyboard
		drawKeyboard();

		// clean up OpenGL state for keyboard
		glDisable (GL_BLEND);
		glDisable (GL_CULL_FACE);

		// now we print the text onto the screen
		// clear depth again
		glClear (GL_DEPTH_BUFFER_BIT);

		// render text to screen using orthographic projection
		glMatrixMode (GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		gluOrtho2D (0, WIDTH, 0, HEIGHT);
		// scale and translate to get origin in upper left hand corner of screen
		glScalef(1, -1, 1);
		glTranslatef(0, -HEIGHT, 0);
		glMatrixMode (GL_MODELVIEW);
		glPushMatrix();
		glLoadIdentity();
		glUseProgram(0); // using fixed function for the text, shaders not necessary

		// draw a translucent text box at the top of the screen
		glEnable (GL_BLEND);
		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glBegin (GL_QUADS);
		glColor4f (1.0, 1.0, 1.0, 0.5);
		glVertex2f (0.0, 0.0);
		glVertex2f (0.0, 100.0);
		glVertex2f (WIDTH, 100.0);
		glVertex2f (WIDTH, 0.0);
		glEnd ();
		glDisable (GL_BLEND);

		// draw the text
		glActiveTexture (GL_TEXTURE0);
		glEnable (GL_TEXTURE_2D);
		glBindTexture (GL_TEXTURE_2D, bmf_texture);
		glEnable (GL_BLEND);
		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		renderText();
		glMatrixMode (GL_PROJECTION);
		glPopMatrix ();
		glMatrixMode (GL_MODELVIEW);
		glPopMatrix();
		glDisable (GL_TEXTURE_2D);
		glDisable (GL_BLEND);

		// finally, swap buffers
		SDL_GL_SwapBuffers();	    
	}

	return 0;
}
Example #7
0
int main(void) {
	acInit();
	gfxInitDefault();
	
	gfxSetDoubleBuffering(GFX_TOP, false);
	gfxSetDoubleBuffering(GFX_BOTTOM, false);
	
	if(setjmp(exitJmp)) goto exit;
	
	preRenderKeyboard();
	
	clearScreen();
	drawString(10, 10, "Initing FS...");
	gfxFlushBuffers();
	gfxSwapBuffers();
	
	fsInit();
	
	clearScreen();
	drawString(10, 10, "Initing SOC...");
	gfxFlushBuffers();
	gfxSwapBuffers();
	
	SOC_Initialize((u32 *)memalign(0x1000, 0x100000), 0x100000);
	
	u32 wifiStatus = 0;
	ACU_GetWifiStatus(NULL, &wifiStatus);
	if(!wifiStatus) {
		hang("No WiFi! Is your wireless slider on?");
	}
	
	clearScreen();
	drawString(10, 10, "Reading settings...");
	gfxFlushBuffers();
	gfxSwapBuffers();
	
	if(!readSettings()) {
		hang("Could not read 3DSController.ini!");
	}
	
	clearScreen();
	drawString(10, 10, "Connecting to %s on port %d...", settings.IPString, settings.port);
	gfxFlushBuffers();
	gfxSwapBuffers();
	
	openSocket(settings.port);
	sendConnectionRequest();
	
	clearScreen();
	gfxFlushBuffers();
	gfxSwapBuffers();
	
	disableBacklight();
	
	while(aptMainLoop()) {
		hidScanInput();
		irrstScanInput();
		
		u32 kHeld = hidKeysHeld();
		circlePosition circlePad;
		circlePosition cStick;
		hidCstickRead(&cStick);
		hidCircleRead(&circlePad);
		touchPosition touch;
		touchRead(&touch);
		
		clearScreen();
		
		if((kHeld & KEY_L) && (kHeld & KEY_R) && (kHeld & KEY_X)) {
			if(keyboardToggle) {
				keyboardActive = !keyboardActive;
				keyboardToggle = false;
				
				if(keyboardActive) enableBacklight();
			}
		}
		else keyboardToggle = true;
		
		if(keyboardActive) {
			drawKeyboard();
			
			if(touch.px >= 1 && touch.px <= 312 && touch.py >= 78 && touch.py <= 208) {
				int x = (int)((float)touch.px * 12.0f / 320.0f);
				int y = (int)((float)(touch.py - 78) * 12.0f / 320.0f);
				int width = 24;
				int height = 24;
				
				if(keyboardChars[x + y * 12] == ' ') {
					while(keyboardChars[(x - 1) + y * 12] == ' ') x--;
					
					width = (int)(5.0f * 320.0f / 12.0f) - 1;
				}
				
				else if(keyboardChars[x + y * 12] == '\13') {
					while(keyboardChars[(x - 1) + y * 12] == '\13') x--;
					while(keyboardChars[x + (y - 1) * 12] == '\13') y--;
					
					width = (int)(2.0f * 320.0f / 12.0f) - 1;
					height = (int)(3.0f * 320.0f / 12.0f) - 1;
				}
				
				if(keyboardChars[x + y * 12]) drawBox((int)((float)x * 320.0f / 12.0f) + 1, (int)(78.0f + (float)y * 320.0f / 12.0f) + 1, width, height, 31, 31, 0);
			}
		}
		
		sendKeys(kHeld, circlePad, touch, cStick);
		
		//receiveBuffer(sizeof(struct packet));
		
		if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1);
		
		gfxFlushBuffers();
		gspWaitForVBlank();
		gfxSwapBuffers();
	}
	
	exit:
	
	enableBacklight();
	
	SOC_Shutdown();
	
	svcCloseHandle(fileHandle);
	fsExit();
	
	gfxExit();
	acExit();
	
	return 0;
}