Created
May 13, 2014 14:27
-
-
Save michalpelka/017b0f2b057bede023a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <helper_image.h> | |
#include <cuda_runtime.h> | |
#include <cuda.h> | |
#include <GL/glew.h> | |
#include <GL/freeglut.h> | |
#include <helper_cuda_gl.h> | |
unsigned int width=0; | |
unsigned int height=0; | |
#define REFRESH_DELAY 10 //ms | |
extern "C" void TreshImg(unsigned char *inImg, unsigned char* outImg, int w, int h); | |
GLuint texture[2]; | |
///pierwszy obrazek RGBA - orginalna Lena Söderberg | |
unsigned char *indata; | |
///pierwszy obrazek uint8 - przetworzona Lena Söderberg | |
unsigned char *outdata; | |
void timerEvent(int value); | |
//GLUT SSIE!!! | |
//CHCĘ KJUTA!! | |
void display() | |
{ | |
// execute filter, writing results to pbo | |
unsigned int *d_result; | |
///pierwsza tekstura lena1 | |
glGenTextures(2, texture); | |
glBindTexture(GL_TEXTURE_2D, texture[0]); | |
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); | |
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); | |
glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, indata); | |
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); | |
//druga lena | |
glBindTexture(GL_TEXTURE_2D, texture[1]); | |
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); | |
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); | |
glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, outdata); | |
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); | |
// display results | |
glClear(GL_COLOR_BUFFER_BIT); | |
glEnable(GL_TEXTURE_2D); | |
glDisable(GL_DEPTH_TEST); | |
glBindTexture(GL_TEXTURE_2D, texture[0]); | |
glBegin(GL_QUADS); | |
glTexCoord2f(0, 1); | |
glVertex2f(0, 0); | |
glTexCoord2f(1, 1); | |
glVertex2f(1, 0); | |
glTexCoord2f(1, 0); | |
glVertex2f(1, 1); | |
glTexCoord2f(0, 0); | |
glVertex2f(0, 1); | |
glEnd(); | |
glBindTexture(GL_TEXTURE_2D, texture[1]); | |
glBegin(GL_QUADS); | |
glTexCoord2f(0, 1); | |
glVertex2f(1, 0); | |
glTexCoord2f(1, 1); | |
glVertex2f(2, 0); | |
glTexCoord2f(1, 0); | |
glVertex2f(2, 1); | |
glTexCoord2f(0, 0); | |
glVertex2f(1, 1); | |
glEnd(); | |
glDisable(GL_TEXTURE_2D); | |
glutSwapBuffers(); | |
} | |
void initGL(int *argc, char **argv) | |
{ | |
// initialize GLUT | |
glutInit(argc, argv); | |
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); | |
glutInitWindowSize(1024, 512); | |
glutCreateWindow("Zad1"); | |
gluOrtho2D(0, 2, 0, 1); | |
glutDisplayFunc(display); | |
glutTimerFunc(REFRESH_DELAY, timerEvent, 0); | |
glewInit(); | |
} | |
void timerEvent(int value) | |
{ | |
glutPostRedisplay(); | |
glutTimerFunc(REFRESH_DELAY, timerEvent, 0); | |
} | |
void main (int *argc, char **argv) | |
{ | |
//rezerwacja pamięci na hoscie | |
indata = new unsigned char [4*512*512]; | |
outdata = new unsigned char [512*512]; | |
char *my_argv[]= {"myprogram", NULL}; | |
int my_argc =1; | |
sdkLoadPPM4("lena.ppm", &indata, &width,&height); | |
printf("loaded image w/h:%d,%d", width,height); | |
TreshImg(indata,outdata,width,height); | |
initGL(&my_argc,my_argv); | |
glutMainLoop(); | |
///free - host mem | |
delete outdata; | |
delete indata; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment