[ create a new paste ] login | about

Link: http://codepad.org/O096OoKU    [ raw code | output | fork ]

C++, pasted on Feb 24:
#include <GL/glew.h>
#include <iostream>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <windows.h>
#include "imageloader.h"
#include "kamera.h"
#include "Shader.h"


using namespace std;

GLuint _textureId[3];
kamera Camera;
Shader shader;
int  screenX, screenY;

GLuint loadTexture(Image* image)
{
        GLuint textureId;
        glGenTextures(1, &textureId); 
        glBindTexture(GL_TEXTURE_2D, textureId); 
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,image->width, image->height,0, GL_RGB,GL_UNSIGNED_BYTE,image->pixels);
        return textureId;

} 

void initsmth()
{
        screenX = GetSystemMetrics(SM_CXSCREEN);
        screenY = GetSystemMetrics(SM_CYSCREEN);
        glEnable(GL_DEPTH_TEST);
        glutSetCursor(GLUT_CURSOR_NONE);
		Image* image = loadBMP("ground3.bmp");
        _textureId[0] = loadTexture(image);
        delete image;
        image = loadBMP("ground.bmp");
        _textureId[1] = loadTexture(image);
        delete image;
        image = loadBMP("crate.bmp");
        _textureId[2] = loadTexture(image);
        delete image;
		
}
   


void reshape(int width, int height)
{
        if (height==0)
                height=1;
        float ratio = width*1.0 /height;
        glMatrixMode(GL_PROJECTION);
        
        glLoadIdentity();
        glViewport(0,0,width,height);
        gluPerspective(45.0f,ratio,0.1f,100.0f);
        glMatrixMode(GL_MODELVIEW);

}


void Display()
{
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        Camera.Render();
        glTranslatef(0.0f, 1.0f, -16.0f);

	
         
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, _textureId[0]);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);      
      // 	glUniform1i(glGetUniformLocation(shader.ShaderProgram,"img"),0);
        glBegin(GL_QUADS);
        glTexCoord2f(0.0f, 0.0f);
        glVertex3f(-2.5f, -2.5f, 2.5f);
        glTexCoord2f(1.0f, 0.0f);
        glVertex3f(2.5f, -2.5f, 2.5f);
        glTexCoord2f(1.0f, 1.0f);
        glVertex3f(2.5f, -2.5f, -2.5f);
        glTexCoord2f(0.0f, 1.0f);
        glVertex3f(-2.5f, -2.5f, -2.5f);
        glEnd();
        glBindTexture(GL_TEXTURE_2D, _textureId[1]);    
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);      
        glBegin(GL_QUADS);
        glTexCoord2f(0.0f, 0.0f);
        glVertex3f(-2.5f, -2.5f, 2.5f);
        glTexCoord2f(5.0f, 0.0f);
        glVertex3f(-2.5f, -2.5f, -2.5f);
        glTexCoord2f(5.0f, 5.0f);
        glVertex3f(-2.5f, 2.5f, -2.5f);
        glTexCoord2f(0.0f, 5.0f);
        glVertex3f(-2.5f, 2.5f, 2.5f);
        glEnd();

        glBindTexture(GL_TEXTURE_2D, _textureId[2]);    
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);      
        glBegin(GL_QUADS);

        
        glBegin(GL_QUADS);
        glTexCoord2f(0.0f, 0.0f);       
        glVertex3f(0.5f, -2.5f, 0.5f);
        glTexCoord2f(1.0f, 0.0f);
        glVertex3f(-0.5f, -2.5f, 0.5f);
        glTexCoord2f(1.0f, 1.0f);
        glVertex3f(-0.5f,-2.0f, 0.5f);
        glTexCoord2f(0.0f, 1.0f);
        glVertex3f(0.5f, -2.0f, 0.5f);
        
        glTexCoord2f(0.0f, 0.0f);               
        glVertex3f(0.5f, -2.0f, -0.5f);
        glTexCoord2f(1.0f, 0.0f);       
        glVertex3f(-0.5f, -2.0f, -0.5f);
        glTexCoord2f(1.0f, 1.0f);       
        glVertex3f(-0.5f,-2.0f, 0.5f);
        glTexCoord2f(0.0f, 1.0f);       
        glVertex3f(0.5f, -2.0f, 0.5f);

        glTexCoord2f(0.0f, 0.0f);       
        glVertex3f(0.5f, -2.5f, 0.5f);
        glTexCoord2f(1.0f, 0.0f);       
        glVertex3f(0.5f, -2.0f, 0.5f);  
        glTexCoord2f(1.0f, 1.0f);       
        glVertex3f(0.5f, -2.0f, -0.5f);
        glTexCoord2f(0.0f, 1.0f);       
        glVertex3f(0.5f, -2.5f, -0.5f);
        glEnd();
        
        
        glDisable(GL_TEXTURE_2D);
                
        glutSwapBuffers();
}

void KeyDown(unsigned char key, int x, int y)
{
        switch (key) 
        {
        case 27:                //ESC
                exit(0);
                break;
        case 'a':               
                Camera.Strafe(-0.1);
                Display();
                break;
        case 'd':               
                Camera.Strafe(0.1);
                Display();
                break;
        case 'w':               
                Camera.MoveForwards( -0.1) ;
                Display();
                break;
        case 's':               
                Camera.MoveForwards(0.1) ;
                Display();
                break;

        }
}

void mousemove(int x, int y)
{
        static float lastx = 0.0;
        static float lasty = 0.0;
        
        lastx = (float)x - lastx;
        lasty = (float)y - lasty;
        cout << "lastx = "<<x<<endl;
        cout << "lasty = "<<y<<endl<<endl;

        if(x>(screenX-10) || x<10 || y>(screenY-10) || y<10)
        {
                glutWarpPointer(screenX/2, screenY/2);
                lastx =(float)screenX/2;
                lasty =(float)screenY/2;
                return;
        }
        if((float)x > lastx)
                Camera.RotateY((-lastx)*0.05);
        else
                Camera.RotateY(lastx*0.05);
        if((float)y > lasty)
                Camera.RotateX(lasty*0.05);
        else
                Camera.RotateX((-lasty)*0.05);
        lastx = (float)x;
        lasty = (float)y;
        Display();
}



int main(int argc, char **argv)
{

        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
        glutInitWindowPosition(0, 0);
        glutCreateWindow("kutay's ultra super cubes");
        initsmth();
        glutFullScreen();
 
		cout << glutGet(GLUT_WINDOW_WIDTH); cout <<glutGet(GLUT_WINDOW_HEIGHT) <<endl<< glutGet( GLUT_WINDOW_X )<<endl<<glutGet( GLUT_WINDOW_Y );
        GLenum res = glewInit();
        if (res != GLEW_OK)
		{
		  fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
           return 1;
        }
		shader.CompileShaders();
		glutDisplayFunc(Display);
        glutReshapeFunc(reshape);
        glutKeyboardFunc(KeyDown);
        glutPassiveMotionFunc(mousemove);
		 

        

        glutMainLoop();

}


Output:
1
2
3
4
5
6
7
8
Line 20: error: GL/glew.h: No such file or directory
Line 20: error: GL/glut.h: No such file or directory
Line 20: error: windows.h: No such file or directory
Line 24: error: imageloader.h: No such file or directory
Line 19: error: kamera.h: No such file or directory
Line 19: error: Shader.h: No such file or directory
Line 16: error: 'GLuint' does not name a type
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: