CodeCrafterCpp
Erfahrenes Mitglied
Hier der Quellcode der opengl_init.cpp:
Aber warum ein void als Parameter im Error steht ist mir fraglich.
Im Anhang die _OpenGl und _SDL.
C++:
//***** OPENGL_INIT_CPP *****//
//***** OpenGL 0.0.1 *****//
#include "stdafx.h"
#include "opengl_init.h"
using namespace std;
void OpenGL_Init::opengl_init_scene(){
this->angle = 0.0;
float dif[] = {1.0f, 1.0f, 1.0f, 1.0f};
float amb[] = {0.2f, 0.2f, 0.2f, 1.0f};
glClearColor(0.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, 640.0/480.0, 1.0, 500.0);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_TEXTURE_2D);
tex = loadTexture("C:/Users/Jonas/Desktop/brick.bmp");
glLoadIdentity();
}
unsigned int loadTexture(const char* filename)
{
SDL_Surface* img = SDL_LoadBMP(filename);
unsigned int id;
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->w, img->h,
0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, img->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
SDL_FreeSurface(img);
return id;
}
void OpenGL_Init::opengl_draw_scene(){
if(this->angle >= 360)
this->angle = 0.0f;
float pos[] = {-2.0f, 2.0f,-3.0f, 1.0f};
float size = 2.0f;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0,-10.0);
glRotatef(angle, 0.0f, 2.0f, 0.0f);
glBindTexture(GL_TEXTURE_2D, tex);
glBegin(GL_QUADS);
glTexCoord2f(1.0, 1.0);
glVertex3f(size/2, size/2, 0.0f);
glTexCoord2f(0.0, 1.0);
glVertex3f(-size/2, size/2, 0.0f);
glTexCoord2f(0.0, 0.0);
glVertex3f(-size/2,-size/2, 0.0f);
glTexCoord2f(1.0, 0.0);
glVertex3f(size/2,-size/2, 0.0f);
glEnd();
//opengl_draw_cube(size);
}
void OpenGL_Init::opengl_draw_cube(float size)
{
glBegin(GL_QUADS);
//front face
glNormal3f( 0.0, 0.0, size);
glColor3f( 1.0f, 0.0f, 0.0f);
glVertex3f( size/2, size/2, size/2);
glVertex3f(-size/2, size/2, size/2);
glVertex3f(-size/2,-size/2, size/2);
glVertex3f( size/2,-size/2, size/2);
//left face
glNormal3f( -size, 0.0, 0.0);
glColor3f( 0.0f, 1.0, 0.0f);
glVertex3f(-size/2, size/2, size/2);
glVertex3f(-size/2, size/2,-size/2);
glVertex3f(-size/2,-size/2,-size/2);
glVertex3f(-size/2,-size/2, size/2);
//back face
glNormal3f( 0.0, 0.0,-size);
glColor3f( 0.0f, 0.0f, 1.0f);
glVertex3f( size/2, size/2, -size/2);
glVertex3f(-size/2, size/2, -size/2);
glVertex3f(-size/2,-size/2, -size/2);
glVertex3f( size/2,-size/2, -size/2);
//right face
glNormal3f( size, 0.0, 0.0);
glColor3f( 1.0f, 1.0f, 0.0f);
glVertex3f( size/2, size/2, size/2);
glVertex3f( size/2, size/2,-size/2);
glVertex3f( size/2,-size/2,-size/2);
glVertex3f( size/2,-size/2, size/2);
//top face
glNormal3f( 0.0, size, 0.0);
glColor3f( 0.0f, 0.0f, 0.0f);
glVertex3f(-size/2, size/2, size/2);
glVertex3f(-size/2, size/2,-size/2);
glVertex3f( size/2, size/2,-size/2);
glVertex3f( size/2, size/2, size/2);
//bottom face
glNormal3f( 0.0,-size, 0.0);
glColor3f( 1.0f, 0.0f, 1.0f);
glVertex3f(-size/2,-size/2, size/2);
glVertex3f(-size/2,-size/2,-size/2);
glVertex3f( size/2,-size/2,-size/2);
glVertex3f( size/2,-size/2, size/2);
glEnd();
glBegin(GL_TRIANGLES);
//Front face
glNormal3f(size-size, size, size);
glColor3f( 0.0f, 1.0f, 0.0f);
glVertex3f( size/2, size/2, size/2);
glVertex3f(-size/2, size/2, size/2);
glVertex3f( size-size, size, size-size);
//Left face
glNormal3f( -size, size, size-size);
glColor3f( 0.0f, 0.0f, 1.0f);
glVertex3f(-size/2, size/2, size/2);
glVertex3f(-size/2, size/2,-size/2);
glVertex3f( size-size, size, size-size);
//Right face
glNormal3f( size, size, size-size);
glColor3f( 1.0f, 0.0f, 1.0f);
glVertex3f( size/2, size/2, size/2);
glVertex3f( size/2, size/2,-size/2);
glVertex3f( size-size, size, size-size);
//Back face
glColor3f( 1.0f, 0.0f, 0.0f);
glNormal3f(size-size, size, -size);
glVertex3f( size/2, size/2, -size/2);
glVertex3f(-size/2, size/2, -size/2);
glVertex3f( size-size, size, size-size);
glEnd();
}
void OpenGL_Init::opengl_movement(float angle){
this->angle += angle;
}
Aber warum ein void als Parameter im Error steht ist mir fraglich.
Im Anhang die _OpenGl und _SDL.
Anhänge
Zuletzt bearbeitet von einem Moderator: