Jump to content
  • Advertisement

ThatHippieFromBethlehem

Member
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

112 Neutral

About ThatHippieFromBethlehem

  • Rank
    Newbie
  1. ThatHippieFromBethlehem

    Need advice on my code and help with Skybox implementation

    Thanks that would boost my learning!!! :) PM?
  2. ThatHippieFromBethlehem

    Need advice on my code and help with Skybox implementation

    Hi krinosx,   Thank you for the advice and the link it will be useful. :) I will migrate to modern OpenGL eventually but my hardware isn't that great. I think I can only go upto OpenGL 3.1. I'll get new hardware soon.
  3. Hi All,   I've been learning SDL2 and Opengl for about a month now and need advice on my code alot of which from various resources online. I've also been adding it all up ie. background music and texture so now I would like to add background Image to the rotating textured cube which is essentially a skybox. Any advice on the skybox and on my code is welcomed. Feel free to use this code because I'm pretty sure you'll find similar ones out there.   My Code here: #include <SDL2/SDL.h> #include <SDL2/SDL_opengl.h> #include <SDL2/SDL_mixer.h> #include <SDL2/SDL_image.h> #include <GL/glu.h> void Reshape(); void Render(); double rotquad; int WIDTH = 640; int HEIGHT = 480; SDL_Window *window; SDL_Surface *surface; Mix_Music *music = NULL; GLuint texture; int main(int argc, char* argv[]) { Uint32 last_time = SDL_GetTicks(); Uint32 current_time,ellapsed_time; SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); Mix_Init(MIX_INIT_MP3); IMG_Init(IMG_INIT_JPG); SDL_ShowCursor(0); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); window = SDL_CreateWindow("3D",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,WIDTH,HEIGHT,SDL_WINDOW_OPENGL); SDL_GLContext context = SDL_GL_CreateContext(window); surface = IMG_Load("texture.jpg"); Reshape(); Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048); Mix_AllocateChannels(0); music = Mix_LoadMUS("sound.wav"); Mix_PlayMusic(music, -1); while (1) { SDL_Event event; while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: SDL_GL_DeleteContext(context); SDL_DestroyWindow(window); Mix_FreeMusic(music); Mix_CloseAudio(); Mix_Quit(); IMG_Quit(); SDL_Quit(); return 0; break; } } Mix_PlayingMusic(); current_time = SDL_GetTicks(); ellapsed_time = current_time - last_time; last_time = current_time; rotquad += 0.05 * ellapsed_time; Render(); ellapsed_time = SDL_GetTicks(); if (ellapsed_time < 10) { SDL_Delay(10 - ellapsed_time); } } return 0; } void Reshape() { glClearColor(0.3, 0.3, 0.3, 1.0); glViewport(0, 0, WIDTH, HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45, WIDTH / HEIGHT, 1, 1000); glMatrixMode(GL_MODELVIEW); glClearDepth(1); glEnable(GL_DEPTH_TEST); glGenTextures(1,&texture); glBindTexture(GL_TEXTURE_2D,texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->w,surface->h, 0, GL_RGB,GL_UNSIGNED_BYTE,surface->pixels); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } void Render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0); glBindTexture(GL_TEXTURE_2D,texture); glRotated(rotquad, 0, 1, 0); glRotated(rotquad, 1, 1, 1); glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); glTexCoord2i(0, 0); glVertex3f(-1, -1, -1); glTexCoord2i(0, 1); glVertex3f(-1, -1, 1); glTexCoord2i(1, 1); glVertex3f(-1, 1, 1); glTexCoord2i(1, 0); glVertex3f(-1, 1, -1); glTexCoord2i(0, 0); glVertex3f( 1, -1, -1); glTexCoord2i(0, 1); glVertex3f( 1, -1, 1); glTexCoord2i(1, 1); glVertex3f( 1, 1, 1); glTexCoord2i(1, 0); glVertex3f( 1, 1, -1); glTexCoord2i(0, 0); glVertex3f(-1, -1, -1); glTexCoord2i(0, 1); glVertex3f(-1, -1, 1); glTexCoord2i(1, 1); glVertex3f( 1, -1, 1); glTexCoord2i(1, 0); glVertex3f( 1, -1, -1); glTexCoord2i(0, 0); glVertex3f(-1, 1, -1); glTexCoord2i(0, 1); glVertex3f(-1, 1, 1); glTexCoord2i(1, 1); glVertex3f( 1, 1, 1); glTexCoord2i(1, 0); glVertex3f( 1, 1, -1); glTexCoord2i(0, 0); glVertex3f(-1, -1, -1); glTexCoord2i(0, 1); glVertex3f(-1, 1, -1); glTexCoord2i(1, 1); glVertex3f( 1, 1, -1); glTexCoord2i(1, 0); glVertex3f( 1, -1, -1); glTexCoord2i(0, 0); glVertex3f(-1, -1, 1); glTexCoord2i(0, 1); glVertex3f(-1, 1, 1); glTexCoord2i(1, 1); glVertex3f( 1, 1, 1); glTexCoord2i(1, 0); glVertex3f( 1, -1, 1); glEnd(); glDisable(GL_TEXTURE_2D); glFlush(); SDL_GL_SwapWindow(window); } See attached file for screenshot.  
  4. ThatHippieFromBethlehem

    help implementing a limit view to avoid upside down

    Thank you JB!
  5. ThatHippieFromBethlehem

    help implementing a limit view to avoid upside down

    Hi JB,   Can you check my logic? float Max = 90.0f; float Min = -90.0f; float pitch = mDXInput->MouseDY() / 360; float patch; //So I should store pitch value here? if (pitch == Max || pitch == Min ) { //block mouse? /ignore input till check passes /don't update view if input from mouse is higher than 90 or lower than -90? } else { //Keep going? }
  6. Hi, I've been messing around with this and I can't seem to wrap my head around it.   I want to set and angle limit of 90 and -90 degrees to avoid upside down view. Any ideas on how I should go about? #include "Camera.h" Camera* gCamera = 0; Camera::Camera() { D3DXMatrixIdentity(&m_matView); D3DXMatrixIdentity(&m_matProj); m_vEyePoint = D3DXVECTOR3(0.0f, 0.0f, 0.0f); m_vRight = D3DXVECTOR3(1.0f, 0.0f, 0.0f); m_vUp = D3DXVECTOR3(0.0f, 1.0f, 0.0f); m_vForward = D3DXVECTOR3(0.0f, 0.0f, 1.0f); mSpeed = 0.2f; mDXInput = new DXInput() ; } const D3DXMATRIX& Camera::GetViewMatrix() const { return m_matView; } const D3DXMATRIX& Camera::GetProjMatrix() const { return m_matProj; } void Camera::SetViewParams(D3DXVECTOR3& pos, D3DXVECTOR3& target, D3DXVECTOR3& up) { D3DXVECTOR3 L = target - pos; D3DXVec3Normalize(&L, &L); D3DXVECTOR3 R; D3DXVec3Cross(&R, &up, &L); D3DXVec3Normalize(&R, &R); D3DXVECTOR3 U; D3DXVec3Cross(&U, &L, &R); D3DXVec3Normalize(&U, &U); m_vEyePoint = pos; m_vRight = R; m_vUp = U; m_vForward = L; BuildViewMatrix(); } void Camera::SetProjParams(float fov, float aspect, float nearZ, float farZ) { D3DXMatrixPerspectiveFovLH(&m_matProj, fov, aspect, nearZ, farZ); } void Camera::Update(float dt, float offsetHeight) { mDXInput->Update() ; D3DXVECTOR3 dir(0.0f, 0.0f, 0.0f); if( mDXInput->KeyDown(DIK_W) ) dir += m_vForward; if( mDXInput->KeyDown(DIK_S) ) dir -= m_vForward; if( mDXInput->KeyDown(DIK_D) ) dir += m_vRight; if( mDXInput->KeyDown(DIK_A) ) dir -= m_vRight; D3DXVec3Normalize(&dir, &dir); D3DXVECTOR3 newPos = m_vEyePoint + dir * mSpeed * dt; m_vEyePoint = newPos ; if (m_vEyePoint.y < 2.0f) { m_vEyePoint.y = 2.0f ; } if (m_vEyePoint.y > 2.0f) { m_vEyePoint.y = 2.0f ; } float pitch = mDXInput->MouseDY() / 360.0f; float yAngle = mDXInput->MouseDX() / 360.0f; D3DXMATRIX R; D3DXMatrixRotationAxis(&R, &m_vRight, pitch); D3DXVec3TransformCoord(&m_vForward, &m_vForward, &R); D3DXVec3TransformCoord(&m_vUp, &m_vUp, &R); D3DXMatrixRotationY(&R, yAngle); D3DXVec3TransformCoord(&m_vRight, &m_vRight, &R); D3DXVec3TransformCoord(&m_vForward, &m_vForward, &R); BuildViewMatrix(); } void Camera::BuildViewMatrix() { D3DXVec3Normalize(&m_vForward, &m_vForward); D3DXVec3Cross(&m_vUp, &m_vForward, &m_vRight); D3DXVec3Normalize(&m_vUp, &m_vUp); D3DXVec3Cross(&m_vRight, &m_vUp, &m_vForward); D3DXVec3Normalize(&m_vRight, &m_vRight); float x = -D3DXVec3Dot(&m_vEyePoint, &m_vRight); float y = -D3DXVec3Dot(&m_vEyePoint, &m_vUp); float z = -D3DXVec3Dot(&m_vEyePoint, &m_vForward); m_matView(0,0) = m_vRight.x; m_matView(1,0) = m_vRight.y; m_matView(2,0) = m_vRight.z; m_matView(3,0) = x; m_matView(0,1) = m_vUp.x; m_matView(1,1) = m_vUp.y; m_matView(2,1) = m_vUp.z; m_matView(3,1) = y; m_matView(0,2) = m_vForward.x; m_matView(1,2) = m_vForward.y; m_matView(2,2) = m_vForward.z; m_matView(3,2) = z; m_matView(0,3) = 0.0f; m_matView(1,3) = 0.0f; m_matView(2,3) = 0.0f; m_matView(3,3) = 1.0f; } const D3DXVECTOR3 Camera::GetLookAt() const { return m_vForward ; } const D3DXVECTOR3 Camera::GetEyePoint() const { return m_vEyePoint ; } const D3DXVECTOR3 Camera::GetUpVector() const { return m_vUp ; }
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!