SDL 다룰줄 아시는 분 도와주세요=;

hyangii의 이미지

안녕하세요.

제가 하고자 하는것은 SDL로 쓰레드를 생성해서 랜덤한 수를 공급하고요

그 수를 높이 수치로 받아서 높이가 변화하는 사각형을 opengl로 써서

구현하는 것입니다.

SDL을 안끌어들여도 지장은 없지만, 더블버퍼링을 해도 깜빡거림이 없어지지

않아서, 건드리게 됐는데, 컴파일 & 실행이 안되고, 주위를 인터넷을 찾아도,,

원하는걸 찾기가 힘드네요(기초적인 부분을 몰라서리 -_ㅠ);;

우선 사용되는 헤더파일들은

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <SDL/SDL.h>
#include <SDL/SDL_thread.h>
#include <time.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

이고,

쓰레드를 만들어서 그리는 함수는

int worker_func(void *data)
{
	while (thread_control == GO) {
		int bucket;
		
    	SDL_mutexP(mutex);
	    for (bucket = 0 ; bucket <512; bucket++)
	    {
		 srand(time(NULL));
		 int n,m;
		 m=rand();
		 n=(m%512)+1;
		 freq[bucket]=n;
	    }
	    SDL_mutexV(mutex);                             //랜덤수를 잡아 freq에 저장
            
           int h;
	
	    SDL_mutexP(mutex);
		h= freq[0];                                                                                                                        // h에는 계속 랜덤수가 저장
            SDL_mutexV(mutex);
	    SDL_SetVideoMode(480,320,32,SDL_OPENGL);
	


        gluLookAt(0,0,5,0,0,0,0,1,0);
	glClearColor(0.0f,0.0f,0.0f,0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glLoadIdentity();

	static float rotation = 0;
	float height, color1,color2,color3;      // h를 이용해 높이, 색등을 지정.
	height=h/1024.0;
	color1=h/512.0;
	color2=h/2048.0;
	color3=h/1024.0;


	glRotatef(rotation++,0,0,1);
	glBegin(GL_POLYGON);                     //사각형 구현 부분
		glColor3f(color3,0.0f,color1);
		glVertex3f(-0.5f,-0.5f,0.0f);

		glColor3f(color2,0.0f,0.0f);
		glVertex3f(0.5f,-0.5f,0.0f);

		glColor3f(0.0f,0.0f,color3);
		glVertex3f(0.5f,height,0.0f);

		glColor3f(color1,color2,color3);
		glVertex3f(-0.5f,height,0.0f);
	glEnd();
	SDL_GL_SwapBuffers();

	rotation+=1.0f;
	if(rotation>359) rotation=1.0f;
	
	
	}
		
}


이것 입니다...

그리고 메인 함수는

int main(int argc, char **argv)
{
	Init();  // 랜덤 수를 발생하게 쓰레드를 설정해주는 함수
	SDL_Init(SDL_INIT_VIDEO);
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	worker_func(worker_thread); // 어떻게 해야할지 모르는 부분 !!	        
        glutReshapeFunc(changeSize);
	glEnable(GL_DEPTH_TEST);
	glutMainLoop();
	Cleanup();

	return 0;
}
	

입니다..

컴파일은
g++ mutex2.c -lSDL -lGL -lGLU -lglut -lpthread
로 했습니다.

worker_func함수를 불러와야 하는데, 컴파일을 하면 세그멘테이션 오류'가
뜨네요.

전체 코드를 첨부 시켰습니다... 대략 100라인 -_-;;

어떻게 해결할 수 있을까요, 조언 부탁드립니다...

File attachments: 
첨부파일 크기
파일 mutex2.c2.57 KB
파일 mutex2.cpp3.09 KB
ageldama의 이미지

제가 생각할 때 이상한 부분이 2가지입니다.

우선 첫번째는 단순히 glut에서 생성한 윈도가 sdl에서 제대로 붙나요?
(전 윈도 vc++7에서)전 차라리 sdl만으로 수정했습니다.

그리고 쓰레드에서는 값만 변경하시는 편이 좋지 않을까요?

수정한 화일을 첨부합니다.

아참. 그런데 매번 렌더링 할때마다 SDL_SetVideoMode()을 호출하는건 왜지요? 없으면 렌더링이 안되더군요.

댓글 첨부 파일: 
첨부파일 크기
파일 0바이트

----
The future is here. It's just not widely distributed yet.
- William Gibson

hyangii의 이미지

에.. 님께서 이상하다 말하신 부분들이.. 어떤부분이 어떻게 이상하게 돌아가는지

잘 모릅니다.. xmms의 시각화 플러그인 메뉴얼을 보고 허접으로 스스슥

짰기때문에ㅣ...

이렇게 수정해주신거 감사합니다.

다만... 리눅스에서 컴파일 해서 그런지 몇가지 문제가 떴습니다.

gcc mutex3.cpp -lSDL -lGL -lGLU -lGLU -lglut -lpthread

이렇게 컴파일했습니다만,

처음에는 SDL_Delay(0.1f); 부분이 에러가 났는데요

원레 인자가 unsigned int 여야 한다면서 컴팔이 안되더군요

그래서 아예 '1'로 수정했습니다.

그랬더니 에러메세지 없이 컴파일은 됐습니다만,

화면이 초기화 되고, 윈도우도 생성되는데,

화면에 아무것도 뿌려지지가 않네요.

조금만 더 도움을 주실수 있을까요 ;;;;;;;

ageldama의 이미지

디버거를 사용하시면 디버거로 아니면 printf()등으로
worker_func(), render()가 계속해서 호출되는지를 보세요.
만약 render도 주기적으로 잘 호출되는데 역시 내용이 없다면 문제가 ;;;

제 경우엔 사각형 크기가 바뀌거나 하진 않습니다.
(역시 freq을 디버거나 printf등으로 실행시간에 살펴보세요. 저는 주욱 늘어날 뿐이더군요.)

----
The future is here. It's just not widely distributed yet.
- William Gibson

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.